MCPcopy Index your code
hub / github.com/parca-dev/parca / useQueryState

Function useQueryState

ui/packages/shared/profile/src/hooks/useQueryState.ts:81–535  ·  view source on GitHub ↗
(options: UseQueryStateOptions = {})

Source from the content-addressed store, hash-verified

79}
80
81export const useQueryState = (options: UseQueryStateOptions = {}): UseQueryStateReturn => {
82 const {queryServiceClient: queryClient} = useParcaContext();
83 const {
84 suffix = '',
85 defaultExpression = '',
86 defaultTimeSelection = 'relative:minute|15', // Default to 15 minutes relative
87 defaultFrom,
88 defaultTo,
89 comparing = false,
90 onProfileTypeChange,
91 } = options;
92
93 const resetFlameGraphState = useResetFlameGraphState();
94 const resetStateOnProfileTypeChange = useResetStateOnProfileTypeChange();
95
96 // URL state hooks with appropriate suffixes via useQueryStates
97 const [queryParams, setQueryParams] = useQueryStates(
98 {
99 expression: stringParam,
100 from: stringParam,
101 to: stringParam,
102 time_selection: stringParam,
103 sum_by: stringParam,
104 merge_from: stringParam,
105 merge_to: stringParam,
106 selection: stringParam,
107 },
108 {
109 history: 'replace',
110 urlKeys: {
111 expression: `expression${suffix}`,
112 from: `from${suffix}`,
113 to: `to${suffix}`,
114 time_selection: `time_selection${suffix}`,
115 sum_by: `sum_by${suffix}`,
116 merge_from: `merge_from${suffix}`,
117 merge_to: `merge_to${suffix}`,
118 selection: `selection${suffix}`,
119 },
120 }
121 );
122
123 const expression = queryParams.expression ?? defaultExpression;
124 const from = queryParams.from ?? defaultFrom?.toString();
125 const to = queryParams.to ?? defaultTo?.toString();
126 const timeSelection = queryParams.time_selection ?? defaultTimeSelection;
127 const sumByParam = queryParams.sum_by;
128 const mergeFrom = queryParams.merge_from;
129 const mergeTo = queryParams.merge_to;
130 const selectionParam = queryParams.selection;
131
132 // Individual setters for direct access
133 const setExpressionState = useCallback(
134 (val: string | null) => void setQueryParams({expression: val}),
135 [setQueryParams]
136 );
137 const setSumByParam = useCallback(
138 (val: string | null) => void setQueryParams({sum_by: val}),

Callers 15

PreSelectedMatchersFunction · 0.90
ProfileSelectorFunction · 0.90
ProfileExplorerCompareFunction · 0.90
ProfileExplorerSingleFunction · 0.90
TestComponentFunction · 0.90
ProfileViewWithDataFunction · 0.85
TableContextMenuFunction · 0.85
MoreDropdownFunction · 0.85
index.tsxFile · 0.85
useTableConfigurationFunction · 0.85
InvertCallStackFunction · 0.85

Calls 15

useParcaContextFunction · 0.90
useResetFlameGraphStateFunction · 0.90
useSumByFromParamsFunction · 0.90
useSumByFunction · 0.90
sumByToParamFunction · 0.90
parseMethod · 0.80
profileTypeMethod · 0.80
profileNameMethod · 0.80
fromRangeKeyMethod · 0.80
getFromMsMethod · 0.80

Tested by 1

TestComponentFunction · 0.72