Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions ui/packages/shared/profile/src/useSumBy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,14 @@ export const useSumBySelection = (
}
}

// Prefer non-empty URL default over auto-computed default to avoid a
// one-render race where defaultSumBy overwrites the default value from upstream.
const hasExplicitDefault = defaultValue != null && defaultValue.length > 0;
let result =
userSelectedSumBy[profileType?.toString() ?? ''] ?? defaultSumBy ?? DEFAULT_EMPTY_SUM_BY;
userSelectedSumBy[profileType?.toString() ?? ''] ??
(hasExplicitDefault ? defaultValue : undefined) ??
defaultSumBy ??
DEFAULT_EMPTY_SUM_BY;

if (profileType?.delta !== true) {
result = DEFAULT_EMPTY_SUM_BY;
Expand All @@ -123,7 +129,7 @@ export const useSumBySelection = (
lastValidSumByRef.current = result;

return result;
}, [userSelectedSumBy, profileType, defaultSumBy, labelNamesLoading, draftSumBy]);
}, [userSelectedSumBy, profileType, defaultSumBy, labelNamesLoading, draftSumBy, defaultValue]);

return [
sumBy,
Expand Down Expand Up @@ -266,7 +272,11 @@ export const useDraftSumBy = (
const {defaultSumBy, isLoading} = useDefaultSumBy(profileType, labelNamesLoading, labels);

return {
draftSumBy: draftSumBy ?? defaultSumBy ?? DEFAULT_EMPTY_SUM_BY,
draftSumBy:
draftSumBy ??
(defaultValue != null && defaultValue.length > 0 ? defaultValue : undefined) ??
defaultSumBy ??
DEFAULT_EMPTY_SUM_BY,
setDraftSumBy,
isDraftSumByLoading: isLoading,
};
Expand Down
Loading