-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[Controls] [Dashboard] Use EuiSelectable for options list suggestions
#148420
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 17 commits into
elastic:main
from
Heenawter:refactor-options-list_2023-01-04
Jan 16, 2023
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
62e2727
Use `euiSelectable` for options list suggestions
Heenawter 86ab9f7
Add debounced loading state and fix loading bug
Heenawter 58539b9
Clean up code by splitting up simple components
Heenawter 9d624a6
Fix tests
Heenawter 1fba2dd
Adjust `getAvailableOptions` for virtualized selectable
Heenawter 19888a1
Fix styling of popover
Heenawter ae67a53
Initial attempt at flaky test fix
Heenawter 147a01b
Convert invalid selections + add screen reader support
Heenawter 41176d5
Second attempt at flaky test fix
Heenawter 05d38ba
Separate options lists tests into multiple files
Heenawter 53722ce
Final flaky test fix
Heenawter 6383bbe
Clean up
Heenawter 514cec9
Fix cleanup and teardown of `options_list/config`
Heenawter 46b8bd7
Clean up unnecessary `useMemo`s
Heenawter 197a66b
Merge branch 'main' into refactor-options-list_2023-01-04
Heenawter fd9ce5d
Merge branch 'main' into refactor-options-list_2023-01-04
Heenawter a85c941
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
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
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
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
35 changes: 35 additions & 0 deletions
35
src/plugins/controls/public/options_list/components/options_list_popover_empty_message.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,35 @@ | ||
| /* | ||
| * 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 { EuiIcon, EuiSpacer } from '@elastic/eui'; | ||
|
|
||
| import { OptionsListStrings } from './options_list_strings'; | ||
|
|
||
| export const OptionsListPopoverEmptyMessage = ({ | ||
| showOnlySelected, | ||
| }: { | ||
| showOnlySelected: boolean; | ||
| }) => { | ||
| return ( | ||
| <span | ||
| className="euiFilterSelect__note" | ||
| data-test-subj={`optionsList-control-${ | ||
| showOnlySelected ? 'selectionsEmptyMessage' : 'noSelectionsMessage' | ||
| }`} | ||
| > | ||
| <span className="euiFilterSelect__noteContent"> | ||
| <EuiIcon type="minusInCircle" /> | ||
| <EuiSpacer size="xs" /> | ||
| {showOnlySelected | ||
| ? OptionsListStrings.popover.getSelectionsEmptyMessage() | ||
| : OptionsListStrings.popover.getEmptyMessage()} | ||
| </span> | ||
| </span> | ||
| ); | ||
| }; |
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 |
|---|---|---|
|
|
@@ -6,9 +6,15 @@ | |
| * Side Public License, v 1. | ||
| */ | ||
|
|
||
| import React from 'react'; | ||
| import React, { useEffect, useState } from 'react'; | ||
|
|
||
| import { EuiFilterSelectItem, EuiSpacer, EuiTitle } from '@elastic/eui'; | ||
| import { | ||
| EuiSelectableOption, | ||
| EuiSelectable, | ||
| EuiSpacer, | ||
| EuiTitle, | ||
| EuiScreenReaderOnly, | ||
| } from '@elastic/eui'; | ||
| import { useReduxEmbeddableContext } from '@kbn/presentation-util-plugin/public'; | ||
|
|
||
| import { OptionsListReduxState } from '../types'; | ||
|
|
@@ -26,6 +32,31 @@ export const OptionsListPopoverInvalidSelections = () => { | |
|
|
||
| // Select current state from Redux using multiple selectors to avoid rerenders. | ||
| const invalidSelections = select((state) => state.componentState.invalidSelections); | ||
| const fieldName = select((state) => state.explicitInput.fieldName); | ||
|
|
||
| const [selectableOptions, setSelectableOptions] = useState<EuiSelectableOption[]>([]); // will be set in following useEffect | ||
| useEffect(() => { | ||
| /* This useEffect makes selectableOptions responsive to unchecking options */ | ||
| const options: EuiSelectableOption[] = (invalidSelections ?? []).map((key) => { | ||
| return { | ||
| key, | ||
| label: key, | ||
| checked: 'on', | ||
| className: 'optionsList__selectionInvalid', | ||
| 'data-test-subj': `optionsList-control-ignored-selection-${key}`, | ||
| prepend: ( | ||
| <EuiScreenReaderOnly> | ||
| <div> | ||
| {OptionsListStrings.popover.getInvalidSelectionScreenReaderText()} | ||
| {'" "'} {/* Adds a pause for the screen reader */} | ||
| </div> | ||
| </EuiScreenReaderOnly> | ||
| ), | ||
| }; | ||
| }); | ||
| setSelectableOptions(options); | ||
| }, [invalidSelections]); | ||
|
|
||
| return ( | ||
| <> | ||
| <EuiSpacer size="s" /> | ||
|
|
@@ -40,18 +71,20 @@ export const OptionsListPopoverInvalidSelections = () => { | |
| )} | ||
| </label> | ||
| </EuiTitle> | ||
| {invalidSelections?.map((ignoredSelection, index) => ( | ||
| <EuiFilterSelectItem | ||
| data-test-subj={`optionsList-control-ignored-selection-${ignoredSelection}`} | ||
| checked={'on'} | ||
| className="optionsList__selectionInvalid" | ||
| key={index} | ||
| onClick={() => dispatch(deselectOption(ignoredSelection))} | ||
| aria-label={OptionsListStrings.popover.getInvalidSelectionAriaLabel(ignoredSelection)} | ||
| > | ||
| {`${ignoredSelection}`} | ||
| </EuiFilterSelectItem> | ||
| ))} | ||
| <EuiSelectable | ||
| aria-label={OptionsListStrings.popover.getInvalidSelectionsSectionAriaLabel( | ||
| fieldName, | ||
| invalidSelections?.length ?? 0 | ||
| )} | ||
| options={selectableOptions} | ||
| listProps={{ onFocusBadge: false, isVirtualized: false }} | ||
|
Contributor
Author
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. |
||
| onChange={(newSuggestions, _, changedOption) => { | ||
| setSelectableOptions(newSuggestions); | ||
| dispatch(deselectOption(changedOption.label)); | ||
| }} | ||
| > | ||
| {(list) => list} | ||
| </EuiSelectable> | ||
| </> | ||
| ); | ||
| }; | ||
46 changes: 46 additions & 0 deletions
46
...plugins/controls/public/options_list/components/options_list_popover_suggestion_badge.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,46 @@ | ||
| /* | ||
| * 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 { css } from '@emotion/react'; | ||
| import { EuiScreenReaderOnly, EuiText, EuiToolTip, useEuiTheme } from '@elastic/eui'; | ||
|
|
||
| import { OptionsListStrings } from './options_list_strings'; | ||
|
|
||
| export const OptionsListPopoverSuggestionBadge = ({ documentCount }: { documentCount: number }) => { | ||
| const { euiTheme } = useEuiTheme(); | ||
|
|
||
| return ( | ||
| <> | ||
| <EuiToolTip | ||
| content={OptionsListStrings.popover.getDocumentCountTooltip(documentCount)} | ||
| position={'right'} | ||
| > | ||
| <EuiText | ||
| size="xs" | ||
| aria-hidden={true} | ||
| className="eui-textNumber" | ||
| color={euiTheme.colors.subduedText} | ||
| data-test-subj="optionsList-document-count-badge" | ||
| css={css` | ||
| font-weight: ${euiTheme.font.weight.medium} !important; | ||
| `} | ||
| > | ||
| {`${documentCount.toLocaleString()}`} | ||
| </EuiText> | ||
| </EuiToolTip> | ||
| <EuiScreenReaderOnly> | ||
| <div> | ||
| {'" "'} {/* Adds a pause for the screen reader */} | ||
| {OptionsListStrings.popover.getDocumentCountScreenReaderText(documentCount)} | ||
| </div> | ||
| </EuiScreenReaderOnly> | ||
| </> | ||
| ); | ||
| }; |
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.
Nice, aria labels should definitely be i18nized!