Skip to content

Commit

Permalink
fix(widget-builder): Reset legend alias on dataset change (#84194)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nikkikapadia authored Jan 29, 2025
1 parent ee445ae commit 369f09e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,33 @@ describe('useWidgetBuilderState', () => {

expect(result.current.state.thresholds).toBeUndefined();
});

it('resets the legend alias when the dataset is switched', () => {
mockedUsedLocation.mockReturnValue(
LocationFixture({
query: {
dataset: WidgetType.ERRORS,
displayType: DisplayType.LINE,
legendAlias: ['test'],
},
})
);

const {result} = renderHook(() => useWidgetBuilderState(), {
wrapper: WidgetBuilderProvider,
});

expect(result.current.state.legendAlias).toEqual(['test']);

act(() => {
result.current.dispatch({
type: BuilderStateAction.SET_DATASET,
payload: WidgetType.TRANSACTIONS,
});
});

expect(result.current.state.legendAlias).toEqual([]);
});
});

describe('fields', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ function useWidgetBuilderState(): {

setThresholds(undefined);
setQuery([config.defaultWidgetQuery.conditions]);
setLegendAlias([]);
setSelectedAggregate(undefined);
break;
case BuilderStateAction.SET_FIELDS:
Expand Down

0 comments on commit 369f09e

Please sign in to comment.