[9.4] [Metrics][Discover] Fix multi-dimension breakdown picker to match current grid (#263629)#265127
Merged
kibanamachine merged 1 commit intoelastic:9.4from Apr 22, 2026
Merged
Conversation
…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)
Contributor
💚 Build Succeeded
Metrics [docs]Module Count
Async chunks
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Backport
This will backport the following commits from
mainto9.4:Questions ?
Please refer to the Backport tool documentation