From 232515e645e80484acd90adadb2ef91556e3f7ab Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Tue, 26 Nov 2024 23:15:20 +1100 Subject: [PATCH] [8.x] [Maps] Surface data request errors (#200860) (#201743) # Backport This will backport the following commits from `main` to `8.x`: - [[Maps] Surface data request errors (#200860)](https://github.com/elastic/kibana/pull/200860) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Krzysztof Kowalczyk --- .../vector/components/legend/style_error.tsx | 72 +++++++++++++++++++ .../components/legend/vector_style_legend.tsx | 27 +++++-- .../properties/dynamic_style_property.tsx | 28 +++----- .../maps/public/classes/util/data_request.tsx | 4 ++ 4 files changed, 107 insertions(+), 24 deletions(-) create mode 100644 x-pack/plugins/maps/public/classes/styles/vector/components/legend/style_error.tsx diff --git a/x-pack/plugins/maps/public/classes/styles/vector/components/legend/style_error.tsx b/x-pack/plugins/maps/public/classes/styles/vector/components/legend/style_error.tsx new file mode 100644 index 0000000000000..06811f79517aa --- /dev/null +++ b/x-pack/plugins/maps/public/classes/styles/vector/components/legend/style_error.tsx @@ -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; +} + +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 ( +
+ + + + + + {label} + + + + + + + +

{error.message}

+
+
+
+ ); +}; diff --git a/x-pack/plugins/maps/public/classes/styles/vector/components/legend/vector_style_legend.tsx b/x-pack/plugins/maps/public/classes/styles/vector/components/legend/vector_style_legend.tsx index 60bcd05c9f738..afe1bbe194636 100644 --- a/x-pack/plugins/maps/public/classes/styles/vector/components/legend/vector_style_legend.tsx +++ b/x-pack/plugins/maps/public/classes/styles/vector/components/legend/vector_style_legend.tsx @@ -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'; @@ -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).getStyleMetaDataRequest() + : undefined; + + const error = styleMetaDataRequest?.getError(); + + const row = error ? ( + } /> + ) : ( + styles[i].renderLegendDetailRow({ + isLinesOnly, + isPointsOnly, + symbolId, + svg, + }) + ); legendRows.push(
diff --git a/x-pack/plugins/maps/public/classes/styles/vector/properties/dynamic_style_property.tsx b/x-pack/plugins/maps/public/classes/styles/vector/properties/dynamic_style_property.tsx index e3751d9424dd0..7790ebb0956bf 100644 --- a/x-pack/plugins/maps/public/classes/styles/vector/properties/dynamic_style_property.tsx +++ b/x-pack/plugins/maps/public/classes/styles/vector/properties/dynamic_style_property.tsx @@ -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 { @@ -97,6 +98,7 @@ export interface IDynamicStyleProperty extends IStyleProperty { mbMap: MbMap, mbSourceId: string ): boolean; + getStyleMetaDataRequest(): DataRequest | undefined; } export class DynamicStyleProperty @@ -122,6 +124,11 @@ export class DynamicStyleProperty 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 ? [] @@ -147,12 +154,7 @@ export class DynamicStyleProperty } _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; } @@ -177,12 +179,7 @@ export class DynamicStyleProperty 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; } @@ -202,12 +199,7 @@ export class DynamicStyleProperty } _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 []; } diff --git a/x-pack/plugins/maps/public/classes/util/data_request.tsx b/x-pack/plugins/maps/public/classes/util/data_request.tsx index 4554761ac0f4e..12b9e6a66045c 100644 --- a/x-pack/plugins/maps/public/classes/util/data_request.tsx +++ b/x-pack/plugins/maps/public/classes/util/data_request.tsx @@ -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;