Skip to content

Commit c6f28c7

Browse files
committed
Add sumBy parameter to commitDraft in query state hooks
This allows updating the sumBy value when committing a draft.
1 parent 5b27526 commit c6f28c7

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

ui/packages/shared/profile/src/ProfileSelector/useAutoFlameChartQuerySelector.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ interface UseAutoFlameChartQuerySelectorProps {
2929
setTimeRangeSelection: Dispatch<SetStateAction<DateTimeRange>>;
3030
setDraftTimeRange: (from: number, to: number, timeSelection: string) => void;
3131
setDraftSumBy: (sumBy: string[] | undefined) => void;
32-
commitDraft: (refreshedTimeRange?: {from: number; to: number; timeSelection: string}) => void;
32+
commitDraft: (
33+
refreshedTimeRange?: {from: number; to: number; timeSelection: string},
34+
expression?: string,
35+
sumBy?: string[] | undefined
36+
) => void;
3337
}
3438

3539
export const useAutoFlameChartQuerySelector = ({
@@ -102,11 +106,15 @@ export const useAutoFlameChartQuerySelector = ({
102106
setDraftTimeRange(fromMs, toMs, timeSelection);
103107
setDraftSumBy(optimalSumBy);
104108

105-
commitDraft({
106-
from: fromMs,
107-
to: toMs,
108-
timeSelection,
109-
});
109+
commitDraft(
110+
{
111+
from: fromMs,
112+
to: toMs,
113+
timeSelection,
114+
},
115+
undefined,
116+
optimalSumBy
117+
);
110118

111119
previousDashboardItems.current = dashboardItems;
112120
}, [

ui/packages/shared/profile/src/hooks/useQueryState.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,12 @@ export const useQueryState = (options: UseQueryStateOptions = {}): UseQueryState
270270
// Optional refreshedTimeRange parameter allows re-evaluating relative time ranges (e.g., "last 15 minutes")
271271
// to the current moment when the Search button is clicked
272272
// Optional expression parameter allows updating the expression before committing
273+
// Optional sumBy parameter allows updating the sumBy before committing
273274
const commitDraft = useCallback(
274275
(
275276
refreshedTimeRange?: {from: number; to: number; timeSelection: string},
276-
expression?: string
277+
expression?: string,
278+
sumBy?: string[] | undefined
277279
) => {
278280
batchUpdates(() => {
279281
// Use provided expression or current draft expression
@@ -314,8 +316,12 @@ export const useQueryState = (options: UseQueryStateOptions = {}): UseQueryState
314316
// Parse the final expression to check if it's a delta profile
315317
const finalQuery = Query.parse(finalExpression);
316318
const isDelta = finalQuery.profileType().delta;
319+
320+
// Use provided sumBy or fall back to draftSumBy
321+
const finalSumBy = sumBy !== undefined ? sumBy : draftSumBy;
322+
317323
if (isDelta) {
318-
setSumByParam(sumByToParam(draftSumBy));
324+
setSumByParam(sumByToParam(finalSumBy));
319325
} else {
320326
setSumByParam(DEFAULT_EMPTY_SUM_BY);
321327
}

0 commit comments

Comments
 (0)