From 0b328a2597a493a35e41b81062b5037e7b2b2cc7 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 10 Sep 2024 23:49:00 +0000 Subject: [PATCH] Fix refresh on index (#8121) Signed-off-by: abbyhu2000 (cherry picked from commit 1d36fd30074c7b97fa9c417e5e3c461b5b4c7d7c) Signed-off-by: github-actions[bot] --- .../view_components/utils/use_index_pattern.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/plugins/discover/public/application/view_components/utils/use_index_pattern.ts b/src/plugins/discover/public/application/view_components/utils/use_index_pattern.ts index c9585240da70..1ced2beaccfe 100644 --- a/src/plugins/discover/public/application/view_components/utils/use_index_pattern.ts +++ b/src/plugins/discover/public/application/view_components/utils/use_index_pattern.ts @@ -45,8 +45,18 @@ export const useIndexPattern = (services: DiscoverViewServices) => { let isMounted = true; const handleIndexPattern = async () => { - if (isQueryEnhancementEnabled && query?.dataset) { - const pattern = await data.indexPatterns.get(query.dataset.id); + if (isQueryEnhancementEnabled && query.dataset) { + let pattern = await data.indexPatterns.get( + query.dataset.id, + query.dataset.type !== 'INDEX_PATTERN' + ); + if (!pattern) { + await data.query.queryString.getDatasetService().cacheDataset(query.dataset); + pattern = await data.indexPatterns.get( + query.dataset.id, + query.dataset.type !== 'INDEX_PATTERN' + ); + } if (isMounted && pattern) { setIndexPattern(pattern); @@ -95,7 +105,8 @@ export const useIndexPattern = (services: DiscoverViewServices) => { store, toastNotifications, uiSettings, - query?.dataset, + query.dataset, + data.query.queryString, ]); return indexPattern;