-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[ML] Adds ability to toggle visibility for empty fields when choosing an aggregation or field in Anomaly detection, data frame analytics #186670
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
Merged
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
3ec0455
Refactor to OptionList
qn895 4b7dd54
Refactor to OptionListWithStats
qn895 fcb84ba
Add styling for removal
qn895 0f6224a
Add for other rest of AD
qn895 cc0de0e
Update for geo field
qn895 57377aa
Update styling for DFA
qn895 e321f9d
Update types and styling
qn895 29658f7
Update width
qn895 585b2e3
Revert AIOps change
qn895 70399ee
Remove commented code
qn895 f9fd80f
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine 0915532
Update translations
qn895 711409f
Update component
qn895 a2efa16
FIx types
qn895 72bb627
Update layout
qn895 1e16d85
Use formcontrolledlayout instead
qn895 5a8269d
Update types
qn895 0636979
Merge branch 'ml-fields-empty-state-controls' into replace-combo-box
qn895 eecd220
Fix in advanced settings
qn895 2534c00
Update tests
qn895 2f75637
Update tests for AD
qn895 ddd93dd
Update for DFA
qn895 8d260a4
Update DFA tests
qn895 b32e595
Fix accessability test
qn895 0d5c2be
Merge remote-tracking branch 'upstream/main' into replace-combo-box
qn895 5e8355e
Update tests
qn895 139627c
Fix button showing more than needed
qn895 570880c
Merge remote-tracking branch 'upstream/main' into replace-combo-box
qn895 84fd32d
Fix undefined
qn895 17d1253
Fix type
qn895 5cebeb9
Merge remote-tracking branch 'upstream/main' into replace-combo-box
qn895 c7371cc
Fix timestamp or fields without aggs showing up
qn895 4c0c3ae
Update types, style, remove extra icons
qn895 ba1bd8c
Merge remote-tracking branch 'upstream/main' into replace-combo-box
qn895 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
67 changes: 0 additions & 67 deletions
67
x-pack/packages/ml/field_stats_flyout/eui_combo_box_with_field_stats.tsx
This file was deleted.
Oops, something went wrong.
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
158 changes: 158 additions & 0 deletions
158
x-pack/packages/ml/field_stats_flyout/options_list_with_stats/option_list_popover.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,158 @@ | ||
| /* | ||
| * 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; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
| import type { FC } from 'react'; | ||
| import React, { useMemo, useState, useEffect } from 'react'; | ||
| import { isDefined } from '@kbn/ml-is-defined'; | ||
| import type { | ||
| EuiComboBoxOptionOption, | ||
| EuiComboBoxSingleSelectionShape, | ||
| EuiSelectableOption, | ||
| } from '@elastic/eui'; | ||
| import { EuiFlexItem, EuiSelectable, htmlIdGenerator } from '@elastic/eui'; | ||
| import { css } from '@emotion/react'; | ||
| import { type DropDownLabel } from './types'; | ||
| import { useFieldStatsFlyoutContext } from '../use_field_stats_flyout_context'; | ||
| import { OptionsListPopoverFooter } from './option_list_popover_footer'; | ||
|
|
||
| interface OptionsListPopoverProps { | ||
| options: DropDownLabel[]; | ||
| renderOption: (option: DropDownLabel) => React.ReactNode; | ||
| singleSelection?: boolean | EuiComboBoxSingleSelectionShape; | ||
| onChange?: | ||
| | ((newSuggestions: DropDownLabel[]) => void) | ||
| | (( | ||
| newSuggestions: Array<EuiComboBoxOptionOption<string | number | string[] | undefined>> | ||
| ) => void); | ||
| setPopoverOpen: (open: boolean) => void; | ||
| isLoading?: boolean; | ||
| } | ||
|
|
||
| interface OptionsListPopoverSuggestionsProps { | ||
| options: DropDownLabel[]; | ||
| renderOption: (option: DropDownLabel) => React.ReactNode; | ||
| singleSelection?: boolean | EuiComboBoxSingleSelectionShape; | ||
| onChange?: | ||
| | ((newSuggestions: DropDownLabel[]) => void) | ||
| | (( | ||
| newSuggestions: Array<EuiComboBoxOptionOption<string | number | string[] | undefined>> | ||
| ) => void); | ||
| setPopoverOpen: (open: boolean) => void; | ||
| } | ||
| const OptionsListPopoverSuggestions: FC<OptionsListPopoverSuggestionsProps> = ({ | ||
| options, | ||
| renderOption, | ||
| singleSelection, | ||
| onChange, | ||
| setPopoverOpen, | ||
| }) => { | ||
| const [selectableOptions, setSelectableOptions] = useState<DropDownLabel[]>([]); // will be set in following useEffect | ||
| useEffect(() => { | ||
| /* This useEffect makes selectableOptions responsive to search, show only selected, and clear selections */ | ||
| const _selectableOptions = (options ?? []).map((suggestion) => { | ||
| const key = suggestion.label ?? suggestion.field?.id; | ||
| return { | ||
| ...suggestion, | ||
| key, | ||
| checked: undefined, | ||
| 'data-test-subj': `optionsListControlSelection-${key}`, | ||
| }; | ||
| }); | ||
| setSelectableOptions(_selectableOptions); | ||
| }, [options]); | ||
|
|
||
| return ( | ||
| <EuiSelectable | ||
| searchProps={{ 'data-test-subj': 'optionsListFilterInput' }} | ||
| singleSelection={Boolean(singleSelection)} | ||
| searchable | ||
| options={selectableOptions as Array<EuiSelectableOption<string>>} | ||
| renderOption={renderOption} | ||
| listProps={{ onFocusBadge: false }} | ||
| onChange={(opts, _, changedOption) => { | ||
| const option = changedOption as DropDownLabel; | ||
| if (singleSelection) { | ||
| if (onChange) { | ||
| onChange([option as EuiComboBoxOptionOption<string | number | string[] | undefined>]); | ||
| setPopoverOpen(false); | ||
| } | ||
| } else { | ||
| if (onChange) { | ||
| onChange([option as EuiComboBoxOptionOption<string | number | string[] | undefined>]); | ||
| setPopoverOpen(false); | ||
| } | ||
| } | ||
| }} | ||
| > | ||
| {(list, search) => ( | ||
| <> | ||
| {search} | ||
| {list} | ||
| </> | ||
| )} | ||
| </EuiSelectable> | ||
| ); | ||
| }; | ||
|
|
||
| export const OptionsListPopover = ({ | ||
| options, | ||
| renderOption, | ||
| singleSelection, | ||
| onChange, | ||
| setPopoverOpen, | ||
| isLoading, | ||
| }: OptionsListPopoverProps) => { | ||
| const { populatedFields } = useFieldStatsFlyoutContext(); | ||
|
|
||
| const [showEmptyFields, setShowEmptyFields] = useState(false); | ||
| const id = useMemo(() => htmlIdGenerator()(), []); | ||
|
|
||
| const filteredOptions = useMemo(() => { | ||
| return showEmptyFields | ||
| ? options | ||
| : options.filter((option) => { | ||
| if (isDefined(option['data-is-empty'])) { | ||
| return !option['data-is-empty']; | ||
| } | ||
| if ( | ||
| Object.hasOwn(option, 'isGroupLabel') || | ||
| Object.hasOwn(option, 'isGroupLabelOption') | ||
| ) { | ||
| const key = option.key ?? option.searchableLabel; | ||
| return key ? populatedFields?.has(key) : false; | ||
| } | ||
| if (option.field) { | ||
| return populatedFields?.has(option.field.id); | ||
| } | ||
| return true; | ||
| }); | ||
| }, [options, showEmptyFields, populatedFields]); | ||
| return ( | ||
| <div | ||
| id={`control-popover-${id}`} | ||
| className={'optionsList__popover'} | ||
| data-test-subj={`optionsListControlPopover`} | ||
| > | ||
| <EuiFlexItem | ||
| data-test-subj={`optionsListControlAvailableOptions`} | ||
| css={css({ width: '100%', height: '100%' })} | ||
| > | ||
| <OptionsListPopoverSuggestions | ||
| renderOption={renderOption} | ||
| options={filteredOptions} | ||
| singleSelection={singleSelection} | ||
| onChange={onChange} | ||
| setPopoverOpen={setPopoverOpen} | ||
| /> | ||
| </EuiFlexItem> | ||
| <OptionsListPopoverFooter | ||
| showEmptyFields={showEmptyFields} | ||
| setShowEmptyFields={setShowEmptyFields} | ||
| isLoading={isLoading} | ||
| /> | ||
| </div> | ||
| ); | ||
| }; | ||
51 changes: 51 additions & 0 deletions
51
x-pack/packages/ml/field_stats_flyout/options_list_with_stats/option_list_popover_footer.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,51 @@ | ||
| /* | ||
| * 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; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
| import React from 'react'; | ||
| import type { FC } from 'react'; | ||
| import { EuiPopoverFooter, EuiSwitch, EuiProgress, useEuiBackgroundColor } from '@elastic/eui'; | ||
| import { css } from '@emotion/react'; | ||
| import { i18n } from '@kbn/i18n'; | ||
| import { euiThemeVars } from '@kbn/ui-theme'; | ||
|
|
||
| export const OptionsListPopoverFooter: FC<{ | ||
| showEmptyFields: boolean; | ||
| setShowEmptyFields: (showEmptyFields: boolean) => void; | ||
| isLoading?: boolean; | ||
| }> = ({ showEmptyFields, setShowEmptyFields, isLoading }) => { | ||
| return ( | ||
| <EuiPopoverFooter | ||
| paddingSize="none" | ||
| css={css({ | ||
| height: euiThemeVars.euiButtonHeight, | ||
| backgroundColor: useEuiBackgroundColor('subdued'), | ||
| alignItems: 'center', | ||
| display: 'flex', | ||
| paddingLeft: euiThemeVars.euiSizeS, | ||
| })} | ||
| > | ||
| {isLoading ? ( | ||
| // @ts-expect-error css should be ok | ||
| <div css={css({ position: 'absolute', width: '100%' })}> | ||
| <EuiProgress | ||
| data-test-subj="optionsList-control-popover-loading" | ||
| size="xs" | ||
| color="accent" | ||
| /> | ||
| </div> | ||
| ) : null} | ||
|
|
||
| <EuiSwitch | ||
| data-test-subj="optionsListIncludeEmptyFields" | ||
| label={i18n.translate('xpack.ml.controls.optionsList.popover.includeEmptyFieldsLabel', { | ||
| defaultMessage: 'Include empty fields', | ||
| })} | ||
| checked={showEmptyFields} | ||
| onChange={(e) => setShowEmptyFields(e.target.checked)} | ||
| /> | ||
| </EuiPopoverFooter> | ||
| ); | ||
| }; |
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.
The vertical spacing in these dropdowns as always been a bit off, but with this PR they fields now have different kind of uneven spacing where the field looks like it needs some padding above it or maybe moved closer to the detector function below.

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.
Updated here
4c0c3ae(#186670)