Skip to content

Commit 8bb6a9b

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 8bb6a9b

File tree

4 files changed

+26
-10
lines changed

4 files changed

+26
-10
lines changed

ui/packages/shared/profile/src/ProfileFlameGraph/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,9 @@ const ProfileFlameGraph = function ProfileFlameGraphNonMemo({
376376
errorMessage={
377377
<>
378378
<span>
379-
{error.message ? capitalizeOnlyFirstLetter(error.message) : 'An error occurred'}
379+
{error.message != null
380+
? capitalizeOnlyFirstLetter(error.message)
381+
: 'An error occurred'}
380382
</span>
381383
{isFlameChart ? flamechartHelpText ?? null : null}
382384
</>

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
}

ui/packages/shared/profile/src/useSumBy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ export const useDraftSumBy = (
267267

268268
return {
269269
draftSumBy: draftSumBy ?? defaultSumBy ?? DEFAULT_EMPTY_SUM_BY,
270-
setDraftSumBy: setDraftSumBy,
270+
setDraftSumBy,
271271
isDraftSumByLoading: isLoading,
272272
};
273273
};

0 commit comments

Comments
 (0)