Skip to content

[Metrics][Discover] Add an option to clear the selection in the dropdowns#233776

Merged
jennypavlova merged 22 commits intoelastic:mainfrom
jennypavlova:233653-metricsdiscover-add-an-option-to-clear-the-selection-in-the-dropdowns
Sep 5, 2025
Merged

[Metrics][Discover] Add an option to clear the selection in the dropdowns#233776
jennypavlova merged 22 commits intoelastic:mainfrom
jennypavlova:233653-metricsdiscover-add-an-option-to-clear-the-selection-in-the-dropdowns

Conversation

@jennypavlova
Copy link
Member

@jennypavlova jennypavlova commented Sep 2, 2025

Closes #233653

Summary

This PR adds an option to clear the selection in the dimension and value selectors. When all dimensions are cleared, it will clear all values as well as those related to the corresponding dimensions. The PR also extracts the toolbar_selector to a shared place and uses it in the metrics grid and the histogram without adding the dependency issue.

image image

How to test

  • Set the following config to kibana.dev.yml
discover.experimental.enabledProfiles:
  - observability-metrics-data-source-profile
metricsExperience.enabled: true
dimf.mov
  • In case of logs-* search, for example, the breakdown selector should work as before:
image

@jennypavlova jennypavlova self-assigned this Sep 2, 2025
@jennypavlova jennypavlova added release_note:skip Skip the PR/issue when compiling release notes backport:skip This PR does not require backporting Team:obs-ux-infra_services - DEPRECATED DEPRECATED - Use Team:obs-presentation. labels Sep 2, 2025
@jennypavlova jennypavlova marked this pull request as ready for review September 3, 2025 12:50
@jennypavlova jennypavlova requested a review from a team September 3, 2025 12:50
@jennypavlova jennypavlova requested a review from a team as a code owner September 3, 2025 12:50
@elasticmachine
Copy link
Contributor

Pinging @elastic/obs-ux-infra_services-team (Team:obs-ux-infra_services)

Copy link
Contributor

@crespocarlos crespocarlos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Left a few nits

On the new package to centralize the ToolbarSelector, I don't have any strong opinions against it. The component appears to be generic enough to be reused outside the Discover/Metrics Experience context, and it may help as more features are added to One Discover. We'll see.

fields={fields}
onChange={onDimensionsChange}
selectedDimensions={dimensions}
clearDimensionSelection={() => onClearAllDimensions()}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For event, let's follow the on[Event] convention, like onChange

Suggested change
clearDimensionSelection={() => onClearAllDimensions()}
onClear={onClearAllDimensions}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you checked this suggestion?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, missed that. Good point, renamed ✅

disabled={dimensions.length === 0}
indices={[indexPattern]}
timeRange={timeRange}
clearValuesSelection={() => dispatch(setValueFilters([]))}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. Perhaps you could also use the onValuesChange and pass an empty array

Suggested change
clearValuesSelection={() => dispatch(setValueFilters([]))}
const onClearValues = useCallback(() => onValuesChange([]))
<ValuesSelector
onClear={onClearValues}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you checked this suggestion? Wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, done ✅

return (
<FormattedMessage
id="metricsExperience.breakdownFieldSelector.breakdownFieldButtonLabel"
id="metricsExperience.dimensionsSelector.breakdownFieldButtonLabel"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice. thanks for fixing this.

options={options}
singleSelection={false}
onChange={handleChange}
popoverTitle={i18n.translate('metricsExperience.dimensionsSelector.label', {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There’s no title in the designs. Do we need one?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, I removed it. It was also adding the aria-labels using the title content, and unfortunately, we won't get them now 😞

);
}, [selectedDimensions]);

const clearAllSection = useMemo(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're repeating this component here and in the values_selector. Should we extract it into a new file and reuse it on both components?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! I expected that they would have more differences when I added them. I created a component and reused it 👍

searchable={true}
singleSelection={true}
popoverTitle="My Popover Title"
clearAllSection={<span>Custom Section</span>}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If clearAllSection accepts any component - not necessarily a component that has a selection counter and a clear all button -, should we rename the prop to something more generic but clear enough to tell it will be rendered below the search bar?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, thanks! I also wasn't sure how to call it TBH, I asked GH Copilot and it suggested popoverContentBelowSearch, so I would go with that (this was the best suggestion it gave IMO 😅 )

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe searchProps: { append: React.ReactNode } }?

Copy link
Member Author

@jennypavlova jennypavlova Sep 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have search props > append in a different context when using search in EuiSelectable 🤔 And it's not directly inside the search, so I think popoverContentBelowSearch describes it well. Or maybe just contentBelowSearch, idk

fireEvent.click(getByText('B'));
expect(onChange).toHaveBeenCalled();
// Should be called with array of selected options
expect(Array.isArray(onChange.mock.calls[0][0])).toBe(true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we validate the items that were passed to onChange?

eg:

 expect(onChange).toHaveBeenCalledWith([
    { label: 'A', value: 'a' },
    { label: 'B', value: 'b' },
  ]);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestions! We have 2 calls, so I used toHaveBeenNthCalledWith and checked both calls 👍

fireEvent.click(getByTestId('toolbarSelectorTestButton'));
fireEvent.click(getByText('Option 2'));
expect(onChange).toHaveBeenCalled();
expect(onChange.mock.calls[0][0].label).toBe('Option 2');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we validate it like this?

 expect(onChange).toHaveBeenCalledWith({ label: 'Option 2', value: 'option2' });

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done ✅

Copy link
Contributor

@AlexGPlay AlexGPlay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discover changes lgtm - code review only

Copy link
Member Author

@jennypavlova jennypavlova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@crespocarlos Thank you for reviewing! I believe I addressed all the comments. Can you please take a look again when you have time?

searchable={true}
singleSelection={true}
popoverTitle="My Popover Title"
clearAllSection={<span>Custom Section</span>}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, thanks! I also wasn't sure how to call it TBH, I asked GH Copilot and it suggested popoverContentBelowSearch, so I would go with that (this was the best suggestion it gave IMO 😅 )

fireEvent.click(getByText('B'));
expect(onChange).toHaveBeenCalled();
// Should be called with array of selected options
expect(Array.isArray(onChange.mock.calls[0][0])).toBe(true);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestions! We have 2 calls, so I used toHaveBeenNthCalledWith and checked both calls 👍

fireEvent.click(getByTestId('toolbarSelectorTestButton'));
fireEvent.click(getByText('Option 2'));
expect(onChange).toHaveBeenCalled();
expect(onChange.mock.calls[0][0].label).toBe('Option 2');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done ✅

options={options}
singleSelection={false}
onChange={handleChange}
popoverTitle={i18n.translate('metricsExperience.dimensionsSelector.label', {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, I removed it. It was also adding the aria-labels using the title content, and unfortunately, we won't get them now 😞

);
}, [selectedDimensions]);

const clearAllSection = useMemo(() => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! I expected that they would have more differences when I added them. I created a component and reused it 👍

Copy link
Contributor

@crespocarlos crespocarlos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 🚀

@jennypavlova jennypavlova enabled auto-merge (squash) September 4, 2025 16:34
Copy link
Contributor

@davismcphee davismcphee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for getting to this late after it was already approved on our end. Data Discovery code changes seem fine to me, just have a question about the dependencies and new package.

@davismcphee davismcphee disabled auto-merge September 4, 2025 17:13
@davismcphee
Copy link
Contributor

Just an fyi that I disabled auto merge to give @jennypavlova an opportunity to respond to my comment before it auto merges.

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
datasetQuality 842 843 +1
discover 1488 1490 +2
total +3

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/shared-ux-toolbar-selector - 24 +24
@kbn/unified-histogram 92 88 -4
total +20

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
datasetQuality 437.3KB 437.2KB -42.0B
discover 1.1MB 1.1MB +1.3KB
total +1.3KB

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
@kbn/unified-histogram 17 14 -3

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
kbnUiSharedDeps-srcJs 3.8MB 3.8MB +262.0B
Unknown metric groups

API count

id before after diff
@kbn/shared-ux-toolbar-selector - 24 +24
@kbn/unified-histogram 118 114 -4
total +20

History

cc @jennypavlova

@jennypavlova jennypavlova merged commit f081354 into elastic:main Sep 5, 2025
15 checks passed
shahargl pushed a commit to shahargl/kibana that referenced this pull request Sep 7, 2025
…owns (elastic#233776)

Closes elastic#233653

## Summary

This PR adds an option to clear the selection in the dimension and value
selectors. When all dimensions are cleared, it will clear all values as
well as those related to the corresponding dimensions. The PR also
extracts the toolbar_selector to a shared place and uses it in the
metrics grid and the histogram without adding the dependency issue.

<img width="1276" height="669" alt="image"
src="https://github.com/user-attachments/assets/e83d3338-fbe2-4f87-b2b0-d66ec50b79c9"
/>
<img width="2328" height="687" alt="image"
src="https://github.com/user-attachments/assets/6c13b429-8566-4f8f-aa88-35207f524abf"
/>


## How to test
- Set the following config to `kibana.dev.yml`
```yml
discover.experimental.enabledProfiles:
  - observability-metrics-data-source-profile
metricsExperience.enabled: true
 ```
- Navigate to Discover and Switch to ESQL mode
- Set the space to Observability
- Run `FROM metrics-*` search
- Clone https://github.com/simianhacker/simian-forge/tree/main
- Run ` ./forge --dataset hosts --count 25 --interval 30s`
- Check the drop-downs in the metrics grid:


https://github.com/user-attachments/assets/77313c81-59fa-41ee-b3f9-60384212cfab


- In case of `logs-*` search, for example, the breakdown selector should work as before: 

<img width="3544" height="1332" alt="image" src="https://github.com/user-attachments/assets/ce33654f-9835-456a-b47f-6a60ed58edd8" />

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
KodeRad pushed a commit to KodeRad/kibana that referenced this pull request Sep 15, 2025
…owns (elastic#233776)

Closes elastic#233653

## Summary

This PR adds an option to clear the selection in the dimension and value
selectors. When all dimensions are cleared, it will clear all values as
well as those related to the corresponding dimensions. The PR also
extracts the toolbar_selector to a shared place and uses it in the
metrics grid and the histogram without adding the dependency issue.

<img width="1276" height="669" alt="image"
src="https://github.com/user-attachments/assets/e83d3338-fbe2-4f87-b2b0-d66ec50b79c9"
/>
<img width="2328" height="687" alt="image"
src="https://github.com/user-attachments/assets/6c13b429-8566-4f8f-aa88-35207f524abf"
/>


## How to test
- Set the following config to `kibana.dev.yml`
```yml
discover.experimental.enabledProfiles:
  - observability-metrics-data-source-profile
metricsExperience.enabled: true
 ```
- Navigate to Discover and Switch to ESQL mode
- Set the space to Observability
- Run `FROM metrics-*` search
- Clone https://github.com/simianhacker/simian-forge/tree/main
- Run ` ./forge --dataset hosts --count 25 --interval 30s`
- Check the drop-downs in the metrics grid:


https://github.com/user-attachments/assets/77313c81-59fa-41ee-b3f9-60384212cfab


- In case of `logs-*` search, for example, the breakdown selector should work as before: 

<img width="3544" height="1332" alt="image" src="https://github.com/user-attachments/assets/ce33654f-9835-456a-b47f-6a60ed58edd8" />

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
CAWilson94 pushed a commit to CAWilson94/kibana that referenced this pull request Sep 24, 2025
…owns (elastic#233776)

Closes elastic#233653

## Summary

This PR adds an option to clear the selection in the dimension and value
selectors. When all dimensions are cleared, it will clear all values as
well as those related to the corresponding dimensions. The PR also
extracts the toolbar_selector to a shared place and uses it in the
metrics grid and the histogram without adding the dependency issue.

<img width="1276" height="669" alt="image"
src="https://github.com/user-attachments/assets/e83d3338-fbe2-4f87-b2b0-d66ec50b79c9"
/>
<img width="2328" height="687" alt="image"
src="https://github.com/user-attachments/assets/6c13b429-8566-4f8f-aa88-35207f524abf"
/>


## How to test
- Set the following config to `kibana.dev.yml`
```yml
discover.experimental.enabledProfiles:
  - observability-metrics-data-source-profile
metricsExperience.enabled: true
 ```
- Navigate to Discover and Switch to ESQL mode
- Set the space to Observability
- Run `FROM metrics-*` search
- Clone https://github.com/simianhacker/simian-forge/tree/main
- Run ` ./forge --dataset hosts --count 25 --interval 30s`
- Check the drop-downs in the metrics grid:


https://github.com/user-attachments/assets/77313c81-59fa-41ee-b3f9-60384212cfab


- In case of `logs-*` search, for example, the breakdown selector should work as before: 

<img width="3544" height="1332" alt="image" src="https://github.com/user-attachments/assets/ce33654f-9835-456a-b47f-6a60ed58edd8" />

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team:obs-ux-infra_services - DEPRECATED DEPRECATED - Use Team:obs-presentation. v9.2.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Metrics][Discover] Add an option to clear the selection in the dropdowns

6 participants