From 300f185492120c4bfd171b2d30a34ed1b0dd7e92 Mon Sep 17 00:00:00 2001 From: Rodney Norris Date: Fri, 25 Oct 2024 18:02:16 +0000 Subject: [PATCH] fix(search-index-details): poll mappings Updated the mappings call to poll like the index call does so that the UI will refresh when the user adds mappings with the dev console or somewhere else with the window still in focus. Additionally updated the query key for the fetch to save the `fetchMapping` key to the constants so we can track all query keys in one place. --- x-pack/plugins/search_indices/public/constants.ts | 1 + .../search_indices/public/hooks/api/use_index_mappings.ts | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/search_indices/public/constants.ts b/x-pack/plugins/search_indices/public/constants.ts index bf9cf14a4ea17..fa5d7fde6d4c8 100644 --- a/x-pack/plugins/search_indices/public/constants.ts +++ b/x-pack/plugins/search_indices/public/constants.ts @@ -7,6 +7,7 @@ export enum QueryKeys { FetchIndex = 'fetchIndex', + FetchMapping = 'fetchMapping', FetchSearchIndicesStatus = 'fetchSearchIndicesStatus', FetchUserStartPrivileges = 'fetchUserStartPrivileges', SearchDocuments = 'searchDocuments', diff --git a/x-pack/plugins/search_indices/public/hooks/api/use_index_mappings.ts b/x-pack/plugins/search_indices/public/hooks/api/use_index_mappings.ts index 0e57e17465922..1d5a83aa920ed 100644 --- a/x-pack/plugins/search_indices/public/hooks/api/use_index_mappings.ts +++ b/x-pack/plugins/search_indices/public/hooks/api/use_index_mappings.ts @@ -8,12 +8,16 @@ import { useQuery } from '@tanstack/react-query'; import { useKibana } from '../use_kibana'; import { Mappings } from '../../types'; +import { QueryKeys } from '../../constants'; +const POLLING_INTERVAL = 15 * 1000; export const useIndexMapping = (indexName: string) => { const { http } = useKibana().services; - const queryKey = ['fetchMapping', indexName]; + const queryKey = [QueryKeys.FetchMapping, indexName]; const result = useQuery({ queryKey, + refetchInterval: POLLING_INTERVAL, + refetchIntervalInBackground: true, refetchOnWindowFocus: 'always', queryFn: () => http.fetch(`/api/index_management/mapping/${encodeURIComponent(indexName)}`),