From f8d48e47982cbef8f351c0ac4bb5f842f7291116 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Thu, 18 Apr 2024 05:08:45 -0400 Subject: [PATCH] [8.14] [SLOs] Refetch data views on save (#181033) (#181113) # Backport This will backport the following commits from `main` to `8.14`: - [[SLOs] Refetch data views on save (#181033)](https://github.com/elastic/kibana/pull/181033) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Shahzad --- .../observability/public/hooks/use_fetch_data_views.ts | 6 +++--- .../slo_edit/components/custom_common/index_selection.tsx | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/observability_solution/observability/public/hooks/use_fetch_data_views.ts b/x-pack/plugins/observability_solution/observability/public/hooks/use_fetch_data_views.ts index 2d7602431266..3e19bb73d8f0 100644 --- a/x-pack/plugins/observability_solution/observability/public/hooks/use_fetch_data_views.ts +++ b/x-pack/plugins/observability_solution/observability/public/hooks/use_fetch_data_views.ts @@ -16,10 +16,10 @@ export interface UseFetchDataViewsResponse { data: DataViewListItem[] | undefined; } -export function useFetchDataViews(): UseFetchDataViewsResponse { +export function useFetchDataViews() { const { dataViews } = useKibana().services; - const { isLoading, isError, isSuccess, data } = useQuery({ + const { isLoading, isError, isSuccess, data, refetch } = useQuery({ queryKey: ['fetchDataViewsList'], queryFn: async () => { return dataViews.getIdsWithTitle(); @@ -29,5 +29,5 @@ export function useFetchDataViews(): UseFetchDataViewsResponse { refetchOnWindowFocus: false, }); - return { isLoading, isError, isSuccess, data }; + return { isLoading, isError, isSuccess, data, refetch }; } diff --git a/x-pack/plugins/observability_solution/slo/public/pages/slo_edit/components/custom_common/index_selection.tsx b/x-pack/plugins/observability_solution/slo/public/pages/slo_edit/components/custom_common/index_selection.tsx index 880c15e6a67b..fe023cd85954 100644 --- a/x-pack/plugins/observability_solution/slo/public/pages/slo_edit/components/custom_common/index_selection.tsx +++ b/x-pack/plugins/observability_solution/slo/public/pages/slo_edit/components/custom_common/index_selection.tsx @@ -19,7 +19,7 @@ export function IndexSelection() { const { control, getFieldState, setValue, watch } = useFormContext(); const { dataViews: dataViewsService } = useKibana().services; - const { isLoading: isDataViewsLoading, data: dataViews = [] } = useFetchDataViews(); + const { isLoading: isDataViewsLoading, data: dataViews = [], refetch } = useFetchDataViews(); const { dataViewEditor } = useKibana().services; @@ -100,7 +100,8 @@ export function IndexSelection() { setAdHocDataViews([...adHocDataViews, dataView]); field.onChange(dataView.getIndexPattern()); } else { - field.onChange(getDataViewPatternById(dataView.id)); + refetch(); + field.onChange(dataView.getIndexPattern()); } if (dataView.timeFieldName) { setValue('indicator.params.timestampField', dataView.timeFieldName);