Skip to content

Commit

Permalink
[ML] Transforms: Improve transform list reloading behavior. (#164296)
Browse files Browse the repository at this point in the history
## Summary

- If the transform list fails to load, it does no longer show a
non-refreshable full page error. Instead the error is shown in an inline
callout and the refresh button is still present.
- `AuthorizationProvider` is gone and has been replaced by a custom
hook `useTransformCapabilities`. All client side code no longer relies
on `privileges` being present but makes use of `capabilities` (like
`canGetTransform` etc.). The custom route to fetch privileges and
capabilities is also gone, instead capabilities are retrieved from
Kibana's own `application.capabilities.transform` which we register
server side.
- Refactors all remote data fetching to use `react-query`. This gets
rid of the custom code to refresh the transform list using observables,
instead all CRUD actions now make use of `react-query`'s `useMutation`
and trigger a cache invalidation of the transform list data to initiate
a refetch. The `useApi` hook is gone, instead we now have specific hooks
for data fetching that wrap `useQuery` (`useGetTransform`,
`useGetTransformStats` etc.) and the existing hooks for actions have
been refactored to use `useMutation` (`useStartTransforms`,
`useStopTransforms` etc.).
- Toasts for "success" messages have been removed.
- All tests that made use of `toMatchSnapshot` have been refactored
away from `enzyme` to `react-testing-lib` and no longer rely on
snapshots, instead we make basic assertions on the rendered components.

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [x] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
  • Loading branch information
walterra authored Sep 1, 2023
1 parent e52dd71 commit 0b705eb
Show file tree
Hide file tree
Showing 163 changed files with 2,402 additions and 4,093 deletions.
2 changes: 1 addition & 1 deletion x-pack/plugins/transform/common/api_schemas/transforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { schema, TypeOf } from '@kbn/config-schema';
import { schema, type TypeOf } from '@kbn/config-schema';

import type { ES_FIELD_TYPES } from '@kbn/field-types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { getTransformsRequestSchema } from './transforms';

export const getTransformsStatsRequestSchema = getTransformsRequestSchema;

export type GetTransformsRequestSchema = TypeOf<typeof getTransformsStatsRequestSchema>;
export type GetTransformsStatsRequestSchema = TypeOf<typeof getTransformsStatsRequestSchema>;

export interface GetTransformsStatsResponseSchema {
node_failures?: object;
Expand Down
147 changes: 0 additions & 147 deletions x-pack/plugins/transform/common/api_schemas/type_guards.ts

This file was deleted.

31 changes: 15 additions & 16 deletions x-pack/plugins/transform/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ const EXTERNAL_API_BASE_PATH = '/api/transform/';
export const addInternalBasePath = (uri: string): string => `${INTERNAL_API_BASE_PATH}${uri}`;
export const addExternalBasePath = (uri: string): string => `${EXTERNAL_API_BASE_PATH}${uri}`;

export const TRANSFORM_REACT_QUERY_KEYS = {
DATA_SEARCH: 'transform.data_search',
DATA_VIEW_EXISTS: 'transform.data_view_exists',
GET_DATA_VIEW_TITLES: 'transform.get_data_view_titles',
GET_ES_INDICES: 'transform.get_es_indices',
GET_ES_INGEST_PIPELINES: 'transform.get_es_ingest_pipelines',
GET_HISTOGRAMS_FOR_FIELDS: 'transform.get_histograms_for_fields',
GET_TRANSFORM: 'transform.get_transform',
GET_TRANSFORM_NODES: 'transform.get_transform_nodes',
GET_TRANSFORM_AUDIT_MESSAGES: 'transform.get_transform_audit_messages',
GET_TRANSFORM_STATS: 'transform.get_transform_stats',
GET_TRANSFORMS: 'transform.get_transforms',
GET_TRANSFORMS_PREVIEW: 'transform.get_transforms_preview',
} as const;

// In order to create a transform, the API requires the following privileges:
// - transform_admin (builtin)
// - cluster privileges: manage_transform
Expand Down Expand Up @@ -71,22 +86,6 @@ export const APP_CLUSTER_PRIVILEGES = [
// Minimum privileges required to return transform node count
export const NODES_INFO_PRIVILEGES = ['cluster:monitor/transform/get'];

// Equivalent of capabilities.canGetTransform
export const APP_GET_TRANSFORM_CLUSTER_PRIVILEGES = [
'cluster.cluster:monitor/transform/get',
'cluster.cluster:monitor/transform/stats/get',
];

// Equivalent of capabilities.canCreateTransform
export const APP_CREATE_TRANSFORM_CLUSTER_PRIVILEGES = [
'cluster.cluster:monitor/transform/get',
'cluster.cluster:monitor/transform/stats/get',
'cluster.cluster:admin/transform/preview',
'cluster.cluster:admin/transform/put',
'cluster.cluster:admin/transform/start',
'cluster.cluster:admin/transform/start_task',
];

export const APP_INDEX_PRIVILEGES = ['monitor'];

// reflects https://github.com/elastic/elasticsearch/blob/master/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/TransformStats.java#L214
Expand Down
Loading

0 comments on commit 0b705eb

Please sign in to comment.