Skip to content

Commit 369f09e

Browse files
authored
fix(widget-builder): Reset legend alias on dataset change (#84194)
The legend alias didn't reset when changing the datasets which didn't make sense so now it does (for chart widgets). It isn't reset when changing between chart types (this is the behaviour in the old widget builder so I'm keeping that). Let me know if there's any other odd behaviour with the legend aliases that you want me to change i can do it in this pr.
1 parent ee445ae commit 369f09e

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

static/app/views/dashboards/widgetBuilder/hooks/useWidgetBuilderState.spec.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,33 @@ describe('useWidgetBuilderState', () => {
908908

909909
expect(result.current.state.thresholds).toBeUndefined();
910910
});
911+
912+
it('resets the legend alias when the dataset is switched', () => {
913+
mockedUsedLocation.mockReturnValue(
914+
LocationFixture({
915+
query: {
916+
dataset: WidgetType.ERRORS,
917+
displayType: DisplayType.LINE,
918+
legendAlias: ['test'],
919+
},
920+
})
921+
);
922+
923+
const {result} = renderHook(() => useWidgetBuilderState(), {
924+
wrapper: WidgetBuilderProvider,
925+
});
926+
927+
expect(result.current.state.legendAlias).toEqual(['test']);
928+
929+
act(() => {
930+
result.current.dispatch({
931+
type: BuilderStateAction.SET_DATASET,
932+
payload: WidgetType.TRANSACTIONS,
933+
});
934+
});
935+
936+
expect(result.current.state.legendAlias).toEqual([]);
937+
});
911938
});
912939

913940
describe('fields', () => {

static/app/views/dashboards/widgetBuilder/hooks/useWidgetBuilderState.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ function useWidgetBuilderState(): {
288288

289289
setThresholds(undefined);
290290
setQuery([config.defaultWidgetQuery.conditions]);
291+
setLegendAlias([]);
291292
setSelectedAggregate(undefined);
292293
break;
293294
case BuilderStateAction.SET_FIELDS:

0 commit comments

Comments
 (0)