-
Notifications
You must be signed in to change notification settings - Fork 8.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ML] Transforms: Adds reset action to transforms management. #123735
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
07d9e7a
[ML] Adds reset action to transforms management.
walterra ee15a85
[ML] Fix capabilities. Fix tests.
walterra f608ad7
[ML] Fix translations.
walterra 894b117
[ML] Extend functional tests.
walterra de12f96
[ML] Fix action name.
walterra b7cfbe7
Merge branch 'main' into ml-transform-reset
walterra 044b4da
[ML] Fix comment.
walterra ab14042
[ML] Adds reset transform API tests.
walterra 2b4cd35
Merge branch 'main' into ml-transform-reset
walterra 53a349b
Merge branch 'main' into ml-transform-reset
kibanamachine 591e8ef
Merge branch 'main' into ml-transform-reset
walterra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
x-pack/plugins/transform/common/api_schemas/reset_transforms.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 { schema, TypeOf } from '@kbn/config-schema'; | ||
|
||
import { transformStateSchema, ResponseStatus } from './common'; | ||
|
||
export const resetTransformsRequestSchema = schema.object({ | ||
/** | ||
* Reset Transforms | ||
*/ | ||
transformsInfo: schema.arrayOf( | ||
schema.object({ | ||
id: schema.string(), | ||
state: transformStateSchema, | ||
}) | ||
), | ||
}); | ||
|
||
export type ResetTransformsRequestSchema = TypeOf<typeof resetTransformsRequestSchema>; | ||
|
||
export interface ResetTransformStatus { | ||
transformReset: ResponseStatus; | ||
} | ||
|
||
export interface ResetTransformsResponseSchema { | ||
[key: string]: ResetTransformStatus; | ||
} |
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
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
112 changes: 112 additions & 0 deletions
112
x-pack/plugins/transform/public/app/hooks/use_reset_transform.tsx
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,112 @@ | ||
/* | ||
* 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 React from 'react'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { toMountPoint } from '../../../../../../src/plugins/kibana_react/public'; | ||
import type { | ||
ResetTransformStatus, | ||
ResetTransformsRequestSchema, | ||
} from '../../../common/api_schemas/reset_transforms'; | ||
import { isResetTransformsResponseSchema } from '../../../common/api_schemas/type_guards'; | ||
import { getErrorMessage } from '../../../common/utils/errors'; | ||
import { useAppDependencies, useToastNotifications } from '../app_dependencies'; | ||
import { REFRESH_TRANSFORM_LIST_STATE, refreshTransformList$ } from '../common'; | ||
import { ToastNotificationText } from '../components'; | ||
import { useApi } from './use_api'; | ||
|
||
type SuccessCountField = keyof Omit<ResetTransformStatus, 'destinationIndex'>; | ||
|
||
export const useResetTransforms = () => { | ||
const { overlays, theme } = useAppDependencies(); | ||
const toastNotifications = useToastNotifications(); | ||
const api = useApi(); | ||
|
||
return async (reqBody: ResetTransformsRequestSchema) => { | ||
const results = await api.resetTransforms(reqBody); | ||
|
||
if (!isResetTransformsResponseSchema(results)) { | ||
toastNotifications.addDanger({ | ||
title: i18n.translate('xpack.transform.transformList.resetTransformGenericErrorMessage', { | ||
defaultMessage: 'An error occurred calling the API endpoint to reset transforms.', | ||
}), | ||
text: toMountPoint( | ||
<ToastNotificationText | ||
previewTextLength={50} | ||
overlays={overlays} | ||
theme={theme} | ||
text={getErrorMessage(results)} | ||
/>, | ||
{ theme$: theme.theme$ } | ||
), | ||
}); | ||
return; | ||
} | ||
|
||
const isBulk = Object.keys(results).length > 1; | ||
const successCount: Record<SuccessCountField, number> = { | ||
transformReset: 0, | ||
}; | ||
for (const transformId in results) { | ||
// hasOwnProperty check to ensure only properties on object itself, and not its prototypes | ||
if (results.hasOwnProperty(transformId)) { | ||
const status = results[transformId]; | ||
|
||
// if we are only resetting one transform, show the success toast messages | ||
if (!isBulk && status.transformReset) { | ||
if (status.transformReset?.success) { | ||
toastNotifications.addSuccess( | ||
i18n.translate('xpack.transform.transformList.resetTransformSuccessMessage', { | ||
defaultMessage: 'Request to reset transform {transformId} acknowledged.', | ||
values: { transformId }, | ||
}) | ||
); | ||
} | ||
} else { | ||
(Object.keys(successCount) as SuccessCountField[]).forEach((key) => { | ||
if (status[key]?.success) { | ||
successCount[key] = successCount[key] + 1; | ||
} | ||
}); | ||
} | ||
if (status.transformReset?.error) { | ||
const error = status.transformReset.error.reason; | ||
toastNotifications.addDanger({ | ||
title: i18n.translate('xpack.transform.transformList.resetTransformErrorMessage', { | ||
defaultMessage: 'An error occurred resetting the transform {transformId}', | ||
values: { transformId }, | ||
}), | ||
text: toMountPoint( | ||
<ToastNotificationText | ||
previewTextLength={50} | ||
overlays={overlays} | ||
theme={theme} | ||
text={error} | ||
/>, | ||
{ theme$: theme.theme$ } | ||
), | ||
}); | ||
} | ||
} | ||
} | ||
|
||
// if we are deleting multiple transforms, combine the success messages | ||
if (isBulk) { | ||
if (successCount.transformReset > 0) { | ||
toastNotifications.addSuccess( | ||
i18n.translate('xpack.transform.transformList.bulkResetTransformSuccessMessage', { | ||
defaultMessage: | ||
'Successfully reset {count} {count, plural, one {transform} other {transforms}}.', | ||
values: { count: successCount.transformReset }, | ||
}) | ||
); | ||
} | ||
} | ||
|
||
refreshTransformList$.next(REFRESH_TRANSFORM_LIST_STATE.REFRESH); | ||
}; | ||
}; |
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
10 changes: 10 additions & 0 deletions
10
...ugins/transform/public/app/sections/transform_management/components/action_reset/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,10 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export { useResetAction } from './use_reset_action'; | ||
export { ResetActionModal } from './reset_action_modal'; | ||
export { isResetActionDisabled, ResetActionName } from './reset_action_name'; |
88 changes: 88 additions & 0 deletions
88
...m/public/app/sections/transform_management/components/action_reset/reset_action_modal.tsx
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,88 @@ | ||
/* | ||
* 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 React, { FC, useMemo } from 'react'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { EUI_MODAL_CONFIRM_BUTTON, EuiConfirmModal, EuiFlexGroup, EuiSpacer } from '@elastic/eui'; | ||
import { ResetAction } from './use_reset_action'; | ||
import { isManagedTransform } from '../../../../common/managed_transforms_utils'; | ||
import { ManagedTransformsWarningCallout } from '../managed_transforms_callout/managed_transforms_callout'; | ||
|
||
export const ResetActionModal: FC<ResetAction> = ({ | ||
closeModal, | ||
resetAndCloseModal, | ||
items, | ||
shouldForceReset, | ||
}) => { | ||
const hasManagedTransforms = useMemo(() => items.some((t) => isManagedTransform(t)), [items]); | ||
const isBulkAction = items.length > 1; | ||
|
||
const bulkResetModalTitle = i18n.translate('xpack.transform.transformList.bulkResetModalTitle', { | ||
defaultMessage: 'Reset {count} {count, plural, one {transform} other {transforms}}?', | ||
values: { count: items.length }, | ||
}); | ||
const resetModalTitle = i18n.translate('xpack.transform.transformList.resetModalTitle', { | ||
defaultMessage: 'Reset {transformId}?', | ||
values: { transformId: items[0] && items[0].config.id }, | ||
}); | ||
const bulkResetModalContent = ( | ||
<> | ||
<EuiFlexGroup direction="column" gutterSize="none"> | ||
{hasManagedTransforms ? ( | ||
<> | ||
<ManagedTransformsWarningCallout | ||
count={items.length} | ||
action={i18n.translate( | ||
'xpack.transform.transformList.resetManagedTransformDescription', | ||
{ defaultMessage: 'resetting' } | ||
)} | ||
/> | ||
<EuiSpacer /> | ||
</> | ||
) : null} | ||
</EuiFlexGroup> | ||
</> | ||
); | ||
|
||
const resetModalContent = ( | ||
<> | ||
<EuiFlexGroup direction="column" gutterSize="none"> | ||
{hasManagedTransforms ? ( | ||
<> | ||
<ManagedTransformsWarningCallout | ||
count={1} | ||
action={i18n.translate( | ||
'xpack.transform.transformList.resetManagedTransformDescription', | ||
{ defaultMessage: 'resetting' } | ||
)} | ||
/> | ||
<EuiSpacer /> | ||
</> | ||
) : null} | ||
</EuiFlexGroup> | ||
</> | ||
); | ||
|
||
return ( | ||
<EuiConfirmModal | ||
data-test-subj="transformResetModal" | ||
title={isBulkAction === true ? bulkResetModalTitle : resetModalTitle} | ||
onCancel={closeModal} | ||
onConfirm={resetAndCloseModal} | ||
cancelButtonText={i18n.translate('xpack.transform.transformList.resetModalCancelButton', { | ||
defaultMessage: 'Cancel', | ||
})} | ||
confirmButtonText={i18n.translate('xpack.transform.transformList.resetModalResetButton', { | ||
defaultMessage: 'Reset', | ||
})} | ||
defaultFocusedButton={EUI_MODAL_CONFIRM_BUTTON} | ||
buttonColor="danger" | ||
> | ||
{isBulkAction ? bulkResetModalContent : resetModalContent} | ||
</EuiConfirmModal> | ||
); | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will there ever be a case a response has a mix of transformReset and something else? Can we use
.some
here? Just curious not a suggestion.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current APIs we have don't allow these combinations at the moment. Depending on the endpoint, this attribute is hard coded for example like
transformDeleted
ortransformReset
.