-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
fix(dashboards): update url with legend selection #105495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
fix(dashboards): update url with legend selection #105495
Conversation
| const releasesSelectionDiffersFromDefault = | ||
| releasesKey in selected && selected[releasesKey] !== showReleaseByDefault; | ||
|
|
||
| const thisWidgetWithoutReleasesWasSelected = | ||
| !Object.keys(selected).includes(`Releases${SERIES_NAME_DELIMITER}${widget.id}`) && | ||
| Object.values(selected).filter(value => value === false).length === 1; | ||
| !(releasesKey in selected) && | ||
| Object.values(selected).filter(value => value === showReleaseByDefault).length === | ||
| 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: The condition for thisWidgetWithoutReleasesWasSelected incorrectly checks against showReleaseByDefault instead of false, preventing correct URL updates when only the releases series is deselected.
Severity: HIGH | Confidence: High
🔍 Detailed Analysis
The logic to determine if a widget's release series was the only unselected item is flawed. The variable thisWidgetWithoutReleasesWasSelected now compares the number of selected series against showReleaseByDefault. However, the URL is updated by encoding unselected series (where the value is false). When showReleaseByDefault is true, the condition incorrectly checks if exactly one item is selected, rather than if exactly one item is unselected. This will prevent the URL from being updated correctly when the user modifies the legend selection for widgets where releases are shown by default.
💡 Suggested Fix
The condition should check for exactly one unselected item, regardless of the default visibility. Change Object.values(selected).filter(value => value === showReleaseByDefault).length === 1 back to Object.values(selected).filter(value => value === false).length === 1 to align with the URL encoding logic that tracks unselected series.
🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: static/app/views/dashboards/widgetLegendSelectionState.tsx#L61-L67
Potential issue: The logic to determine if a widget's release series was the only
unselected item is flawed. The variable `thisWidgetWithoutReleasesWasSelected` now
compares the number of selected series against `showReleaseByDefault`. However, the URL
is updated by encoding *unselected* series (where the value is `false`). When
`showReleaseByDefault` is `true`, the condition incorrectly checks if exactly one item
is selected, rather than if exactly one item is unselected. This will prevent the URL
from being updated correctly when the user modifies the legend selection for widgets
where releases are shown by default.
Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 8001953
| [WidgetLegendNameEncoderDecoder.encodeSeriesNameForLegend( | ||
| 'Releases', | ||
| widget.id | ||
| )]: false, | ||
| )]: this.shouldShowReleaseByDefault(widget), | ||
| } | ||
| : {}; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: getWidgetSelectionState doesn't provide a default 'Releases' legend state for BAR charts, even though they support timeseries, because it incorrectly checks widgetRequiresLegendUnselection().
Severity: HIGH | Confidence: High
🔍 Detailed Analysis
The function getWidgetSelectionState fails to provide a default legend state for BAR chart widgets, even though they support timeseries visualization and are intended to show releases by default. The logic only returns a default state for widgets where widgetRequiresLegendUnselection() is true, which is limited to AREA and LINE charts. As a result, when the dashboards-widget-timeseries-visualization feature is enabled, BAR charts will be initialized with an empty legendSelection, failing to display the 'Releases' series in the legend by default as intended.
💡 Suggested Fix
The condition in getWidgetSelectionState should be based on whether the widget supports the new timeseries visualization, not just if it requires legend unselection. Change the condition from this.widgetRequiresLegendUnselection(widget) to this.shouldShowReleaseByDefault(widget) to ensure all timeseries-capable charts, including BAR charts, receive the default 'Releases' legend state.
🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: static/app/views/dashboards/widgetLegendSelectionState.tsx#L154-L160
Potential issue: The function `getWidgetSelectionState` fails to provide a default
legend state for `BAR` chart widgets, even though they support timeseries visualization
and are intended to show releases by default. The logic only returns a default state for
widgets where `widgetRequiresLegendUnselection()` is true, which is limited to `AREA`
and `LINE` charts. As a result, when the `dashboards-widget-timeseries-visualization`
feature is enabled, `BAR` charts will be initialized with an empty `legendSelection`,
failing to display the 'Releases' series in the legend by default as intended.
Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 8001953
| 1; | ||
|
|
||
| if (thisWidgetWithReleasesWasSelected || thisWidgetWithoutReleasesWasSelected) { | ||
| if (releasesSelectionDiffersFromDefault || thisWidgetWithoutReleasesWasSelected) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
URL not updated when hiding non-releases series for first time
When there's no unselectedSeries in the URL and a user hides a non-Releases series for the first time, the URL won't be updated. The new condition releasesSelectionDiffersFromDefault only checks if the Releases series state differs from default, but fails to detect when other series are hidden. The old logic checked if the count of hidden series (value === false) changed from the default, which correctly detected all legend changes. Additionally, thisWidgetWithoutReleasesWasSelected incorrectly filters for value === showReleaseByDefault when it should always check for value === false (hidden series).
When dashboards uses the new charts, we now:
Additionally, the widget legend state allows releases to be on or off by default. For the new charts, we have them on by default.