-
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.
[Controls] Move "clear selections" to hover action (#159526)
Closes #159395 Closes #153383 ## Summary This PR moves the "clear selections" button for all controls (options list, range slider, and time slider) from inside their respective popovers to a general hover action - this not only saves users a click for this common interaction (which has actually been brought in user feedback up as a downside of the current controls compared to the legacy controls), it also allows us to fully move forward with migrating the range slider control to the `EuiDualRange` component. This will be done in a follow up PR, which should both (1) clean up our range slider code significantly and (2) fix the [bug discussed here](#159271 (review)). The related issue can be tracked [here](#159724), since we might not be able to get to it right away. This "clear selections" action is available in both view and edit mode, like so: | | Edit mode | View mode | |--------|--------|--------| | **Range slider** | ![image](https://github.com/elastic/kibana/assets/8698078/83cb1e1a-0b20-43aa-a37b-14484b5f4945) | ![image](https://github.com/elastic/kibana/assets/8698078/0d28ce03-5242-4f3a-8a05-d447bca50ddb) | | **Options list** | ![image](https://github.com/elastic/kibana/assets/8698078/066257f6-c0ce-4e33-a193-5bbc62e341a6) | ![image](https://github.com/elastic/kibana/assets/8698078/d1ec124c-f5ee-4137-9eb9-33e06d522435) | | **Time slider** | ![image](https://github.com/elastic/kibana/assets/8698078/33b8bb80-fa0c-4281-ae81-f1e1b44086f3) | ![image](https://github.com/elastic/kibana/assets/8698078/bd7c41ae-706c-45f3-8b49-9bd4d259e5cf) | You may notice in the above screenshots that the "delete" action is now represented with a red trash icon rather than a red cross, and the tooltip text was also changed to use the word "Delete" rather than the word "Remove" - these changes were both made to be more consistent with the "Delete panel" action available on dashboards: | Delete control - Before | Delete control - After | Delete panel | |--------|--------|--------| | ![Screenshot 2023-06-13 at 5 32 22 PM](https://github.com/elastic/kibana/assets/8698078/2600b197-653b-43ea-a043-a50be7e6a796) | ![image](https://github.com/elastic/kibana/assets/8698078/5ef80380-2575-45fc-ba11-c59f3f252ac3) | <img src="https://github.com/elastic/kibana/assets/8698078/a7f65777-45cf-44f2-96a7-f1042cb25e02"/> | Beyond these changes, I also made a few quick changes to the time slider control, including: 1. Fixing the appearance so that the background is once again white, as described [here](#159526 (comment)) 2. Adding comparison logic so that clearing selections no longer causes unsaved changes unnecessarily, as described [here](#159526 (comment)) ### Videos **Before** https://github.com/elastic/kibana/assets/8698078/96365c85-748e-4fd7-ae5d-589aa11a23ef **After** https://github.com/elastic/kibana/assets/8698078/68352559-e71b-4b5e-8709-587016f0b35a ### Checklist - [x] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [x] Any UI touched in this PR is usable by keyboard only (learn more about [keyboard accessibility](https://webaim.org/techniques/keyboard/)) - [x] Any UI touched in this PR does not create any new axe failures (run axe in browser: [FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/), [Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US)) - [x] This renders correctly on smaller devices using a responsive layout. (You can test this [in your browser](https://www.browserstack.com/guide/responsive-testing-on-local-server)) - [x] This was checked for [cross-browser compatibility](https://www.elastic.co/support/matrix#matrix_browsers) ### For maintainers - [ ] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) --------- Co-authored-by: kibanamachine <[email protected]>
- Loading branch information
1 parent
69849ee
commit f1dc1e1
Showing
28 changed files
with
207 additions
and
148 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
78 changes: 78 additions & 0 deletions
78
src/plugins/controls/public/control_group/actions/clear_control_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,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(); | ||
} | ||
} |
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
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
Oops, something went wrong.