-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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 _schedule_now
action to transform list.
#153545
Merged
walterra
merged 13 commits into
elastic:main
from
walterra:ml-150350-transform-schedule-now
Mar 26, 2023
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8f1fadd
adds _schedule_now action
walterra f991e5a
fix i18n
walterra 0ca8fbe
fix bulk menu disabled status
walterra 69df7c2
fix jest tests
walterra 967f452
add missing privilege
walterra bdff00b
fix line reference
walterra ca7197e
fix i18n
walterra 02b902b
Merge branch 'main' into ml-150350-transform-schedule-now
walterra f4898da
remove schedule now confirmation modal
walterra f0ed391
tweak texts
walterra a92b1ae
adds default tooltip to schedule-now button
walterra 24ba764
fix modal removal
walterra 3563f14
API integration test
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
14 changes: 14 additions & 0 deletions
14
x-pack/plugins/transform/common/api_schemas/schedule_now_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,14 @@ | ||
/* | ||
* 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 { TypeOf } from '@kbn/config-schema'; | ||
|
||
import { transformIdsSchema, CommonResponseStatusSchema } from './common'; | ||
|
||
export const scheduleNowTransformsRequestSchema = transformIdsSchema; | ||
export type ScheduleNowTransformsRequestSchema = TypeOf<typeof scheduleNowTransformsRequestSchema>; | ||
export type ScheduleNowTransformsResponseSchema = CommonResponseStatusSchema; |
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
84 changes: 84 additions & 0 deletions
84
x-pack/plugins/transform/public/app/hooks/use_schedule_now_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,84 @@ | ||
/* | ||
* 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 '@kbn/kibana-react-plugin/public'; | ||
|
||
import type { ScheduleNowTransformsRequestSchema } from '../../../common/api_schemas/schedule_now_transforms'; | ||
import { isScheduleNowTransformsResponseSchema } from '../../../common/api_schemas/type_guards'; | ||
|
||
import { getErrorMessage } from '../../../common/utils/errors'; | ||
|
||
import { useAppDependencies, useToastNotifications } from '../app_dependencies'; | ||
import { refreshTransformList$, REFRESH_TRANSFORM_LIST_STATE } from '../common'; | ||
import { ToastNotificationText } from '../components'; | ||
|
||
import { useApi } from './use_api'; | ||
|
||
export const useScheduleNowTransforms = () => { | ||
const { overlays, theme } = useAppDependencies(); | ||
const toastNotifications = useToastNotifications(); | ||
const api = useApi(); | ||
|
||
return async (transformsInfo: ScheduleNowTransformsRequestSchema) => { | ||
const results = await api.scheduleNowTransforms(transformsInfo); | ||
|
||
if (!isScheduleNowTransformsResponseSchema(results)) { | ||
toastNotifications.addDanger({ | ||
title: i18n.translate( | ||
'xpack.transform.stepCreateForm.scheduleNowTransformResponseSchemaErrorMessage', | ||
{ | ||
defaultMessage: | ||
'An error occurred calling the request to schedule the transform to process data instantly.', | ||
} | ||
), | ||
text: toMountPoint( | ||
<ToastNotificationText | ||
overlays={overlays} | ||
theme={theme} | ||
text={getErrorMessage(results)} | ||
/>, | ||
{ theme$: theme.theme$ } | ||
), | ||
}); | ||
return; | ||
} | ||
|
||
for (const transformId in results) { | ||
// hasOwnProperty check to ensure only properties on object itself, and not its prototypes | ||
if (results.hasOwnProperty(transformId)) { | ||
const result = results[transformId]; | ||
if (result.success === true) { | ||
toastNotifications.addSuccess( | ||
i18n.translate('xpack.transform.transformList.scheduleNowTransformSuccessMessage', { | ||
defaultMessage: | ||
'Request to schedule transform {transformId} to process data instantly acknowledged.', | ||
values: { transformId }, | ||
}) | ||
); | ||
} else { | ||
toastNotifications.addError(new Error(JSON.stringify(result.error!.caused_by, null, 2)), { | ||
title: i18n.translate( | ||
'xpack.transform.transformList.scheduleNowTransformErrorMessage', | ||
{ | ||
defaultMessage: | ||
'An error occurred scheduling transform {transformId} to process data instantly.', | ||
values: { transformId }, | ||
} | ||
), | ||
toastMessage: result.error!.reason, | ||
}); | ||
} | ||
} | ||
} | ||
|
||
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
9 changes: 9 additions & 0 deletions
9
...ransform/public/app/sections/transform_management/components/action_schedule_now/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,9 @@ | ||
/* | ||
* 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 { useScheduleNowAction } from './use_schedule_now_action'; | ||
export { isScheduleNowActionDisabled, ScheduleNowActionName } from './schedule_now_action_name'; |
102 changes: 102 additions & 0 deletions
102
...sections/transform_management/components/action_schedule_now/schedule_now_action_name.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,102 @@ | ||
/* | ||
* 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, useContext } from 'react'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { EuiToolTip } from '@elastic/eui'; | ||
|
||
import { | ||
createCapabilityFailureMessage, | ||
AuthorizationContext, | ||
} from '../../../../lib/authorization'; | ||
import { TransformListRow, isCompletedBatchTransform } from '../../../../common'; | ||
|
||
export const scheduleNowActionNameText = i18n.translate( | ||
'xpack.transform.transformList.scheduleNowActionNameText', | ||
{ | ||
defaultMessage: 'Schedule now', | ||
} | ||
); | ||
|
||
export const isScheduleNowActionDisabled = ( | ||
items: TransformListRow[], | ||
canScheduleNowTransform: boolean, | ||
transformNodes: number | ||
) => { | ||
// Disable schedule-now for batch transforms which have completed. | ||
const completedBatchTransform = items.some((i: TransformListRow) => isCompletedBatchTransform(i)); | ||
|
||
return ( | ||
!canScheduleNowTransform || | ||
completedBatchTransform || | ||
items.length === 0 || | ||
transformNodes === 0 | ||
); | ||
}; | ||
|
||
export interface ScheduleNowActionNameProps { | ||
items: TransformListRow[]; | ||
forceDisable?: boolean; | ||
transformNodes: number; | ||
} | ||
export const ScheduleNowActionName: FC<ScheduleNowActionNameProps> = ({ | ||
items, | ||
forceDisable, | ||
transformNodes, | ||
}) => { | ||
const { canScheduleNowTransform } = useContext(AuthorizationContext).capabilities; | ||
const isBulkAction = items.length > 1; | ||
|
||
// Disable schedule-now for batch transforms which have completed. | ||
const completedBatchTransform = items.some((i: TransformListRow) => isCompletedBatchTransform(i)); | ||
|
||
let completedBatchTransformMessage; | ||
|
||
if (isBulkAction === true) { | ||
completedBatchTransformMessage = i18n.translate( | ||
'xpack.transform.transformList.cannotScheduleNowCompleteBatchTransformBulkActionToolTip', | ||
{ | ||
defaultMessage: | ||
'One or more transforms are completed batch transforms and cannot be scheduled to process data instantly.', | ||
} | ||
); | ||
} else { | ||
completedBatchTransformMessage = i18n.translate( | ||
'xpack.transform.transformList.cannotScheduleNowCompleteBatchTransformToolTip', | ||
{ | ||
defaultMessage: | ||
'{transformId} is a completed batch transform and cannot be scheduled to process data instantly.', | ||
values: { transformId: items[0] && items[0].config.id }, | ||
} | ||
); | ||
} | ||
|
||
const actionIsDisabled = isScheduleNowActionDisabled( | ||
items, | ||
canScheduleNowTransform, | ||
transformNodes | ||
); | ||
|
||
let content: string = i18n.translate('xpack.transform.transformList.scheduleNowToolTip', { | ||
defaultMessage: | ||
'Schedule the transform to instantly process data without waiting for the configured interval between checks for changes in the source indices.', | ||
}); | ||
|
||
if (actionIsDisabled && items.length > 0) { | ||
if (!canScheduleNowTransform) { | ||
content = createCapabilityFailureMessage('canScheduleNowTransform'); | ||
} else if (completedBatchTransform) { | ||
content = completedBatchTransformMessage; | ||
} | ||
} | ||
|
||
return ( | ||
<EuiToolTip position="top" content={content}> | ||
<>{scheduleNowActionNameText}</> | ||
</EuiToolTip> | ||
); | ||
}; |
53 changes: 53 additions & 0 deletions
53
.../sections/transform_management/components/action_schedule_now/use_schedule_now_action.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,53 @@ | ||
/* | ||
* 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, { useContext, useMemo } from 'react'; | ||
|
||
import { TRANSFORM_STATE } from '../../../../../../common/constants'; | ||
|
||
import { AuthorizationContext } from '../../../../lib/authorization'; | ||
import { TransformListAction, TransformListRow } from '../../../../common'; | ||
import { useScheduleNowTransforms } from '../../../../hooks'; | ||
|
||
import { | ||
isScheduleNowActionDisabled, | ||
scheduleNowActionNameText, | ||
ScheduleNowActionName, | ||
} from './schedule_now_action_name'; | ||
|
||
export type ScheduleNowAction = ReturnType<typeof useScheduleNowAction>; | ||
export const useScheduleNowAction = (forceDisable: boolean, transformNodes: number) => { | ||
const { canScheduleNowTransform } = useContext(AuthorizationContext).capabilities; | ||
|
||
const scheduleNowTransforms = useScheduleNowTransforms(); | ||
|
||
const action: TransformListAction = useMemo( | ||
() => ({ | ||
name: (item: TransformListRow) => ( | ||
qn895 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<ScheduleNowActionName | ||
items={[item]} | ||
forceDisable={forceDisable} | ||
transformNodes={transformNodes} | ||
/> | ||
), | ||
available: (item: TransformListRow) => item.stats.state === TRANSFORM_STATE.STARTED, | ||
enabled: (item: TransformListRow) => | ||
!isScheduleNowActionDisabled([item], canScheduleNowTransform, transformNodes), | ||
description: scheduleNowActionNameText, | ||
icon: 'play', | ||
type: 'icon', | ||
onClick: (item: TransformListRow) => scheduleNowTransforms([{ id: item.id }]), | ||
'data-test-subj': 'transformActionScheduleNow', | ||
}), | ||
[canScheduleNowTransform, forceDisable, scheduleNowTransforms, transformNodes] | ||
); | ||
|
||
return { | ||
action, | ||
scheduleNowTransforms, | ||
}; | ||
}; |
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
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.
Can you add a tooltip to this button to provide clarification as to what this action does as @qn895 suggested?
Something like
Instantly run the transform to process data without waiting for the configured interval between checks for changes in the source indices.
?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.
Added a tooltip in a92b1ae.