Skip to content

Commit b08efaf

Browse files
authored
ui: External sumby value handled properly in the query state (#6370)
* External sumby value handled properly in the query state * Linter fix
1 parent e84502e commit b08efaf

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

ui/packages/shared/components/src/ParcaContext/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export interface AdditionalMetricsGraphProps {
5555
interface ExternalProfilerComponentProps {
5656
disableProfileTypesDropdown?: boolean;
5757
defaultProfileType?: string;
58+
defaultSumBy?: string[];
5859
configuredLabelNames?: string[];
5960
disableExplorativeQuerying?: boolean;
6061
profileFilterDefaults?: unknown[];

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ interface UseQueryStateReturn {
7979
}
8080

8181
export const useQueryState = (options: UseQueryStateOptions = {}): UseQueryStateReturn => {
82-
const {queryServiceClient: queryClient} = useParcaContext();
82+
const {queryServiceClient: queryClient, externalProfilerComponent} = useParcaContext();
8383
const {
8484
suffix = '',
8585
defaultExpression = '',
@@ -153,6 +153,13 @@ export const useQueryState = (options: UseQueryStateOptions = {}): UseQueryState
153153
// Parse sumBy from URL parameter format
154154
const sumBy = useSumByFromParams(sumByParam ?? undefined);
155155

156+
// Fall back to the externally-provided sumBy default when the URL carries no
157+
// sum_by, so the materialized value reflects it instead of the empty __none__
158+
// sentinel (an explicit __none__ from the URL is left untouched).
159+
const externalSumBy = externalProfilerComponent?.defaultSumBy;
160+
const sumByWithViewDefault =
161+
sumBy ?? (externalSumBy != null && externalSumBy.length > 0 ? externalSumBy : undefined);
162+
156163
// Draft state management
157164
const [draftExpression, setDraftExpression] = useState<string>(expression ?? defaultExpression);
158165
const [draftFrom, setDraftFrom] = useState<string>(from ?? defaultFrom?.toString() ?? '');
@@ -209,7 +216,7 @@ export const useQueryState = (options: UseQueryStateOptions = {}): UseQueryState
209216
draftTimeRange,
210217
draftProfileType,
211218
draftTimeRange,
212-
sumBy
219+
sumByWithViewDefault
213220
);
214221

215222
// Sync draft state with URL state when URL changes externally

0 commit comments

Comments
 (0)