-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[ML] DF Analytics: add ability to edit job for fields supported by API #70489
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
Merged
alvarezmelissa87
merged 9 commits into
elastic:master
from
alvarezmelissa87:ml-dfanalytics-edit-job
Jul 6, 2020
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d8af951
wip: add edit action to dfanalytics table
alvarezmelissa87 0ad6733
add update endpoint and edit flyout
alvarezmelissa87 59e7f21
show success and error toasts. close flyout and refresh on success
alvarezmelissa87 0db640d
show permission message in edit action
alvarezmelissa87 ffedb7c
update types
alvarezmelissa87 9ac1b43
disable update button if mml not valid
alvarezmelissa87 4d5f238
show error in toast, init values are config values
alvarezmelissa87 81a73e6
fix undefined check for allow lazy start
alvarezmelissa87 4783bab
prevent update if mml is empty
alvarezmelissa87 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
This file contains hidden or 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 hidden or 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 hidden or 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
66 changes: 66 additions & 0 deletions
66
...data_frame_analytics/pages/analytics_management/components/analytics_list/action_edit.tsx
This file contains hidden or 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; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| import React, { useState, FC } from 'react'; | ||
|
|
||
| import { i18n } from '@kbn/i18n'; | ||
|
|
||
| import { EuiButtonEmpty, EuiToolTip } from '@elastic/eui'; | ||
|
|
||
| import { checkPermission } from '../../../../../capabilities/check_capabilities'; | ||
| import { DataFrameAnalyticsListRow } from './common'; | ||
|
|
||
| import { EditAnalyticsFlyout } from './edit_analytics_flyout'; | ||
|
|
||
| interface EditActionProps { | ||
| item: DataFrameAnalyticsListRow; | ||
| } | ||
|
|
||
| export const EditAction: FC<EditActionProps> = ({ item }) => { | ||
| const canCreateDataFrameAnalytics: boolean = checkPermission('canCreateDataFrameAnalytics'); | ||
|
|
||
| const [isFlyoutVisible, setIsFlyoutVisible] = useState(false); | ||
| const closeFlyout = () => setIsFlyoutVisible(false); | ||
| const showFlyout = () => setIsFlyoutVisible(true); | ||
|
|
||
| const buttonEditText = i18n.translate('xpack.ml.dataframe.analyticsList.editActionName', { | ||
| defaultMessage: 'Edit', | ||
| }); | ||
|
|
||
| const editButton = ( | ||
| <EuiButtonEmpty | ||
| data-test-subj="mlAnalyticsJobEditButton" | ||
| size="xs" | ||
| color="text" | ||
| disabled={!canCreateDataFrameAnalytics} | ||
| iconType="copy" | ||
| onClick={showFlyout} | ||
| aria-label={buttonEditText} | ||
| > | ||
| {buttonEditText} | ||
| </EuiButtonEmpty> | ||
| ); | ||
|
|
||
| if (!canCreateDataFrameAnalytics) { | ||
| return ( | ||
| <EuiToolTip | ||
| position="top" | ||
| content={i18n.translate('xpack.ml.dataframe.analyticsList.editActionPermissionTooltip', { | ||
| defaultMessage: 'You do not have permission to edit analytics jobs.', | ||
| })} | ||
| > | ||
| {editButton} | ||
| </EuiToolTip> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <> | ||
| {editButton} | ||
| {isFlyoutVisible && <EditAnalyticsFlyout closeFlyout={closeFlyout} item={item} />} | ||
| </> | ||
| ); | ||
| }; |
This file contains hidden or 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
270 changes: 270 additions & 0 deletions
270
..._analytics/pages/analytics_management/components/analytics_list/edit_analytics_flyout.tsx
This file contains hidden or 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,270 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| import React, { FC, useEffect, useState } from 'react'; | ||
|
|
||
| import { i18n } from '@kbn/i18n'; | ||
|
|
||
| import { | ||
| EuiButton, | ||
| EuiButtonEmpty, | ||
| EuiFieldText, | ||
| EuiFlexGroup, | ||
| EuiFlexItem, | ||
| EuiFlyout, | ||
| EuiFlyoutBody, | ||
| EuiFlyoutFooter, | ||
| EuiFlyoutHeader, | ||
| EuiForm, | ||
| EuiFormRow, | ||
| EuiOverlayMask, | ||
| EuiSelect, | ||
| EuiTitle, | ||
| } from '@elastic/eui'; | ||
|
|
||
| import { useMlKibana } from '../../../../../contexts/kibana'; | ||
| import { ml } from '../../../../../services/ml_api_service'; | ||
| import { | ||
| memoryInputValidator, | ||
| MemoryInputValidatorResult, | ||
| } from '../../../../../../../common/util/validators'; | ||
| import { extractErrorMessage } from '../../../../../../../common/util/errors'; | ||
| import { DataFrameAnalyticsListRow, DATA_FRAME_TASK_STATE } from './common'; | ||
| import { | ||
| useRefreshAnalyticsList, | ||
| UpdateDataFrameAnalyticsConfig, | ||
| } from '../../../../common/analytics'; | ||
|
|
||
| interface EditAnalyticsJobFlyoutProps { | ||
| closeFlyout: () => void; | ||
| item: DataFrameAnalyticsListRow; | ||
| } | ||
|
|
||
| let mmLValidator: (value: any) => MemoryInputValidatorResult; | ||
|
|
||
| export const EditAnalyticsFlyout: FC<EditAnalyticsJobFlyoutProps> = ({ closeFlyout, item }) => { | ||
| const { id: jobId, config } = item; | ||
| const { state } = item.stats; | ||
| const initialAllowLazyStart = | ||
| config.allow_lazy_start !== undefined ? String(config.allow_lazy_start) : ''; | ||
|
|
||
| const [allowLazyStart, setAllowLazyStart] = useState<string>(initialAllowLazyStart); | ||
| const [description, setDescription] = useState<string>(config.description || ''); | ||
| const [modelMemoryLimit, setModelMemoryLimit] = useState<string>(config.model_memory_limit); | ||
| const [mmlValidationError, setMmlValidationError] = useState<string | undefined>(); | ||
|
|
||
| const { | ||
| services: { notifications }, | ||
| } = useMlKibana(); | ||
| const { refresh } = useRefreshAnalyticsList(); | ||
|
|
||
| // Disable if mml is not valid | ||
| const updateButtonDisabled = mmlValidationError !== undefined; | ||
|
|
||
| useEffect(() => { | ||
| if (mmLValidator === undefined) { | ||
| mmLValidator = memoryInputValidator(); | ||
| } | ||
| // validate mml and create validation message | ||
| if (modelMemoryLimit !== '') { | ||
| const validationResult = mmLValidator(modelMemoryLimit); | ||
| if (validationResult !== null && validationResult.invalidUnits) { | ||
| setMmlValidationError( | ||
| i18n.translate('xpack.ml.dataframe.analytics.create.modelMemoryUnitsInvalidError', { | ||
| defaultMessage: 'Model memory limit data unit unrecognized. It must be {str}', | ||
qn895 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| values: { str: validationResult.invalidUnits.allowedUnits }, | ||
| }) | ||
| ); | ||
| } else { | ||
| setMmlValidationError(undefined); | ||
| } | ||
| } else { | ||
| setMmlValidationError( | ||
| i18n.translate('xpack.ml.dataframe.analytics.create.modelMemoryEmptyError', { | ||
| defaultMessage: 'Model memory limit must not be empty', | ||
| }) | ||
| ); | ||
| } | ||
| }, [modelMemoryLimit]); | ||
|
|
||
| const onSubmit = async () => { | ||
| const updateConfig: UpdateDataFrameAnalyticsConfig = Object.assign( | ||
| { | ||
| allow_lazy_start: allowLazyStart, | ||
| description, | ||
| }, | ||
| modelMemoryLimit && { model_memory_limit: modelMemoryLimit } | ||
| ); | ||
|
|
||
| try { | ||
| await ml.dataFrameAnalytics.updateDataFrameAnalytics(jobId, updateConfig); | ||
| notifications.toasts.addSuccess( | ||
| i18n.translate('xpack.ml.dataframe.analyticsList.editFlyoutSuccessMessage', { | ||
| defaultMessage: 'Analytics job {jobId} has been updated.', | ||
| values: { jobId }, | ||
| }) | ||
| ); | ||
| refresh(); | ||
| closeFlyout(); | ||
| } catch (e) { | ||
| // eslint-disable-next-line | ||
| console.error(e); | ||
|
|
||
| notifications.toasts.addDanger({ | ||
| title: i18n.translate('xpack.ml.dataframe.analyticsList.editFlyoutErrorMessage', { | ||
| defaultMessage: 'Could not save changes to analytics job {jobId}', | ||
| values: { | ||
| jobId, | ||
| }, | ||
| }), | ||
| text: extractErrorMessage(e), | ||
| }); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <EuiOverlayMask> | ||
| <EuiFlyout | ||
| onClose={closeFlyout} | ||
| hideCloseButton | ||
| aria-labelledby="analyticsEditFlyoutTitle" | ||
| data-test-subj="analyticsEditFlyout" | ||
| > | ||
| <EuiFlyoutHeader hasBorder> | ||
| <EuiTitle size="m"> | ||
| <h2 id="analyticsEditFlyoutTitle"> | ||
| {i18n.translate('xpack.ml.dataframe.analyticsList.editFlyoutTitle', { | ||
| defaultMessage: 'Edit {jobId}', | ||
| values: { | ||
| jobId, | ||
| }, | ||
| })} | ||
| </h2> | ||
| </EuiTitle> | ||
| </EuiFlyoutHeader> | ||
| <EuiFlyoutBody> | ||
| <EuiForm> | ||
| <EuiFormRow | ||
| label={i18n.translate( | ||
| 'xpack.ml.dataframe.analyticsList.editFlyout.allowLazyStartLabel', | ||
| { | ||
| defaultMessage: 'Allow lazy start', | ||
| } | ||
| )} | ||
| > | ||
| <EuiSelect | ||
| aria-label={i18n.translate( | ||
| 'xpack.ml.dataframe.analyticsList.editFlyout.allowLazyStartAriaLabel', | ||
| { | ||
| defaultMessage: 'Update allow lazy start.', | ||
| } | ||
| )} | ||
| data-test-subj="mlAnalyticsEditFlyoutAllowLazyStartInput" | ||
| options={[ | ||
| { | ||
| value: 'true', | ||
| text: i18n.translate( | ||
| 'xpack.ml.dataframe.analyticsList.editFlyout.allowLazyStartTrueValue', | ||
| { | ||
| defaultMessage: 'True', | ||
| } | ||
| ), | ||
| }, | ||
| { | ||
| value: 'false', | ||
| text: i18n.translate( | ||
| 'xpack.ml.dataframe.analyticsList.editFlyout.allowLazyStartFalseValue', | ||
| { | ||
| defaultMessage: 'False', | ||
| } | ||
| ), | ||
| }, | ||
| ]} | ||
| value={allowLazyStart} | ||
| onChange={(e: React.ChangeEvent<HTMLSelectElement>) => | ||
| setAllowLazyStart(e.target.value) | ||
| } | ||
| /> | ||
| </EuiFormRow> | ||
| <EuiFormRow | ||
| label={i18n.translate( | ||
| 'xpack.ml.dataframe.analyticsList.editFlyout.descriptionLabel', | ||
| { | ||
| defaultMessage: 'Description', | ||
| } | ||
| )} | ||
| > | ||
| <EuiFieldText | ||
| data-test-subj="mlAnalyticsEditFlyoutDescriptionInput" | ||
| value={description} | ||
| onChange={(e) => setDescription(e.target.value)} | ||
| aria-label={i18n.translate( | ||
| 'xpack.ml.dataframe.analyticsList.editFlyout.descriptionAriaLabel', | ||
| { | ||
| defaultMessage: 'Update the job description.', | ||
| } | ||
| )} | ||
| /> | ||
| </EuiFormRow> | ||
| <EuiFormRow | ||
| helpText={ | ||
| state !== DATA_FRAME_TASK_STATE.STOPPED && | ||
| i18n.translate('xpack.ml.dataframe.analyticsList.editFlyout.modelMemoryHelpText', { | ||
| defaultMessage: 'Model memory limit cannot be edited while the job is running.', | ||
| }) | ||
| } | ||
| label={i18n.translate( | ||
| 'xpack.ml.dataframe.analyticsList.editFlyout.modelMemoryLimitLabel', | ||
| { | ||
| defaultMessage: 'Model memory limit', | ||
| } | ||
| )} | ||
| isInvalid={mmlValidationError !== undefined} | ||
| error={mmlValidationError} | ||
| > | ||
| <EuiFieldText | ||
| data-test-subj="mlAnalyticsEditFlyoutmodelMemoryLimitInput" | ||
| isInvalid={mmlValidationError !== undefined} | ||
| readOnly={state !== DATA_FRAME_TASK_STATE.STOPPED} | ||
| value={modelMemoryLimit} | ||
| onChange={(e) => setModelMemoryLimit(e.target.value)} | ||
| aria-label={i18n.translate( | ||
| 'xpack.ml.dataframe.analyticsList.editFlyout.modelMemoryLimitAriaLabel', | ||
| { | ||
| defaultMessage: 'Update the model memory limit.', | ||
| } | ||
| )} | ||
| /> | ||
| </EuiFormRow> | ||
| </EuiForm> | ||
| </EuiFlyoutBody> | ||
| <EuiFlyoutFooter> | ||
| <EuiFlexGroup justifyContent="spaceBetween"> | ||
| <EuiFlexItem grow={false}> | ||
| <EuiButtonEmpty iconType="cross" onClick={closeFlyout} flush="left"> | ||
| {i18n.translate('xpack.ml.dataframe.analyticsList.editFlyoutCancelButtonText', { | ||
| defaultMessage: 'Cancel', | ||
| })} | ||
| </EuiButtonEmpty> | ||
| </EuiFlexItem> | ||
| <EuiFlexItem grow={false}> | ||
| <EuiButton | ||
| data-test-subj="analyticsEditFlyoutUpdateButton" | ||
| onClick={onSubmit} | ||
| fill | ||
| isDisabled={updateButtonDisabled} | ||
| > | ||
| {i18n.translate('xpack.ml.dataframe.analyticsList.editFlyoutUpdateButtonText', { | ||
| defaultMessage: 'Update', | ||
| })} | ||
| </EuiButton> | ||
| </EuiFlexItem> | ||
| </EuiFlexGroup> | ||
| </EuiFlyoutFooter> | ||
| </EuiFlyout> | ||
| </EuiOverlayMask> | ||
| ); | ||
| }; | ||
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.
Uh oh!
There was an error while loading. Please reload this page.