-
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.
refactor IndexService into custom hooks using react-query
- Loading branch information
Showing
6 changed files
with
117 additions
and
89 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
33 changes: 33 additions & 0 deletions
33
x-pack/plugins/transform/public/app/hooks/use_can_delete_index.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,33 @@ | ||
/* | ||
* 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 type { PrivilegesAndCapabilities } from '../../../common/privilege/has_privilege_factory'; | ||
import { addInternalBasePath, TRANSFORM_REACT_QUERY_KEYS } from '../../../common/constants'; | ||
|
||
import { useAppDependencies } from '../app_dependencies'; | ||
|
||
export const useCanDeleteIndex = () => { | ||
const { http } = useAppDependencies(); | ||
|
||
return useQuery<boolean, IHttpFetchError>( | ||
[TRANSFORM_REACT_QUERY_KEYS.CAN_DELETE_INDEX], | ||
async ({ signal }) => { | ||
const resp = await http.get<PrivilegesAndCapabilities>(addInternalBasePath('privileges'), { | ||
version: '1', | ||
signal, | ||
}); | ||
if (!resp) { | ||
return false; | ||
} | ||
return resp.privileges.hasAllPrivileges; | ||
} | ||
); | ||
}; |
32 changes: 32 additions & 0 deletions
32
x-pack/plugins/transform/public/app/hooks/use_data_view_exists.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,32 @@ | ||
/* | ||
* 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 { ErrorType } from '@kbn/ml-error-utils'; | ||
|
||
import { TRANSFORM_REACT_QUERY_KEYS } from '../../../common/constants'; | ||
|
||
import { useAppDependencies } from '../app_dependencies'; | ||
|
||
export const useDataViewExists = (indexName?: string, enabled?: boolean, initialData?: boolean) => { | ||
const { | ||
data: { dataViews: dataViewsContract }, | ||
} = useAppDependencies(); | ||
|
||
return useQuery<boolean, ErrorType>( | ||
[TRANSFORM_REACT_QUERY_KEYS.DATA_VIEW_EXISTS, indexName], | ||
async () => { | ||
if (indexName === undefined) { | ||
return false; | ||
} | ||
|
||
return (await dataViewsContract.find(indexName)).some(({ title }) => title === indexName); | ||
}, | ||
{ enabled, initialData } | ||
); | ||
}; |
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
29 changes: 0 additions & 29 deletions
29
x-pack/plugins/transform/public/app/services/es_index_service.ts
This file was deleted.
Oops, something went wrong.