Skip to content

Commit

Permalink
[8.x] [Maps] Surface data request errors (#200860) (#201743)
Browse files Browse the repository at this point in the history
# Backport

This will backport the following commits from `main` to `8.x`:
- [[Maps] Surface data request errors
(#200860)](#200860)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Krzysztof
Kowalczyk","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-26T10:18:45Z","message":"[Maps]
Surface data request errors (#200860)\n\n## Summary\r\n\r\nThis PR makes
it to so data request errors are surfaced to users, as
a\r\nwarning.\r\n\r\nCloses:
#195294","sha":"1f578909832a9e00342c33fee03f9bd79b5f28b1","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","Team:Presentation","release_note:skip","v9.0.0","backport:prev-minor","Feature:Maps"],"title":"[Maps]
Surface data request
errors","number":200860,"url":"https://github.com/elastic/kibana/pull/200860","mergeCommit":{"message":"[Maps]
Surface data request errors (#200860)\n\n## Summary\r\n\r\nThis PR makes
it to so data request errors are surfaced to users, as
a\r\nwarning.\r\n\r\nCloses:
#195294","sha":"1f578909832a9e00342c33fee03f9bd79b5f28b1"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/200860","number":200860,"mergeCommit":{"message":"[Maps]
Surface data request errors (#200860)\n\n## Summary\r\n\r\nThis PR makes
it to so data request errors are surfaced to users, as
a\r\nwarning.\r\n\r\nCloses:
#195294","sha":"1f578909832a9e00342c33fee03f9bd79b5f28b1"}}]}]
BACKPORT-->

Co-authored-by: Krzysztof Kowalczyk <[email protected]>
  • Loading branch information
kibanamachine and kowalczyk-krzysztof authored Nov 26, 2024
1 parent 678feac commit 232515e
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import React, { useEffect, useState } from 'react';
import { EuiCallOut, EuiFlexGroup, EuiFlexItem, EuiText, EuiToolTip } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { DynamicStyleProperty } from '../../properties/dynamic_style_property';

interface Props {
error: Error;
style: DynamicStyleProperty<object>;
}

export const StyleError = ({ error, style }: Props) => {
const [label, setLabel] = useState('');
const styleName = style.getDisplayStyleName();

useEffect(() => {
let canceled = false;
const getLabel = async () => {
const field = style.getField();
if (!field) {
return;
}

const fieldLabel = await field.getLabel();

if (canceled) {
return;
}

setLabel(fieldLabel);
};

getLabel();

return () => {
canceled = true;
};
}, [style]);

return (
<div>
<EuiFlexGroup gutterSize="xs" justifyContent="spaceBetween">
<EuiFlexItem grow={false}>
<EuiToolTip position="top" title={styleName} content={label}>
<EuiText className="eui-textTruncate" size="xs" style={{ maxWidth: '180px' }}>
<small>
<strong>{label}</strong>
</small>
</EuiText>
</EuiToolTip>
</EuiFlexItem>
</EuiFlexGroup>
<EuiFlexGroup direction="column" gutterSize="none">
<EuiCallOut
title={i18n.translate('xpack.maps.vectorStyleLegend.fetchStyleMetaDataError', {
defaultMessage: 'Unable to fetch style meta data',
})}
color="warning"
iconType="warning"
>
<p>{error.message}</p>
</EuiCallOut>
</EuiFlexGroup>
</div>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
import React from 'react';
import { EuiText } from '@elastic/eui';
import { euiThemeVars } from '@kbn/ui-theme';
import { StyleError } from './style_error';
import {
DynamicStyleProperty,
IDynamicStyleProperty,
} from '../../properties/dynamic_style_property';
import { FIELD_ORIGIN } from '../../../../../../common/constants';
import { Mask } from '../../../../layers/vector_layer/mask';
import { IStyleProperty } from '../../properties/style_property';
Expand All @@ -33,12 +38,22 @@ export function VectorStyleLegend({
const legendRows = [];

for (let i = 0; i < styles.length; i++) {
const row = styles[i].renderLegendDetailRow({
isLinesOnly,
isPointsOnly,
symbolId,
svg,
});
const styleMetaDataRequest = styles[i].isDynamic()
? (styles[i] as IDynamicStyleProperty<object>).getStyleMetaDataRequest()
: undefined;

const error = styleMetaDataRequest?.getError();

const row = error ? (
<StyleError error={error} style={styles[i] as DynamicStyleProperty<object>} />
) : (
styles[i].renderLegendDetailRow({
isLinesOnly,
isPointsOnly,
symbolId,
svg,
})
);

legendRows.push(
<div key={i} className="vectorStyleLegendSpacer">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import _ from 'lodash';
import React from 'react';
import { FeatureCollection } from 'geojson';
import type { FeatureIdentifier, Map as MbMap } from '@kbn/mapbox-gl';
import { DataRequest } from '../../../util/data_request';
import { AbstractStyleProperty, IStyleProperty } from './style_property';
import { DEFAULT_SIGMA } from '../vector_style_defaults';
import {
Expand Down Expand Up @@ -97,6 +98,7 @@ export interface IDynamicStyleProperty<T> extends IStyleProperty<T> {
mbMap: MbMap,
mbSourceId: string
): boolean;
getStyleMetaDataRequest(): DataRequest | undefined;
}

export class DynamicStyleProperty<T extends object>
Expand All @@ -122,6 +124,11 @@ export class DynamicStyleProperty<T extends object>
this._getFieldFormatter = getFieldFormatter;
}

getStyleMetaDataRequest() {
const dataRequestId = this._getStyleMetaDataRequestId(this.getFieldName());
return dataRequestId ? this._layer.getDataRequest(dataRequestId) : undefined;
}

getValueSuggestions = async (query: string) => {
return this._field === null
? []
Expand All @@ -147,12 +154,7 @@ export class DynamicStyleProperty<T extends object>
}

_getRangeFieldMetaFromStyleMetaRequest(): RangeFieldMeta | null {
const dataRequestId = this._getStyleMetaDataRequestId(this.getFieldName());
if (!dataRequestId) {
return null;
}

const styleMetaDataRequest = this._layer.getDataRequest(dataRequestId);
const styleMetaDataRequest = this.getStyleMetaDataRequest();
if (!styleMetaDataRequest || !styleMetaDataRequest.hasData()) {
return null;
}
Expand All @@ -177,12 +179,7 @@ export class DynamicStyleProperty<T extends object>
return null;
}

const dataRequestId = this._getStyleMetaDataRequestId(this.getFieldName());
if (!dataRequestId) {
return null;
}

const styleMetaDataRequest = this._layer.getDataRequest(dataRequestId);
const styleMetaDataRequest = this.getStyleMetaDataRequest();
if (!styleMetaDataRequest || !styleMetaDataRequest.hasData()) {
return null;
}
Expand All @@ -202,12 +199,7 @@ export class DynamicStyleProperty<T extends object>
}

_getCategoryFieldMetaFromStyleMetaRequest() {
const dataRequestId = this._getStyleMetaDataRequestId(this.getFieldName());
if (!dataRequestId) {
return [];
}

const styleMetaDataRequest = this._layer.getDataRequest(dataRequestId);
const styleMetaDataRequest = this.getStyleMetaDataRequest();
if (!styleMetaDataRequest || !styleMetaDataRequest.hasData()) {
return [];
}
Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/maps/public/classes/util/data_request.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ export class DataRequest {
return this._descriptor.dataRequestToken;
}

getError(): Error | undefined {
return this._descriptor.error;
}

renderError(): ReactNode {
if (!this._descriptor.error) {
return null;
Expand Down

0 comments on commit 232515e

Please sign in to comment.