Skip to content

Commit

Permalink
[Visualize] Fixes the case with existing saved search and absent data…
Browse files Browse the repository at this point in the history
…view (#147327)

## Summary

Closes #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.

<img width="1858" alt="image"
src="https://user-images.githubusercontent.com/17003240/206996776-aa595932-0670-4ecc-aaca-344642ec02cd.png">

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.
  • Loading branch information
stratoula authored Dec 12, 2022
1 parent e6cbfac commit 3063950
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()}
</h2>
</EuiTitle>
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
),
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ function MetricsAxisOptions(props: ValidationVisOptionsProps<VisParams>) {

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 !== '') {
Expand Down Expand Up @@ -290,7 +290,7 @@ function MetricsAxisOptions(props: ValidationVisOptionsProps<VisParams>) {
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
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ export function ElasticChartsOptions(props: ValidationVisOptionsProps<VisParams>

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(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ export function PointSeriesOptions(props: ValidationVisOptionsProps<VisParams>)
() =>
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;
Expand Down Expand Up @@ -78,7 +78,7 @@ export function PointSeriesOptions(props: ValidationVisOptionsProps<VisParams>)
showAutoOption={hadAutoLegendSize}
/>

{vis.data.aggs!.aggs.some(
{vis.data?.aggs?.aggs.some(
(agg) => agg.schema === 'segment' && agg.type.name === BUCKET_TYPES.DATE_HISTOGRAM
) ? (
<SwitchOption
Expand Down

0 comments on commit 3063950

Please sign in to comment.