From 3063950097be65079e1ab421518894208a55f4d5 Mon Sep 17 00:00:00 2001 From: Stratoula Kalafateli Date: Mon, 12 Dec 2022 16:21:06 +0200 Subject: [PATCH] [Visualize] Fixes the case with existing saved search and absent dataview (#147327) ## Summary Closes https://github.com/elastic/kibana/issues/147285 It fixes the bug that is described in the issue. If you create a saved search with an index pattern and then delete the index pattern. now it won't break the entire kibana but will navigate to to the following screen that indicates that there is no index. image This is an edge case on my point of view, ideally if there are saved searches that correspond to a non-existent dataview should not be on the list but the current architecture doesn't allow to quickly solve this. I think it is fine for now. --- .../vis_default_editor/public/components/agg_group.tsx | 2 +- .../public/components/sidebar/sidebar_title.tsx | 4 ++-- .../xy/public/convert_to_lens/configurations/index.ts | 4 ++-- .../public/editor/components/options/metrics_axes/index.tsx | 6 +++--- .../options/point_series/elastic_charts_options.tsx | 4 ++-- .../editor/components/options/point_series/point_series.tsx | 6 +++--- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/plugins/vis_default_editor/public/components/agg_group.tsx b/src/plugins/vis_default_editor/public/components/agg_group.tsx index 7f09431d2ea7f..fcff8753fb25c 100644 --- a/src/plugins/vis_default_editor/public/components/agg_group.tsx +++ b/src/plugins/vis_default_editor/public/components/agg_group.tsx @@ -65,7 +65,7 @@ function DefaultEditorAggGroup({ const schemaNames = schemas.map((s) => s.name); const group: IAggConfig[] = useMemo( () => - state.data.aggs!.aggs.filter( + state.data.aggs?.aggs.filter( (agg: IAggConfig) => agg.schema && schemaNames.includes(agg.schema) ) || [], [state.data.aggs, schemaNames] diff --git a/src/plugins/vis_default_editor/public/components/sidebar/sidebar_title.tsx b/src/plugins/vis_default_editor/public/components/sidebar/sidebar_title.tsx index db804bd7c4592..07bbcea16b9df 100644 --- a/src/plugins/vis_default_editor/public/components/sidebar/sidebar_title.tsx +++ b/src/plugins/vis_default_editor/public/components/sidebar/sidebar_title.tsx @@ -167,11 +167,11 @@ function SidebarTitle({ savedSearch, vis, isLinkedSearch, eventEmitter }: Sideba title={i18n.translate('visDefaultEditor.sidebar.indexPatternAriaLabel', { defaultMessage: 'Index pattern: {title}', values: { - title: vis.data.indexPattern!.getName(), + title: vis.data?.indexPattern?.getName(), }, })} > - {vis.data.indexPattern!.getName()} + {vis.data?.indexPattern?.getName()} ) : ( diff --git a/src/plugins/vis_types/xy/public/convert_to_lens/configurations/index.ts b/src/plugins/vis_types/xy/public/convert_to_lens/configurations/index.ts index 9674c47b33bc5..0c6f3b04131c0 100644 --- a/src/plugins/vis_types/xy/public/convert_to_lens/configurations/index.ts +++ b/src/plugins/vis_types/xy/public/convert_to_lens/configurations/index.ts @@ -274,9 +274,9 @@ export const getConfiguration = ( ? Boolean(vis.params.addTimeMarker ?? vis.type.visConfig.defaults.addTimeMarker) : undefined, curveType: getCurveType( - series[0].interpolate === InterpolationMode.StepAfter + series[0]?.interpolate === InterpolationMode.StepAfter ? InterpolationMode.Linear - : series[0].interpolate + : series[0]?.interpolate ), }; }; diff --git a/src/plugins/vis_types/xy/public/editor/components/options/metrics_axes/index.tsx b/src/plugins/vis_types/xy/public/editor/components/options/metrics_axes/index.tsx index a8535f9d148eb..3fbd826dd4f26 100644 --- a/src/plugins/vis_types/xy/public/editor/components/options/metrics_axes/index.tsx +++ b/src/plugins/vis_types/xy/public/editor/components/options/metrics_axes/index.tsx @@ -97,14 +97,14 @@ function MetricsAxisOptions(props: ValidationVisOptionsProps) { series.forEach((serie, seriesIndex) => { if ((axisNumber === 0 && !serie.valueAxis) || serie.valueAxis === axis.id) { - const aggByIndex = aggs.bySchemaName('metric')[seriesIndex]; + const aggByIndex = aggs?.bySchemaName('metric')[seriesIndex]; matchingSeries.push(aggByIndex); } }); if (matchingSeries.length === 1) { // if several series matches to the axis, axis title is set according to the first serie. - newCustomLabel = matchingSeries[0].makeLabel(); + newCustomLabel = matchingSeries[0]?.makeLabel(); } if (lastCustomLabels[axis.id] !== newCustomLabel && newCustomLabel !== '') { @@ -290,7 +290,7 @@ function MetricsAxisOptions(props: ValidationVisOptionsProps) { updateAxisTitle(updatedSeries); }, [firstValueAxesId, setValue, stateParams.seriesParams, updateAxisTitle, aggs, schemaName]); - const isTimeViz = aggs.aggs.some( + const isTimeViz = aggs?.aggs.some( (agg) => agg.schema === 'segment' && agg.enabled && agg.type?.name === BUCKET_TYPES.DATE_HISTOGRAM ); diff --git a/src/plugins/vis_types/xy/public/editor/components/options/point_series/elastic_charts_options.tsx b/src/plugins/vis_types/xy/public/editor/components/options/point_series/elastic_charts_options.tsx index ed57c5427027b..2909ddfef5303 100644 --- a/src/plugins/vis_types/xy/public/editor/components/options/point_series/elastic_charts_options.tsx +++ b/src/plugins/vis_types/xy/public/editor/components/options/point_series/elastic_charts_options.tsx @@ -26,12 +26,12 @@ export function ElasticChartsOptions(props: ValidationVisOptionsProps const isLineChart = stateParams.seriesParams.some( ({ type, data: { id: paramId } }) => - type === ChartType.Line && aggs.aggs.find(({ id }) => id === paramId)?.enabled + type === ChartType.Line && aggs?.aggs.find(({ id }) => id === paramId)?.enabled ); const isAreaChart = stateParams.seriesParams.some( ({ type, data: { id: paramId } }) => - type === ChartType.Area && aggs.aggs.find(({ id }) => id === paramId)?.enabled + type === ChartType.Area && aggs?.aggs.find(({ id }) => id === paramId)?.enabled ); useEffect(() => { diff --git a/src/plugins/vis_types/xy/public/editor/components/options/point_series/point_series.tsx b/src/plugins/vis_types/xy/public/editor/components/options/point_series/point_series.tsx index c12eae1b20b8e..f38471d2ae24e 100644 --- a/src/plugins/vis_types/xy/public/editor/components/options/point_series/point_series.tsx +++ b/src/plugins/vis_types/xy/public/editor/components/options/point_series/point_series.tsx @@ -37,9 +37,9 @@ export function PointSeriesOptions(props: ValidationVisOptionsProps) () => stateParams.seriesParams.some( ({ type, data: { id: paramId } }) => - type === ChartType.Histogram && aggs.aggs.find(({ id }) => id === paramId)?.enabled + type === ChartType.Histogram && aggs?.aggs.find(({ id }) => id === paramId)?.enabled ), - [stateParams.seriesParams, aggs.aggs] + [stateParams.seriesParams, aggs?.aggs] ); const legendSize = stateParams.legendSize; @@ -78,7 +78,7 @@ export function PointSeriesOptions(props: ValidationVisOptionsProps) showAutoOption={hadAutoLegendSize} /> - {vis.data.aggs!.aggs.some( + {vis.data?.aggs?.aggs.some( (agg) => agg.schema === 'segment' && agg.type.name === BUCKET_TYPES.DATE_HISTOGRAM ) ? (