-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ML] Transforms/DFA: Refactor list action buttons so modals won't unm…
…ount after button click. (#70555) (#71050) Related to #70383 and #63455. Refactors the action buttons of the transform and data frame analytics jobs list: Previously custom actions included state and JSX for e.g. confirmation modals. Problem with that: If the actions list popover hides, the modal would unmount too. Since EUI's behaviour will change with the release/merge of #70383, we needed a refactor that solves that issue right now. With this PR, state management for UI behaviour that follows after a button click like the confirmation modals was moved to a custom hook which is part of the outer level of the buttons itself. The modal now also gets mounted on the outer level. This way we won't loose the modals state and DOM rendering when the action button hides. Note that this PR doesn't fix the nested buttons issue (#63455) yet. For that we need EUI issue #70383 to be in Kibana which will arrive with EUI v26.3.0 via #70243. So there will be one follow up to that which will focus on getting rid of the nested button structure. Co-authored-by: Elastic Machine <[email protected]>
- Loading branch information
1 parent
64f9176
commit d4a2c79
Showing
66 changed files
with
1,523 additions
and
1,108 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
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
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
12 changes: 12 additions & 0 deletions
12
...lication/data_frame_analytics/pages/analytics_management/components/action_clone/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,12 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export { | ||
extractCloningConfig, | ||
isAdvancedConfig, | ||
CloneButton, | ||
CloneDataFrameAnalyticsConfig, | ||
} from './clone_button'; |
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
64 changes: 64 additions & 0 deletions
64
...ata_frame_analytics/pages/analytics_management/components/action_delete/delete_button.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,64 @@ | ||
/* | ||
* 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 } from 'react'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { EuiIcon, EuiLink, EuiToolTip } from '@elastic/eui'; | ||
import { | ||
checkPermission, | ||
createPermissionFailureMessage, | ||
} from '../../../../../capabilities/check_capabilities'; | ||
import { isDataFrameAnalyticsRunning, DataFrameAnalyticsListRow } from '../analytics_list/common'; | ||
|
||
interface DeleteButtonProps { | ||
item: DataFrameAnalyticsListRow; | ||
onClick: (item: DataFrameAnalyticsListRow) => void; | ||
} | ||
|
||
export const DeleteButton: FC<DeleteButtonProps> = ({ item, onClick }) => { | ||
const disabled = isDataFrameAnalyticsRunning(item.stats.state); | ||
const canDeleteDataFrameAnalytics: boolean = checkPermission('canDeleteDataFrameAnalytics'); | ||
|
||
const buttonDeleteText = i18n.translate('xpack.ml.dataframe.analyticsList.deleteActionName', { | ||
defaultMessage: 'Delete', | ||
}); | ||
|
||
const buttonDisabled = disabled || !canDeleteDataFrameAnalytics; | ||
let deleteButton = ( | ||
<EuiLink | ||
data-test-subj="mlAnalyticsJobDeleteButton" | ||
color={buttonDisabled ? 'subdued' : 'text'} | ||
disabled={buttonDisabled} | ||
onClick={buttonDisabled ? undefined : () => onClick(item)} | ||
aria-label={buttonDeleteText} | ||
style={{ padding: 0 }} | ||
> | ||
<EuiIcon type="trash" /> {buttonDeleteText} | ||
</EuiLink> | ||
); | ||
|
||
if (disabled || !canDeleteDataFrameAnalytics) { | ||
deleteButton = ( | ||
<EuiToolTip | ||
position="top" | ||
content={ | ||
disabled | ||
? i18n.translate( | ||
'xpack.ml.dataframe.analyticsList.deleteActionDisabledToolTipContent', | ||
{ | ||
defaultMessage: 'Stop the data frame analytics job in order to delete it.', | ||
} | ||
) | ||
: createPermissionFailureMessage('canStartStopDataFrameAnalytics') | ||
} | ||
> | ||
{deleteButton} | ||
</EuiToolTip> | ||
); | ||
} | ||
|
||
return deleteButton; | ||
}; |
108 changes: 108 additions & 0 deletions
108
...ame_analytics/pages/analytics_management/components/action_delete/delete_button_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,108 @@ | ||
/* | ||
* 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 } from 'react'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { | ||
EuiConfirmModal, | ||
EuiOverlayMask, | ||
EuiSwitch, | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EUI_MODAL_CONFIRM_BUTTON, | ||
} from '@elastic/eui'; | ||
import { FormattedMessage } from '@kbn/i18n/react'; | ||
|
||
import { DeleteAction } from './use_delete_action'; | ||
|
||
export const DeleteButtonModal: FC<DeleteAction> = ({ | ||
closeModal, | ||
deleteAndCloseModal, | ||
deleteTargetIndex, | ||
deleteIndexPattern, | ||
indexPatternExists, | ||
item, | ||
toggleDeleteIndex, | ||
toggleDeleteIndexPattern, | ||
userCanDeleteIndex, | ||
}) => { | ||
if (item === undefined) { | ||
return null; | ||
} | ||
|
||
const indexName = item.config.dest.index; | ||
|
||
return ( | ||
<EuiOverlayMask data-test-subj="mlAnalyticsJobDeleteOverlay"> | ||
<EuiConfirmModal | ||
data-test-subj="mlAnalyticsJobDeleteModal" | ||
title={i18n.translate('xpack.ml.dataframe.analyticsList.deleteModalTitle', { | ||
defaultMessage: 'Delete {analyticsId}', | ||
values: { analyticsId: item.config.id }, | ||
})} | ||
onCancel={closeModal} | ||
onConfirm={deleteAndCloseModal} | ||
cancelButtonText={i18n.translate( | ||
'xpack.ml.dataframe.analyticsList.deleteModalCancelButton', | ||
{ | ||
defaultMessage: 'Cancel', | ||
} | ||
)} | ||
confirmButtonText={i18n.translate( | ||
'xpack.ml.dataframe.analyticsList.deleteModalDeleteButton', | ||
{ | ||
defaultMessage: 'Delete', | ||
} | ||
)} | ||
defaultFocusedButton={EUI_MODAL_CONFIRM_BUTTON} | ||
buttonColor="danger" | ||
> | ||
<p> | ||
<FormattedMessage | ||
id="xpack.ml.dataframe.analyticsList.deleteModalBody" | ||
defaultMessage="Are you sure you want to delete this analytics job?" | ||
/> | ||
</p> | ||
|
||
<EuiFlexGroup direction="column" gutterSize="none"> | ||
<EuiFlexItem> | ||
{userCanDeleteIndex && ( | ||
<EuiSwitch | ||
data-test-subj="mlAnalyticsJobDeleteIndexSwitch" | ||
style={{ paddingBottom: 10 }} | ||
label={i18n.translate( | ||
'xpack.ml.dataframe.analyticsList.deleteDestinationIndexTitle', | ||
{ | ||
defaultMessage: 'Delete destination index {indexName}', | ||
values: { indexName }, | ||
} | ||
)} | ||
checked={deleteTargetIndex} | ||
onChange={toggleDeleteIndex} | ||
/> | ||
)} | ||
</EuiFlexItem> | ||
<EuiFlexItem> | ||
{userCanDeleteIndex && indexPatternExists && ( | ||
<EuiSwitch | ||
data-test-subj="mlAnalyticsJobDeleteIndexPatternSwitch" | ||
label={i18n.translate( | ||
'xpack.ml.dataframe.analyticsList.deleteTargetIndexPatternTitle', | ||
{ | ||
defaultMessage: 'Delete index pattern {indexPattern}', | ||
values: { indexPattern: indexName }, | ||
} | ||
)} | ||
checked={deleteIndexPattern} | ||
onChange={toggleDeleteIndexPattern} | ||
/> | ||
)} | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</EuiConfirmModal> | ||
</EuiOverlayMask> | ||
); | ||
}; |
9 changes: 9 additions & 0 deletions
9
...ication/data_frame_analytics/pages/analytics_management/components/action_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,9 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export { DeleteButton } from './delete_button'; | ||
export { DeleteButtonModal } from './delete_button_modal'; | ||
export { useDeleteAction } from './use_delete_action'; |
Oops, something went wrong.