Skip to content

[9.4] [Metrics][Discover] Fix multi-dimension breakdown picker to match current grid (#263629)#265127

Merged
kibanamachine merged 1 commit intoelastic:9.4from
kibanamachine:backport/9.4/pr-263629
Apr 22, 2026
Merged

[9.4] [Metrics][Discover] Fix multi-dimension breakdown picker to match current grid (#263629)#265127
kibanamachine merged 1 commit intoelastic:9.4from
kibanamachine:backport/9.4/pr-263629

Conversation

@kibanamachine
Copy link
Copy Markdown
Contributor

Backport

This will backport the following commits from main to 9.4:

Questions ?

Please refer to the Backport tool documentation

…rent grid (elastic#263629)

## Summary

Resolves elastic#263309.

The Metrics in Discover dimension picker had three related problems:

1. The option list wasn't tailored to the metrics currently in the grid:
users could select a dimension that didn't exist in any visible metric.
2. Selecting a second dimension could cause the first to silently drop
out of the picker, producing a "2 selected, 1 tick" state (see the
screenshots on the ticket).
3. Rapid multi-select across disjoint dimensions could land the user in
an empty-grid dead state before the fetch returned.

This PR fixes all three.

- **Tailored list.** The picker's option list is now derived directly
from the dimensions present in the current `METRICS_INFO` response. This
is the union of `dimensionFields` across the currently visible metrics.
- **Selected-still-visible.** Any currently-selected dimension that is
not in the applicable set (a rare race-condition or URL-restore case) is
surfaced at the top of the picker with its checkmark intact, so the
count badge and visible ticks always match and the user can deselect to
get out of the weird state.
- **Optimistic pre-filter.** When the user clicks a dimension, the
picker immediately recomputes its option list from the in-memory
`metricItems` plus the new local selection, hiding any dimension not
carried by a metric that already has the selection. This makes
non-applicable options disappear before the server round-trip, so rapid
multi-select shouldn't reach an empty-grid state via the picker.

## Commit layout

| Commit | Purpose |
|---|---|
| `1eb2379e` | Revert the earlier accumulator approach (delete
`merge_dimensions.ts`, `use_accumulated_dimensions.ts`, related
plumbing). |
| `290aaf17` | Surface selected dimensions even when not in the
applicable set (orphan safety net). |
| `491456ac` | Optimistically filter picker options by current local
selection. |

## How this maps to the ticket

| Ticket clause | How it's satisfied |
|---|---|
| "The list of dimensions should be tailored to what you see in the
grid" | `allDimensions` is now the union of
`metricItems[*].dimensionFields` from the current response. |
| "You shouldn't be able to [select a dimension that doesn't exist in
one of the metrics]" | Optimistic filter removes non-applicable options
the moment the first selection is clicked — the race click on a
subsequently-invalid dimension cannot hit the DOM. |
| "2 dimensions are selected but only one with the tick" | Selected
dimensions always render with a checkmark, via the orphan-surfacing path
when they fall outside the applicable set. |
| "if we hide them we need to consider the scenario where the user
selects multiple before the grid refreshes" | Orphan surfacing +
optimistic filter together make this scenario unreachable through the
picker, and visible/recoverable when it is reached via URL or external
state. |

## Before / after

_Before:_ Picker lists dimensions regardless of whether the user can
meaningfully select them, and silently drops previously-selected
dimensions if the filtered response no longer carries them.

_After:_ Picker lists only dimensions that apply to the current grid,
prevents selecting a dimension that would produce an empty grid, and
never hides an already-selected dimension.

## Test plan

Manual verification focuses on the two scenarios that can't be covered
by the unit tests below. Applicable-set narrowing, orphan surfacing,
count/tick consistency, and max-selection behavior are fully asserted in
`dimensions_selector.test.tsx`; refetch on context change is asserted in
`use_fetch_metrics_data.test.ts`.

Dataset: TSDB indices with divergent dimension sets: e.g. one metric
with dims `environment` + `host.name`, another with `host.name` +
`region`. The repo's Scout fixture currently puts every dimension on
every metric, so for manual verification use a local `metrics-test*`
with divergent shapes. A follow-up ticket tracks extending the Scout
fixture to cover this scenario end-to-end.

- **Ticket repro, end-to-end.** `TS metrics-test*`: open Dimensions
picker and see all dimensions visible.
- Select `environment` picker collapses to `environment` + `host.name`,
`region` is no longer in the list.
  - Deselect: all three return.
- **Rapid multi-select (throttled network).** Use DevTools to throttle
the network, open the picker, click `environment` then attempt to click
`region` before the first fetch returns. `region` must no longer be in
the DOM by the time the second click fires, so the empty-grid state is
unreachable via the picker. This exercises the optimistic filter's
render-race behavior in a real browser, which unit tests can't simulate.

## Follow-ups

- **Scout fixture extension** to reproduce the ticket end-to-end — the
current generator spreads every dimension onto every metric, which
defeats the scenario.
elastic/observability-dev#5481
- **Orphan styling** — decide whether orphan selections should have a
visual distinguisher beyond placement/checkmark. Separate ticket.

---------

Co-authored-by: Lucas Francisco López <lucaslopezf@gmail.com>
(cherry picked from commit f093d70)
@kibanamachine kibanamachine merged commit d3088ae into elastic:9.4 Apr 22, 2026
20 checks passed
@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
discover 2003 2009 +6

Async chunks

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

id before after diff
discover 1.9MB 1.9MB +1.3KB

cc @justinkambic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport This PR is a backport of another PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants