-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Dashboard] [Controls] Use uiActions for control hover actions
#153065
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
Heenawter
merged 18 commits into
elastic:main
from
Heenawter:use-actions-framework_2023-03-06
Mar 21, 2023
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
9dca4c7
Use EUI variables for hover animation
Heenawter 792c651
Use `uiActions` for editing and deleting
Heenawter dbc6844
Remove assumption that root is a dashboard
Heenawter 2d46f6e
Make rendering of floating actions generic
Heenawter 2e6ce98
Move action fetch logic to floating actions
Heenawter 6d3eb2c
Sort floating actions
Heenawter cc034d4
Clean up + minor fixes
Heenawter 9b79a2a
Add disabled actions logic + example
Heenawter f0f2867
Control hover visibility via disabled actions
Heenawter b66146c
Fix bundle size + Jest unit tests + flyouts not closing bug
Heenawter c95732a
Fix selection clearing bug + reset other parts of options list inputs
Heenawter d70ebc0
Add Jest unit tests
Heenawter d40fa62
Change how floating actions responds to changes + clean up
Heenawter 0c5f280
Add scroll lock to edit control flyout
Heenawter dfd67ac
Merge branch 'main' into use-actions-framework_2023-03-06
Heenawter e232839
Merge branch 'main' into use-actions-framework_2023-03-06
Heenawter 505924e
Address first round of comments
Heenawter d442648
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine 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
87 changes: 87 additions & 0 deletions
87
src/plugins/controls/public/control_group/actions/delete_control_action.test.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,87 @@ | ||
| /* | ||
| * 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 and the Server Side Public License, v 1; you may not use this file except | ||
| * in compliance with, at your election, the Elastic License 2.0 or the Server | ||
| * Side Public License, v 1. | ||
| */ | ||
|
|
||
| import { | ||
| lazyLoadReduxEmbeddablePackage, | ||
| ReduxEmbeddablePackage, | ||
| } from '@kbn/presentation-util-plugin/public'; | ||
| import { ErrorEmbeddable } from '@kbn/embeddable-plugin/public'; | ||
|
|
||
| import { ControlOutput } from '../../types'; | ||
| import { ControlGroupInput } from '../types'; | ||
| import { pluginServices } from '../../services'; | ||
| import { DeleteControlAction } from './delete_control_action'; | ||
| import { OptionsListEmbeddableInput } from '../../options_list'; | ||
| import { controlGroupInputBuilder } from '../control_group_input_builder'; | ||
| import { ControlGroupContainer } from '../embeddable/control_group_container'; | ||
| import { OptionsListEmbeddable } from '../../options_list/embeddable/options_list_embeddable'; | ||
|
|
||
| let container: ControlGroupContainer; | ||
| let embeddable: OptionsListEmbeddable; | ||
| let reduxEmbeddablePackage: ReduxEmbeddablePackage; | ||
|
|
||
| beforeAll(async () => { | ||
| reduxEmbeddablePackage = await lazyLoadReduxEmbeddablePackage(); | ||
|
|
||
| const controlGroupInput = { chainingSystem: 'NONE', panels: {} } as ControlGroupInput; | ||
| controlGroupInputBuilder.addOptionsListControl(controlGroupInput, { | ||
| dataViewId: 'test-data-view', | ||
| title: 'test', | ||
| fieldName: 'test-field', | ||
| width: 'medium', | ||
| grow: false, | ||
| }); | ||
| container = new ControlGroupContainer(reduxEmbeddablePackage, controlGroupInput); | ||
| await container.untilInitialized(); | ||
|
|
||
| embeddable = container.getChild(container.getChildIds()[0]); | ||
| }); | ||
|
|
||
| test('Action is incompatible with Error Embeddables', async () => { | ||
| const deleteControlAction = new DeleteControlAction(); | ||
| const errorEmbeddable = new ErrorEmbeddable('Wow what an awful error', { id: ' 404' }); | ||
| expect(await deleteControlAction.isCompatible({ embeddable: errorEmbeddable as any })).toBe( | ||
| false | ||
| ); | ||
| }); | ||
|
|
||
| test('Execute throws an error when called with an embeddable not in a parent', async () => { | ||
| const deleteControlAction = new DeleteControlAction(); | ||
| const optionsListEmbeddable = new OptionsListEmbeddable( | ||
| reduxEmbeddablePackage, | ||
| {} as OptionsListEmbeddableInput, | ||
| {} as ControlOutput | ||
| ); | ||
| await expect(async () => { | ||
| await deleteControlAction.execute({ embeddable: optionsListEmbeddable }); | ||
| }).rejects.toThrow(Error); | ||
| }); | ||
|
|
||
| describe('Execute should open a confirm modal', () => { | ||
| test('Canceling modal will keep control', async () => { | ||
| const spyOn = jest.fn().mockResolvedValue(false); | ||
| pluginServices.getServices().overlays.openConfirm = spyOn; | ||
|
|
||
| const deleteControlAction = new DeleteControlAction(); | ||
| await deleteControlAction.execute({ embeddable }); | ||
| expect(spyOn).toHaveBeenCalled(); | ||
|
|
||
| expect(container.getPanelCount()).toBe(1); | ||
| }); | ||
|
|
||
| test('Confirming modal will delete control', async () => { | ||
| const spyOn = jest.fn().mockResolvedValue(true); | ||
| pluginServices.getServices().overlays.openConfirm = spyOn; | ||
|
|
||
| const deleteControlAction = new DeleteControlAction(); | ||
| await deleteControlAction.execute({ embeddable }); | ||
| expect(spyOn).toHaveBeenCalled(); | ||
|
|
||
| expect(container.getPanelCount()).toBe(0); | ||
Heenawter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
| }); | ||
91 changes: 91 additions & 0 deletions
91
src/plugins/controls/public/control_group/actions/delete_control_action.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,91 @@ | ||
| /* | ||
| * 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 and the Server Side Public License, v 1; you may not use this file except | ||
| * in compliance with, at your election, the Elastic License 2.0 or the Server | ||
| * Side Public License, v 1. | ||
| */ | ||
|
|
||
| import React from 'react'; | ||
|
|
||
| import { EuiButtonIcon, EuiToolTip } from '@elastic/eui'; | ||
| import { ViewMode, isErrorEmbeddable } from '@kbn/embeddable-plugin/public'; | ||
| import { Action, IncompatibleActionError } from '@kbn/ui-actions-plugin/public'; | ||
|
|
||
| import { ACTION_DELETE_CONTROL } from '.'; | ||
| import { pluginServices } from '../../services'; | ||
| import { ControlGroupStrings } from '../control_group_strings'; | ||
| import { ControlEmbeddable, DataControlInput } from '../../types'; | ||
| import { isControlGroup } from '../embeddable/control_group_helpers'; | ||
|
|
||
| export interface DeleteControlActionContext { | ||
| embeddable: ControlEmbeddable<DataControlInput>; | ||
| } | ||
|
|
||
| export class DeleteControlAction implements Action<DeleteControlActionContext> { | ||
| public readonly type = ACTION_DELETE_CONTROL; | ||
| public readonly id = ACTION_DELETE_CONTROL; | ||
| public order = 2; | ||
|
|
||
| private openConfirm; | ||
|
|
||
| constructor() { | ||
| ({ | ||
| overlays: { openConfirm: this.openConfirm }, | ||
| } = pluginServices.getServices()); | ||
| } | ||
|
|
||
| public readonly MenuItem = ({ context }: { context: DeleteControlActionContext }) => { | ||
| return ( | ||
| <EuiToolTip content={this.getDisplayName(context)}> | ||
| <EuiButtonIcon | ||
| data-test-subj={`control-action-${context.embeddable.id}-delete`} | ||
| aria-label={this.getDisplayName(context)} | ||
| iconType={this.getIconType(context)} | ||
| onClick={() => this.execute(context)} | ||
| color="danger" | ||
| /> | ||
| </EuiToolTip> | ||
| ); | ||
| }; | ||
|
|
||
| public getDisplayName({ embeddable }: DeleteControlActionContext) { | ||
| if (!embeddable.parent || !isControlGroup(embeddable.parent)) { | ||
| throw new IncompatibleActionError(); | ||
| } | ||
| return ControlGroupStrings.floatingActions.getRemoveButtonTitle(); | ||
| } | ||
|
|
||
| public getIconType({ embeddable }: DeleteControlActionContext) { | ||
| if (!embeddable.parent || !isControlGroup(embeddable.parent)) { | ||
| throw new IncompatibleActionError(); | ||
| } | ||
| return 'cross'; | ||
| } | ||
|
|
||
| public async isCompatible({ embeddable }: DeleteControlActionContext) { | ||
| if (isErrorEmbeddable(embeddable)) return false; | ||
| const controlGroup = embeddable.parent; | ||
| return Boolean( | ||
| controlGroup && | ||
| isControlGroup(controlGroup) && | ||
| controlGroup.getInput().viewMode === ViewMode.EDIT | ||
| ); | ||
| } | ||
|
|
||
| public async execute({ embeddable }: DeleteControlActionContext) { | ||
| if (!embeddable.parent || !isControlGroup(embeddable.parent)) { | ||
| throw new IncompatibleActionError(); | ||
| } | ||
| this.openConfirm(ControlGroupStrings.management.deleteControls.getSubtitle(), { | ||
| confirmButtonText: ControlGroupStrings.management.deleteControls.getConfirm(), | ||
| cancelButtonText: ControlGroupStrings.management.deleteControls.getCancel(), | ||
| title: ControlGroupStrings.management.deleteControls.getDeleteTitle(), | ||
| buttonColor: 'danger', | ||
| }).then((confirmed) => { | ||
| if (confirmed) { | ||
| embeddable.parent?.removeEmbeddable(embeddable.id); | ||
| } | ||
| }); | ||
| } | ||
| } |
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.
Would it be quicker to use a mocked version of this? I am not entirely sure if one exists yet, but if not I will be adding it in #150121
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.
It probably would be, yeah! We don't seem to have the mock yet, though - if you plan to add one, that would be awesome!