Skip to content

Commit 66617e6

Browse files
narsaynorathbillyvg
authored andcommitted
fix(widget-builder): Applying a grouping should always add a limit (#89480)
Switching datasets was wiping out the limit, and adding a grouping wasn't reinstating the limit by default, so update the hook to add the default. The code in the diff is added to the `SET_FIELDS` action
1 parent 43dd1a2 commit 66617e6

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,6 +1530,53 @@ describe('useWidgetBuilderState', () => {
15301530
{field: 'crash_free_rate(session)', kind: 'desc'},
15311531
]);
15321532
});
1533+
1534+
it('always assigns a limit when there is a y-axis', () => {
1535+
mockedUsedLocation.mockReturnValue(
1536+
LocationFixture({
1537+
query: {
1538+
yAxis: ['count()', 'count_unique(user)'],
1539+
fields: ['event.type'],
1540+
displayType: DisplayType.LINE,
1541+
dataset: WidgetType.ERRORS,
1542+
limit: '5',
1543+
},
1544+
})
1545+
);
1546+
1547+
const {result} = renderHook(() => useWidgetBuilderState(), {
1548+
wrapper: WidgetBuilderProvider,
1549+
});
1550+
1551+
expect(result.current.state.limit).toBe(5);
1552+
1553+
// Changing the dataset will unset the limit
1554+
act(() => {
1555+
result.current.dispatch({
1556+
type: BuilderStateAction.SET_DATASET,
1557+
payload: WidgetType.TRANSACTIONS,
1558+
});
1559+
});
1560+
1561+
expect(result.current.state.limit).toBeUndefined();
1562+
1563+
// Changing the dataset back and applying a grouping should set a limit
1564+
act(() => {
1565+
result.current.dispatch({
1566+
type: BuilderStateAction.SET_DATASET,
1567+
payload: WidgetType.ERRORS,
1568+
});
1569+
});
1570+
1571+
act(() => {
1572+
result.current.dispatch({
1573+
type: BuilderStateAction.SET_FIELDS,
1574+
payload: [{field: 'event.type', kind: FieldValueKind.FIELD}],
1575+
});
1576+
});
1577+
1578+
expect(result.current.state.limit).toBe(5);
1579+
});
15331580
});
15341581

15351582
describe('yAxis', () => {

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,15 @@ function useWidgetBuilderState(): {
457457
},
458458
]);
459459
}
460+
461+
if (action.payload.length > 0 && (yAxis?.length ?? 0) > 0 && !defined(limit)) {
462+
setLimit(
463+
Math.min(
464+
DEFAULT_RESULTS_LIMIT,
465+
getResultsLimit(query?.length ?? 1, yAxis?.length ?? 0)
466+
)
467+
);
468+
}
460469
break;
461470
}
462471
case BuilderStateAction.SET_Y_AXIS:

0 commit comments

Comments
 (0)