From d594e09465376f4e808cf9fd757e938bf258d17c Mon Sep 17 00:00:00 2001 From: dej611 Date: Wed, 10 Aug 2022 17:01:43 +0200 Subject: [PATCH] :bug: Fix bug when creating dataview in place --- .../lens/public/app_plugin/lens_top_nav.tsx | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/lens/public/app_plugin/lens_top_nav.tsx b/x-pack/plugins/lens/public/app_plugin/lens_top_nav.tsx index 12c8c76306246..452453934c2df 100644 --- a/x-pack/plugins/lens/public/app_plugin/lens_top_nav.tsx +++ b/x-pack/plugins/lens/public/app_plugin/lens_top_nav.tsx @@ -253,13 +253,21 @@ export const LensTopNavMenu = ({ ); const dispatchChangeIndexPattern = React.useCallback( async (indexPatternId) => { - const newIndexPatterns = await indexPatternService.ensureIndexPattern({ - id: indexPatternId, - cache: dataViews.indexPatterns, - }); + const [newIndexPatternRefs, newIndexPatterns] = await Promise.all([ + // Reload refs in case it's a new indexPattern created on the spot + dataViews.indexPatternRefs[indexPatternId] + ? dataViews.indexPatternRefs + : indexPatternService.loadIndexPatternRefs({ + isFullEditor: true, + }), + indexPatternService.ensureIndexPattern({ + id: indexPatternId, + cache: dataViews.indexPatterns, + }), + ]); dispatch( changeIndexPattern({ - dataViews: { indexPatterns: newIndexPatterns }, + dataViews: { indexPatterns: newIndexPatterns, indexPatternRefs: newIndexPatternRefs }, datasourceIds: Object.keys(datasourceStates), visualizationIds: visualization.activeId ? [visualization.activeId] : [], indexPatternId, @@ -267,6 +275,7 @@ export const LensTopNavMenu = ({ ); }, [ + dataViews.indexPatternRefs, dataViews.indexPatterns, datasourceStates, dispatch,