Skip to content

Commit

Permalink
[8.x] [ML] Add control to show or hide empty fields in dropdown in Tr…
Browse files Browse the repository at this point in the history
…ansform (#195485) (#196451)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[ML] Add control to show or hide empty fields in dropdown in
Transform (#195485)](#195485)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Quynh Nguyen
(Quinn)","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-15T22:04:04Z","message":"[ML]
Add control to show or hide empty fields in dropdown in Transform
(#195485)\n\n## Summary\r\nFollow up of
#186670. This PR adds\r\na new
control show or hide empty fields in dropdowns in Transform.\r\n\r\n####
Transform\r\n\r\nPivot transform
creation\r\n\r\n\r\nhttps://github.com/user-attachments/assets/35366671-c7a0-4ba1-ae24-ae3d965a2d69\r\n\r\nLatest
transform creation\r\n\r\n<img width=\"1473\"
alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/db53e7ed-17d5-44d7-93ab-1d0c5ca22f20\">\r\n\r\n\r\n\r\n\r\n\r\n###
Checklist\r\n\r\nDelete any items that are not applicable to this
PR.\r\n\r\n- [ ] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [ ] Any UI touched in this PR is
usable by keyboard only (learn more\r\nabout [keyboard
accessibility](https://webaim.org/techniques/keyboard/))\r\n- [ ] Any UI
touched in this PR does not create any new axe failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[ ] If a plugin configuration key changed, check if it needs to
be\r\nallowlisted in the cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[ ] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[ ] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n\r\n###
Risk Matrix\r\n\r\nDelete this section if it is not applicable to this
PR.\r\n\r\nBefore closing this PR, invite QA, stakeholders, and other
developers to\r\nidentify risks that should be tested prior to the
change/feature\r\nrelease.\r\n\r\nWhen forming the risk matrix, consider
some of the following examples\r\nand how they may potentially impact
the change:\r\n\r\n| Risk | Probability | Severity | Mitigation/Notes
|\r\n\r\n|---------------------------|-------------|----------|-------------------------|\r\n|
Multiple Spaces&mdash;unexpected behavior in non-default Kibana
Space.\r\n| Low | High | Integration tests will verify that all features
are still\r\nsupported in non-default Kibana Space and when user
switches between\r\nspaces. |\r\n| Multiple nodes&mdash;Elasticsearch
polling might have race conditions\r\nwhen multiple Kibana nodes are
polling for the same tasks. | High | Low\r\n| Tasks are idempotent, so
executing them multiple times will not result\r\nin logical error, but
will degrade performance. To test for this case we\r\nadd plenty of unit
tests around this logic and document manual testing\r\nprocedure. |\r\n|
Code should gracefully handle cases when feature X or plugin Y
are\r\ndisabled. | Medium | High | Unit tests will verify that any
feature flag\r\nor plugin combination still results in our service
operational. |\r\n| [See more potential
risk\r\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)
|\r\n\r\n\r\n### For maintainers\r\n\r\n- [ ] This was checked for
breaking API changes and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"d89f32a6aca0b522c606e5aec668cee5a3267d4a","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:enhancement",":ml","Feature:Transforms","v9.0.0","backport:prev-minor","v8.16.0"],"title":"[ML]
Add control to show or hide empty fields in dropdown in Transform
","number":195485,"url":"https://github.com/elastic/kibana/pull/195485","mergeCommit":{"message":"[ML]
Add control to show or hide empty fields in dropdown in Transform
(#195485)\n\n## Summary\r\nFollow up of
#186670. This PR adds\r\na new
control show or hide empty fields in dropdowns in Transform.\r\n\r\n####
Transform\r\n\r\nPivot transform
creation\r\n\r\n\r\nhttps://github.com/user-attachments/assets/35366671-c7a0-4ba1-ae24-ae3d965a2d69\r\n\r\nLatest
transform creation\r\n\r\n<img width=\"1473\"
alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/db53e7ed-17d5-44d7-93ab-1d0c5ca22f20\">\r\n\r\n\r\n\r\n\r\n\r\n###
Checklist\r\n\r\nDelete any items that are not applicable to this
PR.\r\n\r\n- [ ] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [ ] Any UI touched in this PR is
usable by keyboard only (learn more\r\nabout [keyboard
accessibility](https://webaim.org/techniques/keyboard/))\r\n- [ ] Any UI
touched in this PR does not create any new axe failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[ ] If a plugin configuration key changed, check if it needs to
be\r\nallowlisted in the cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[ ] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[ ] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n\r\n###
Risk Matrix\r\n\r\nDelete this section if it is not applicable to this
PR.\r\n\r\nBefore closing this PR, invite QA, stakeholders, and other
developers to\r\nidentify risks that should be tested prior to the
change/feature\r\nrelease.\r\n\r\nWhen forming the risk matrix, consider
some of the following examples\r\nand how they may potentially impact
the change:\r\n\r\n| Risk | Probability | Severity | Mitigation/Notes
|\r\n\r\n|---------------------------|-------------|----------|-------------------------|\r\n|
Multiple Spaces&mdash;unexpected behavior in non-default Kibana
Space.\r\n| Low | High | Integration tests will verify that all features
are still\r\nsupported in non-default Kibana Space and when user
switches between\r\nspaces. |\r\n| Multiple nodes&mdash;Elasticsearch
polling might have race conditions\r\nwhen multiple Kibana nodes are
polling for the same tasks. | High | Low\r\n| Tasks are idempotent, so
executing them multiple times will not result\r\nin logical error, but
will degrade performance. To test for this case we\r\nadd plenty of unit
tests around this logic and document manual testing\r\nprocedure. |\r\n|
Code should gracefully handle cases when feature X or plugin Y
are\r\ndisabled. | Medium | High | Unit tests will verify that any
feature flag\r\nor plugin combination still results in our service
operational. |\r\n| [See more potential
risk\r\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)
|\r\n\r\n\r\n### For maintainers\r\n\r\n- [ ] This was checked for
breaking API changes and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"d89f32a6aca0b522c606e5aec668cee5a3267d4a"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/195485","number":195485,"mergeCommit":{"message":"[ML]
Add control to show or hide empty fields in dropdown in Transform
(#195485)\n\n## Summary\r\nFollow up of
#186670. This PR adds\r\na new
control show or hide empty fields in dropdowns in Transform.\r\n\r\n####
Transform\r\n\r\nPivot transform
creation\r\n\r\n\r\nhttps://github.com/user-attachments/assets/35366671-c7a0-4ba1-ae24-ae3d965a2d69\r\n\r\nLatest
transform creation\r\n\r\n<img width=\"1473\"
alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/db53e7ed-17d5-44d7-93ab-1d0c5ca22f20\">\r\n\r\n\r\n\r\n\r\n\r\n###
Checklist\r\n\r\nDelete any items that are not applicable to this
PR.\r\n\r\n- [ ] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [ ] Any UI touched in this PR is
usable by keyboard only (learn more\r\nabout [keyboard
accessibility](https://webaim.org/techniques/keyboard/))\r\n- [ ] Any UI
touched in this PR does not create any new axe failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[ ] If a plugin configuration key changed, check if it needs to
be\r\nallowlisted in the cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[ ] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[ ] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n\r\n###
Risk Matrix\r\n\r\nDelete this section if it is not applicable to this
PR.\r\n\r\nBefore closing this PR, invite QA, stakeholders, and other
developers to\r\nidentify risks that should be tested prior to the
change/feature\r\nrelease.\r\n\r\nWhen forming the risk matrix, consider
some of the following examples\r\nand how they may potentially impact
the change:\r\n\r\n| Risk | Probability | Severity | Mitigation/Notes
|\r\n\r\n|---------------------------|-------------|----------|-------------------------|\r\n|
Multiple Spaces&mdash;unexpected behavior in non-default Kibana
Space.\r\n| Low | High | Integration tests will verify that all features
are still\r\nsupported in non-default Kibana Space and when user
switches between\r\nspaces. |\r\n| Multiple nodes&mdash;Elasticsearch
polling might have race conditions\r\nwhen multiple Kibana nodes are
polling for the same tasks. | High | Low\r\n| Tasks are idempotent, so
executing them multiple times will not result\r\nin logical error, but
will degrade performance. To test for this case we\r\nadd plenty of unit
tests around this logic and document manual testing\r\nprocedure. |\r\n|
Code should gracefully handle cases when feature X or plugin Y
are\r\ndisabled. | Medium | High | Unit tests will verify that any
feature flag\r\nor plugin combination still results in our service
operational. |\r\n| [See more potential
risk\r\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)
|\r\n\r\n\r\n### For maintainers\r\n\r\n- [ ] This was checked for
breaking API changes and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"d89f32a6aca0b522c606e5aec668cee5a3267d4a"}},{"branch":"8.x","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Quynh Nguyen (Quinn) <[email protected]>
  • Loading branch information
kibanamachine and qn895 authored Oct 15, 2024
1 parent 2a28843 commit e24a665
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ export const OptionsListPopover = ({
}: OptionsListPopoverProps) => {
const { populatedFields } = useFieldStatsFlyoutContext();

const [showEmptyFields, setShowEmptyFields] = useState(false);
const [showEmptyFields, setShowEmptyFields] = useState(
populatedFields ? !(populatedFields.size > 0) : true
);
const id = useMemo(() => htmlIdGenerator()(), []);

const filteredOptions = useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@

import type { FC } from 'react';
import React, { useMemo, useState } from 'react';
import type { EuiComboBoxOptionOption, EuiComboBoxSingleSelectionShape } from '@elastic/eui';
import type {
EuiComboBoxOptionOption,
EuiComboBoxSingleSelectionShape,
EuiFormControlLayoutProps,
} from '@elastic/eui';
import { EuiInputPopover, htmlIdGenerator, EuiFormControlLayout, EuiFieldText } from '@elastic/eui';
import { css } from '@emotion/react';
import { i18n } from '@kbn/i18n';
Expand All @@ -18,8 +22,6 @@ import type { DropDownLabel } from './types';
const MIN_POPOVER_WIDTH = 400;

export const optionCss = css`
display: flex;
align-items: center;
.euiComboBoxOption__enterBadge {
display: none;
}
Expand All @@ -31,7 +33,8 @@ export const optionCss = css`
}
`;

interface OptionListWithFieldStatsProps {
interface OptionListWithFieldStatsProps
extends Pick<EuiFormControlLayoutProps, 'prepend' | 'compressed'> {
options: DropDownLabel[];
placeholder?: string;
'aria-label'?: string;
Expand All @@ -58,6 +61,8 @@ export const OptionListWithFieldStats: FC<OptionListWithFieldStatsProps> = ({
isDisabled,
isLoading,
isClearable = true,
prepend,
compressed,
'aria-label': ariaLabel,
'data-test-subj': dataTestSubj,
}) => {
Expand All @@ -68,13 +73,12 @@ export const OptionListWithFieldStats: FC<OptionListWithFieldStatsProps> = ({
const comboBoxOptions: DropDownLabel[] = useMemo(
() =>
Array.isArray(options)
? options.map(({ isEmpty, hideTrigger: hideInspectButton, ...o }) => ({
? options.map(({ isEmpty, ...o }) => ({
...o,
css: optionCss,
// Change data-is-empty- because EUI is passing all props to dom element
// so isEmpty is invalid, but we need this info to render option correctly
'data-is-empty': isEmpty,
'data-hide-inspect': hideInspectButton,
}))
: [],
[options]
Expand All @@ -89,6 +93,8 @@ export const OptionListWithFieldStats: FC<OptionListWithFieldStatsProps> = ({
id={popoverId}
input={
<EuiFormControlLayout
prepend={prepend}
compressed={compressed}
fullWidth={fullWidth}
// Adding classname to make functional tests similar to EuiComboBox
className={singleSelection ? 'euiComboBox__inputWrap--plainText' : ''}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import type { EuiComboBoxOptionOption, EuiSelectableOption } from '@elastic/eui'
import type { Aggregation, Field } from '@kbn/ml-anomaly-utils';

interface BaseOption<T> {
key?: string;
label: string | React.ReactNode;
key?: string;
value?: string | number | string[];
isEmpty?: boolean;
hideTrigger?: boolean;
'data-is-empty'?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import React from 'react';

import type { EuiComboBoxOptionsListProps, EuiComboBoxOptionOption } from '@elastic/eui';
import { EuiComboBox } from '@elastic/eui';
import { OptionListWithFieldStats } from '@kbn/ml-field-stats-flyout/options_list_with_stats/option_list_with_stats';

interface Props {
options: EuiComboBoxOptionOption[];
Expand All @@ -30,7 +30,7 @@ export const DropDown: React.FC<Props> = ({
isDisabled,
}) => {
return (
<EuiComboBox
<OptionListWithFieldStats
fullWidth
placeholder={placeholder}
singleSelection={{ asPlainText: true }}
Expand All @@ -40,7 +40,6 @@ export const DropDown: React.FC<Props> = ({
isClearable={false}
data-test-subj={testSubj}
isDisabled={isDisabled}
renderOption={renderOption}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ import type { EuiComboBoxOptionOption } from '@elastic/eui';
import { EuiSpacer, EuiToolTip } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import { FieldStatsInfoButton, useFieldStatsTrigger } from '@kbn/ml-field-stats-flyout';
import { AggListForm } from './list_form';
import { DropDown } from '../aggregation_dropdown';
import type { PivotAggsConfig } from '../../../../common';
import { PivotConfigurationContext } from '../pivot_configuration/pivot_configuration';
import { MAX_NESTING_SUB_AGGS } from '../../../../common/pivot_aggs';
import type { DropDownOptionWithField } from '../step_define/common/get_pivot_dropdown_options';
import type { DropDownOption } from '../../../../common/dropdown';

/**
* Component for managing sub-aggregation of the provided
Expand Down Expand Up @@ -54,11 +57,47 @@ export const SubAggsSection: FC<{ item: PivotAggsConfig }> = ({ item }) => {
}
return nestingLevel <= MAX_NESTING_SUB_AGGS;
}, [item]);
const { handleFieldStatsButtonClick, populatedFields } = useFieldStatsTrigger();

const options = useMemo(() => {
const opts: EuiComboBoxOptionOption[] = [];
state.aggOptions.forEach(({ label, field, options: aggOptions }: DropDownOptionWithField) => {
const isEmpty = populatedFields && field.id ? !populatedFields.has(field.id) : false;

const aggOption: DropDownOption = {
isGroupLabel: true,
key: field.id,
searchableLabel: label,
// @ts-ignore Purposefully passing label as element instead of string
// for more robust rendering
label: (
<FieldStatsInfoButton
isEmpty={populatedFields && !populatedFields.has(field.id)}
field={field}
label={label}
onButtonClick={handleFieldStatsButtonClick}
/>
),
};

if (aggOptions.length) {
opts.push(aggOption);
opts.push(
...aggOptions.map((o) => ({
...o,
isEmpty,
isGroupLabel: false,
searchableLabel: o.label,
}))
);
}
});
return opts;
}, [handleFieldStatsButtonClick, populatedFields, state.aggOptions]);
const dropdown = (
<DropDown
changeHandler={addSubAggHandler}
options={state.aggOptions}
options={options}
placeholder={i18n.translate('xpack.transform.stepDefineForm.addSubAggregationPlaceholder', {
defaultMessage: 'Add a sub-aggregation ...',
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { EuiFormRow, type EuiComboBoxOptionOption } from '@elastic/eui';

import { i18n } from '@kbn/i18n';
import { useFieldStatsTrigger, FieldStatsInfoButton } from '@kbn/ml-field-stats-flyout';

import { type DropDownOptionWithField } from '../step_define/common/get_pivot_dropdown_options';
import type { DropDownOption } from '../../../../common';
import { AggListForm } from '../aggregation_list';
Expand Down Expand Up @@ -41,28 +40,42 @@ export const PivotConfiguration: FC<StepDefineFormHook['pivotConfig']> = memo(
const { aggList, aggOptions, aggOptionsData, groupByList, groupByOptions, groupByOptionsData } =
state;

const aggOptionsWithFieldStats: EuiComboBoxOptionOption[] = useMemo(
() =>
aggOptions.map(({ label, field, options }: DropDownOptionWithField) => {
const aggOption: DropDownOption = {
isGroupLabelOption: true,
key: field.id,
// @ts-ignore Purposefully passing label as element instead of string
// for more robust rendering
label: (
<FieldStatsInfoButton
isEmpty={populatedFields && !populatedFields.has(field.id)}
field={field}
label={label}
onButtonClick={handleFieldStatsButtonClick}
/>
),
options: options ?? [],
};
return aggOption;
}),
[aggOptions, handleFieldStatsButtonClick, populatedFields]
);
const aggOptionsWithFieldStats: EuiComboBoxOptionOption[] = useMemo(() => {
const opts: EuiComboBoxOptionOption[] = [];
aggOptions.forEach(({ label, field, options }: DropDownOptionWithField) => {
const isEmpty = populatedFields && field.id ? !populatedFields.has(field.id) : false;

const aggOption: DropDownOption = {
isGroupLabel: true,
key: field.id,
searchableLabel: label,
// @ts-ignore Purposefully passing label as element instead of string
// for more robust rendering
label: (
<FieldStatsInfoButton
isEmpty={populatedFields && !populatedFields.has(field.id)}
field={field}
label={label}
onButtonClick={handleFieldStatsButtonClick}
/>
),
};

if (options.length) {
opts.push(aggOption);
opts.push(
...options.map((o) => ({
...o,
isEmpty,
isGroupLabel: false,
searchableLabel: o.label,
}))
);
}
});
return opts;
}, [aggOptions, handleFieldStatsButtonClick, populatedFields]);

return (
<PivotConfigurationContext.Provider value={{ actions, state }}>
<EuiFormRow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import React, { type FC } from 'react';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import { EuiButtonIcon, EuiCallOut, EuiComboBox, EuiCopy, EuiFormRow } from '@elastic/eui';
import { useFieldStatsTrigger } from '@kbn/ml-field-stats-flyout';
import type { DropDownLabel } from '@kbn/ml-field-stats-flyout';
import { OptionListWithFieldStats, useFieldStatsTrigger } from '@kbn/ml-field-stats-flyout';
import type { LatestFunctionService } from './hooks/use_latest_function_config';

interface LatestFunctionFormProps {
Expand Down Expand Up @@ -73,7 +74,7 @@ export const LatestFunctionForm: FC<LatestFunctionFormProps> = ({
>
<>
{latestFunctionService.sortFieldOptions.length > 0 && (
<EuiComboBox
<OptionListWithFieldStats
fullWidth
placeholder={i18n.translate('xpack.transform.stepDefineForm.sortPlaceholder', {
defaultMessage: 'Add a date field ...',
Expand All @@ -83,15 +84,19 @@ export const LatestFunctionForm: FC<LatestFunctionFormProps> = ({
selectedOptions={
latestFunctionService.config.sort ? [latestFunctionService.config.sort] : []
}
onChange={(selected) => {
latestFunctionService.updateLatestFunctionConfig({
sort: { value: selected[0].value, label: selected[0].label as string },
});
onChange={(selected: DropDownLabel[]) => {
if (typeof selected[0].value === 'string') {
latestFunctionService.updateLatestFunctionConfig({
sort: {
value: selected[0].value,
label: selected[0].label?.toString(),
},
});
}
closeFlyout();
}}
isClearable={false}
data-test-subj="transformWizardSortFieldSelector"
renderOption={renderOption}
/>
)}
{latestFunctionService.sortFieldOptions.length === 0 && (
Expand Down
15 changes: 12 additions & 3 deletions x-pack/test/functional/services/transform/wizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,10 @@ export function TransformWizardProvider({ getService, getPageObjects }: FtrProvi
},

async setSortFieldValue(identificator: string, label: string) {
await comboBox.set('transformWizardSortFieldSelector > comboBoxInput', identificator);
await ml.commonUI.setOptionsListWithFieldStatsValue(
'transformWizardSortFieldSelector > comboBoxInput',
identificator
);
await this.assertSortFieldInputValue(identificator);
},

Expand Down Expand Up @@ -507,7 +510,10 @@ export function TransformWizardProvider({ getService, getPageObjects }: FtrProvi
expectedLabel: string,
expectedIntervalLabel?: string
) {
await comboBox.set('transformGroupBySelection > comboBoxInput', identifier);
await ml.commonUI.setOptionsListWithFieldStatsValue(
'transformGroupBySelection > comboBoxInput',
identifier
);
await this.assertGroupByInputValue([]);
await this.assertGroupByEntryExists(index, expectedLabel, expectedIntervalLabel);
},
Expand Down Expand Up @@ -582,7 +588,10 @@ export function TransformWizardProvider({ getService, getPageObjects }: FtrProvi
formData?: Record<string, any>,
parentSelector = ''
) {
await comboBox.set(this.getAggComboBoxInputSelector(parentSelector), identifier);
await ml.commonUI.setOptionsListWithFieldStatsValue(
this.getAggComboBoxInputSelector(parentSelector),
identifier
);
await this.assertAggregationInputValue([], parentSelector);
await this.assertAggregationEntryExists(index, expectedLabel, parentSelector);

Expand Down

0 comments on commit e24a665

Please sign in to comment.