-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrate rest of useApi to react-query
- Loading branch information
Showing
7 changed files
with
127 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 0 additions & 35 deletions
35
x-pack/plugins/transform/public/app/hooks/__mocks__/use_api.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
66 changes: 66 additions & 0 deletions
66
x-pack/plugins/transform/public/app/hooks/use_get_histograms_for_fields.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { useQuery } from '@tanstack/react-query'; | ||
|
||
import type { IHttpFetchError } from '@kbn/core-http-browser'; | ||
import { KBN_FIELD_TYPES } from '@kbn/field-types'; | ||
import { DEFAULT_SAMPLER_SHARD_SIZE } from '@kbn/ml-agg-utils'; | ||
|
||
import { addInternalBasePath, TRANSFORM_REACT_QUERY_KEYS } from '../../../common/constants'; | ||
import type { | ||
FieldHistogramsRequestSchema, | ||
FieldHistogramsResponseSchema, | ||
} from '../../../common/api_schemas/field_histograms'; | ||
|
||
import { useAppDependencies } from '../app_dependencies'; | ||
|
||
import type { SavedSearchQuery } from './use_search_items'; | ||
|
||
export interface FieldHistogramRequestConfig { | ||
fieldName: string; | ||
type?: KBN_FIELD_TYPES; | ||
} | ||
|
||
export const useGetHistogramsForFields = ( | ||
dataViewTitle: string, | ||
fields: FieldHistogramRequestConfig[], | ||
query: string | SavedSearchQuery, | ||
runtimeMappings?: FieldHistogramsRequestSchema['runtimeMappings'], | ||
enabled?: boolean, | ||
samplerShardSize = DEFAULT_SAMPLER_SHARD_SIZE | ||
) => { | ||
const { http } = useAppDependencies(); | ||
|
||
return useQuery<FieldHistogramsResponseSchema, IHttpFetchError>( | ||
[ | ||
TRANSFORM_REACT_QUERY_KEYS.GET_HISTOGRAMS_FOR_FIELDS, | ||
{ | ||
dataViewTitle, | ||
fields, | ||
query, | ||
runtimeMappings, | ||
samplerShardSize, | ||
}, | ||
], | ||
({ signal }) => | ||
http.post<FieldHistogramsResponseSchema>( | ||
addInternalBasePath(`field_histograms/${dataViewTitle}`), | ||
{ | ||
body: JSON.stringify({ | ||
query, | ||
fields, | ||
samplerShardSize, | ||
...(runtimeMappings !== undefined ? { runtimeMappings } : {}), | ||
}), | ||
version: '1', | ||
signal, | ||
} | ||
), | ||
{ enabled } | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters