Skip to content

fix(dashboards): Disambiguate unaliased filters in widget legends#110908

Merged
gggritso merged 7 commits intomasterfrom
worktree-georgegritsouk/dain-1305-chart-legend-labels-are-duplicated-in-some-widgets
Mar 18, 2026
Merged

fix(dashboards): Disambiguate unaliased filters in widget legends#110908
gggritso merged 7 commits intomasterfrom
worktree-georgegritsouk/dain-1305-chart-legend-labels-are-duplicated-in-some-widgets

Conversation

@gggritso
Copy link
Member

@gggritso gggritso commented Mar 17, 2026

Imagine you add two filters for one chart with a group by:
Screenshot 2026-03-17 at 3 21 42 PM

Before:
Screenshot 2026-03-17 at 3 20 49 PM

After:
Screenshot 2026-03-17 at 3 21 04 PM

We weren't disambiguating the legends at all between the two filters! With this PR, if the queries don't have any aliases we prefix each series by the query that filtered it, so at least the items are all kept separate.

Fix 1: Widget query hooks now call getSeriesQueryPrefix after transformSeries to prefix series names with prettified query conditions when there are multiple queries and no alias. This happens in the hooks (not the visualization component) because the hooks iterate per-query and know which query produced each series — by the time series reach the visualization layer, they're a flat array with no query association.

Fix 2: Changed columns.length > 1 to columns.length > 0 in transformWidgetSeriesToTimeSeries so the yAxis is appended whenever there's at least one group-by column.

This is all destined to be updated very soon when we start using /events-timeseries/ in the Dashboard fetchers, since TimeSeries objects preserve more context and we'll be able to consolidate all this formatting.

Fixes DAIN-1305

gggritso and others added 2 commits March 17, 2026 11:42
…d multi-aggregate widgets

When WidgetType.ERRORS was added to the new VisualizationWidget rendering
path, legend labels became duplicated because transformWidgetSeriesToTimeSeries
recomputed labels from the TimeSeries structure and lost query association.

Two fixes:
- Multi-query without aliases: widget query hooks now prefix series names
  with prettified query conditions via labelSeriesForLegend, since hooks
  know which query produced each series.
- Multi-aggregate with group by: changed columns.length > 1 to > 0 so the
  yAxis is appended for uniqueness with any group-by column.

DAIN-1305
Split labelSeriesForLegend into two focused utilities:
- getSeriesQueryPrefix: returns the prefix for a query's series
- prettifyQueryConditions: converts internal wildcard operator markers
  back to user-facing syntax (*value*, value*, *value)

Rename getSeriesNamePrefix to getSeriesQueryPrefix and update hooks
to apply the prefix inline instead of creating new Series objects.

Revert transformWidgetSeriesToTimeSeries to its original query
resolution logic (alias-based matching with firstQuery fallback).

DAIN-1305
Co-Authored-By: Claude <noreply@anthropic.com>
@gggritso gggritso requested a review from a team as a code owner March 17, 2026 19:19
@linear-code
Copy link

linear-code bot commented Mar 17, 2026

@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Mar 17, 2026
@gggritso gggritso changed the title fix(dashboards): Fix duplicated chart legend labels in some widgets fix(dashboards): Disambiguate unaliased filters in widget legends Mar 17, 2026
Accept upstream named export rename of useApi alongside our
SERIES_NAME_PART_DELIMITER import.
Use SERIES_QUERY_DELIMITER (' > ') to separate the query prefix from
the rest of the series name, matching the existing convention in
transformEventsResponseToSeries for alias + group-by series.

This makes parsing robust: transformWidgetSeriesToTimeSeries checks
for ' > ' to extract the query prefix, instead of heuristically
guessing which part of a ' : '-delimited name is the prefix vs a
group-by value.

Also fixes a bug where group-by values (e.g., "prod") in multi-query
widgets with empty conditions were misidentified as query names.

DAIN-1305
Co-Authored-By: Claude <noreply@anthropic.com>
…T_DELIMITER

Move SERIES_QUERY_DELIMITER to transformLegacySeriesToTimeSeries.tsx
so both series name delimiter constants are defined side by side.

DAIN-1305
Co-Authored-By: Claude <noreply@anthropic.com>
Copy link
Contributor

@DominikB2014 DominikB2014 left a comment

Choose a reason for hiding this comment

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

code lgtm! I feel like it should be the responsibility of the visualization to set the series name and not the data fetching hooks, but since we're eventually moving to the time series endpoint, we can rethink that later!

@gggritso
Copy link
Member Author

@DominikB2014 totally, it's a tough problem though because in a Dashboards context we are sending multiple queries out that all return the same aggregations, so we either have to somehow attach that information to the aggregates themselves or keep track of the queries, both of which are yucky! I will definitely revisit this soon

Accept upstream named export rename of RequestError alongside our
SERIES_QUERY_DELIMITER import.
Copy link
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Compute the split of unprefixedName once and reuse it for both yAxis
lookup and passing to transformLegacySeriesToTimeSeries. Reuses
splitSeriesName when there's no query prefix delimiter.

DAIN-1305
Co-Authored-By: Claude <noreply@anthropic.com>
@gggritso gggritso merged commit ad453d7 into master Mar 18, 2026
64 checks passed
@gggritso gggritso deleted the worktree-georgegritsouk/dain-1305-chart-legend-labels-are-duplicated-in-some-widgets branch March 18, 2026 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants