Skip to content

Commit

Permalink
fix(search-index-details): poll mappings
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
TattdCodeMonkey committed Oct 25, 2024
1 parent 10f234c commit 300f185
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions x-pack/plugins/search_indices/public/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

export enum QueryKeys {
FetchIndex = 'fetchIndex',
FetchMapping = 'fetchMapping',
FetchSearchIndicesStatus = 'fetchSearchIndicesStatus',
FetchUserStartPrivileges = 'fetchUserStartPrivileges',
SearchDocuments = 'searchDocuments',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Mappings, { body: { message: string; error: string } }>({
queryKey,
refetchInterval: POLLING_INTERVAL,
refetchIntervalInBackground: true,
refetchOnWindowFocus: 'always',
queryFn: () =>
http.fetch<Mappings>(`/api/index_management/mapping/${encodeURIComponent(indexName)}`),
Expand Down

0 comments on commit 300f185

Please sign in to comment.