-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[Controls] Move "clear selections" to hover action #159526
Changes from all commits
32d71dd
57de656
0a2e174
ebe9c69
626fb87
c29530a
82efb91
72f7638
7910151
3893cf5
b3ccbc8
eed68ee
31e64af
fc117ae
b97efa9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* 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, { SyntheticEvent } from 'react'; | ||
|
||
import { EuiButtonIcon, EuiToolTip } from '@elastic/eui'; | ||
import { isErrorEmbeddable } from '@kbn/embeddable-plugin/public'; | ||
import { Action, IncompatibleActionError } from '@kbn/ui-actions-plugin/public'; | ||
|
||
import { ACTION_CLEAR_CONTROL } from '.'; | ||
import { ControlGroupStrings } from '../control_group_strings'; | ||
import { ControlEmbeddable, DataControlInput, isClearableControl } from '../../types'; | ||
import { isControlGroup } from '../embeddable/control_group_helpers'; | ||
|
||
export interface ClearControlActionContext { | ||
embeddable: ControlEmbeddable<DataControlInput>; | ||
} | ||
|
||
export class ClearControlAction implements Action<ClearControlActionContext> { | ||
public readonly type = ACTION_CLEAR_CONTROL; | ||
public readonly id = ACTION_CLEAR_CONTROL; | ||
public order = 1; | ||
|
||
constructor() {} | ||
|
||
public readonly MenuItem = ({ context }: { context: ClearControlActionContext }) => { | ||
return ( | ||
<EuiToolTip content={this.getDisplayName(context)}> | ||
<EuiButtonIcon | ||
data-test-subj={`control-action-${context.embeddable.id}-erase`} | ||
aria-label={this.getDisplayName(context)} | ||
iconType={this.getIconType(context)} | ||
onClick={(event: SyntheticEvent<HTMLButtonElement>) => { | ||
(event.target as HTMLButtonElement).blur(); | ||
this.execute(context); | ||
}} | ||
color="text" | ||
/> | ||
</EuiToolTip> | ||
); | ||
}; | ||
|
||
public getDisplayName({ embeddable }: ClearControlActionContext) { | ||
if (!embeddable.parent || !isControlGroup(embeddable.parent)) { | ||
throw new IncompatibleActionError(); | ||
} | ||
return ControlGroupStrings.floatingActions.getClearButtonTitle(); | ||
} | ||
|
||
public getIconType({ embeddable }: ClearControlActionContext) { | ||
if (!embeddable.parent || !isControlGroup(embeddable.parent)) { | ||
throw new IncompatibleActionError(); | ||
} | ||
return 'eraser'; | ||
} | ||
|
||
public async isCompatible({ embeddable }: ClearControlActionContext) { | ||
if (isErrorEmbeddable(embeddable)) return false; | ||
const controlGroup = embeddable.parent; | ||
return Boolean(controlGroup && isControlGroup(controlGroup)) && isClearableControl(embeddable); | ||
} | ||
|
||
public async execute({ embeddable }: ClearControlActionContext) { | ||
if ( | ||
!embeddable.parent || | ||
!isControlGroup(embeddable.parent) || | ||
!isClearableControl(embeddable) | ||
) { | ||
throw new IncompatibleActionError(); | ||
} | ||
embeddable.clearSelections(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ export interface DeleteControlActionContext { | |
export class DeleteControlAction implements Action<DeleteControlActionContext> { | ||
public readonly type = ACTION_DELETE_CONTROL; | ||
public readonly id = ACTION_DELETE_CONTROL; | ||
public order = 2; | ||
public order = 100; // should always be last | ||
|
||
private openConfirm; | ||
|
||
|
@@ -60,7 +60,7 @@ export class DeleteControlAction implements Action<DeleteControlActionContext> { | |
if (!embeddable.parent || !isControlGroup(embeddable.parent)) { | ||
throw new IncompatibleActionError(); | ||
} | ||
return 'cross'; | ||
return 'trash'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
|
||
public async isCompatible({ embeddable }: DeleteControlActionContext) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,6 +82,7 @@ export const ControlGroup = () => { | |
}); | ||
} | ||
} | ||
(document.activeElement as HTMLElement)?.blur(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fixes this bug where the drag handler was retaining focus after it was dropped, which caused the floating actions to remain on the screen after moving a control until the user clicked somewhere to manually remove the focus: Before: Screen.Recording.2023-06-14.at.10.42.44.AM.movAfter: Screen.Recording.2023-06-14.at.10.41.58.AM.mov |
||
setDraggingId(null); | ||
}; | ||
|
||
|
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.
This fixes a bug where resetting the selections back to "undefined" / empty would cause unsaved changes:
Before:
Screen.Recording.2023-06-14.at.10.35.23.AM.mov
After:
Screen.Recording.2023-06-14.at.10.36.53.AM.mov