@parca/profile 0.19.138 → 0.19.140

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/GraphTooltipArrow/useGraphTooltipMetaInfo/index.d.ts.map +1 -1
  3. package/dist/GraphTooltipArrow/useGraphTooltipMetaInfo/index.js +11 -13
  4. package/dist/ProfileExplorer/ProfileExplorerCompare.d.ts.map +1 -1
  5. package/dist/ProfileExplorer/ProfileExplorerCompare.js +4 -9
  6. package/dist/ProfileFlameChart/SamplesStrips/index.d.ts +2 -2
  7. package/dist/ProfileFlameChart/SamplesStrips/index.d.ts.map +1 -1
  8. package/dist/ProfileFlameChart/index.d.ts.map +1 -1
  9. package/dist/ProfileFlameChart/index.js +13 -19
  10. package/dist/ProfileFlameGraph/FlameGraphArrow/ContextMenu.d.ts.map +1 -1
  11. package/dist/ProfileFlameGraph/FlameGraphArrow/ContextMenu.js +8 -8
  12. package/dist/ProfileFlameGraph/FlameGraphArrow/TextWithEllipsis.d.ts.map +1 -1
  13. package/dist/ProfileFlameGraph/FlameGraphArrow/TextWithEllipsis.js +4 -3
  14. package/dist/ProfileFlameGraph/index.d.ts.map +1 -1
  15. package/dist/ProfileFlameGraph/index.js +6 -4
  16. package/dist/ProfileMetricsGraph/index.d.ts.map +1 -1
  17. package/dist/ProfileMetricsGraph/index.js +4 -6
  18. package/dist/ProfileSelector/MetricsGraphSection.d.ts.map +1 -1
  19. package/dist/ProfileSelector/MetricsGraphSection.js +5 -10
  20. package/dist/ProfileSelector/index.d.ts.map +1 -1
  21. package/dist/ProfileSelector/index.js +27 -25
  22. package/dist/ProfileSelector/useAutoQuerySelector.d.ts.map +1 -1
  23. package/dist/ProfileSelector/useAutoQuerySelector.js +3 -0
  24. package/dist/ProfileTypeSelector/index.d.ts.map +1 -1
  25. package/dist/ProfileTypeSelector/index.js +4 -0
  26. package/dist/ProfileView/components/ActionButtons/SortByDropdown.d.ts.map +1 -1
  27. package/dist/ProfileView/components/ActionButtons/SortByDropdown.js +5 -5
  28. package/dist/ProfileView/components/ColorStackLegend.d.ts.map +1 -1
  29. package/dist/ProfileView/components/ColorStackLegend.js +2 -3
  30. package/dist/ProfileView/components/InvertCallStack/index.d.ts.map +1 -1
  31. package/dist/ProfileView/components/InvertCallStack/index.js +5 -4
  32. package/dist/ProfileView/components/ProfileFilters/useProfileFiltersUrlState.d.ts +1 -2
  33. package/dist/ProfileView/components/ProfileFilters/useProfileFiltersUrlState.d.ts.map +1 -1
  34. package/dist/ProfileView/components/ProfileFilters/useProfileFiltersUrlState.js +14 -16
  35. package/dist/ProfileView/components/ProfileFilters/useProfileFiltersUrlState.test.js +84 -170
  36. package/dist/ProfileView/components/Toolbars/MultiLevelDropdown.d.ts.map +1 -1
  37. package/dist/ProfileView/components/Toolbars/MultiLevelDropdown.js +16 -20
  38. package/dist/ProfileView/components/Toolbars/TableColumnsDropdown.d.ts.map +1 -1
  39. package/dist/ProfileView/components/Toolbars/TableColumnsDropdown.js +4 -5
  40. package/dist/ProfileView/components/Toolbars/index.d.ts +2 -2
  41. package/dist/ProfileView/components/Toolbars/index.d.ts.map +1 -1
  42. package/dist/ProfileView/components/Toolbars/index.js +1 -1
  43. package/dist/ProfileView/components/ViewSelector/index.d.ts.map +1 -1
  44. package/dist/ProfileView/components/ViewSelector/index.js +8 -14
  45. package/dist/ProfileView/context/DashboardContext.d.ts.map +1 -1
  46. package/dist/ProfileView/context/DashboardContext.js +6 -6
  47. package/dist/ProfileView/hooks/useResetFlameGraphState.d.ts.map +1 -1
  48. package/dist/ProfileView/hooks/useResetFlameGraphState.js +5 -4
  49. package/dist/ProfileView/hooks/useResetStateOnProfileTypeChange.d.ts.map +1 -1
  50. package/dist/ProfileView/hooks/useResetStateOnProfileTypeChange.js +25 -26
  51. package/dist/ProfileView/hooks/useResetStateOnSeriesChange.d.ts.map +1 -1
  52. package/dist/ProfileView/hooks/useResetStateOnSeriesChange.js +13 -8
  53. package/dist/ProfileView/hooks/useVisualizationState.d.ts +3 -3
  54. package/dist/ProfileView/hooks/useVisualizationState.d.ts.map +1 -1
  55. package/dist/ProfileView/hooks/useVisualizationState.js +35 -51
  56. package/dist/ProfileViewWithData.d.ts.map +1 -1
  57. package/dist/ProfileViewWithData.js +19 -28
  58. package/dist/Sandwich/index.d.ts.map +1 -1
  59. package/dist/Sandwich/index.js +4 -3
  60. package/dist/SourceView/index.d.ts.map +1 -1
  61. package/dist/SourceView/index.js +4 -2
  62. package/dist/SourceView/useSelectedLineRange.d.ts.map +1 -1
  63. package/dist/SourceView/useSelectedLineRange.js +21 -16
  64. package/dist/Table/MoreDropdown.d.ts.map +1 -1
  65. package/dist/Table/MoreDropdown.js +8 -11
  66. package/dist/Table/TableContextMenu.d.ts.map +1 -1
  67. package/dist/Table/TableContextMenu.js +10 -13
  68. package/dist/Table/hooks/useTableConfiguration.d.ts.map +1 -1
  69. package/dist/Table/hooks/useTableConfiguration.js +3 -4
  70. package/dist/Table/index.d.ts.map +1 -1
  71. package/dist/Table/index.js +11 -9
  72. package/dist/TopTable/index.d.ts.map +1 -1
  73. package/dist/TopTable/index.js +3 -4
  74. package/dist/hooks/urlParsers.d.ts +18 -0
  75. package/dist/hooks/urlParsers.d.ts.map +1 -0
  76. package/dist/hooks/urlParsers.js +32 -0
  77. package/dist/hooks/useColorBy.d.ts +5 -0
  78. package/dist/hooks/useColorBy.d.ts.map +1 -0
  79. package/dist/hooks/useColorBy.js +26 -0
  80. package/dist/hooks/useCompareModeMeta.d.ts.map +1 -1
  81. package/dist/hooks/useCompareModeMeta.js +55 -86
  82. package/dist/hooks/useDashboardItems.d.ts +5 -0
  83. package/dist/hooks/useDashboardItems.d.ts.map +1 -0
  84. package/dist/hooks/useDashboardItems.js +27 -0
  85. package/dist/hooks/useQueryState.d.ts +3 -3
  86. package/dist/hooks/useQueryState.d.ts.map +1 -1
  87. package/dist/hooks/useQueryState.js +105 -105
  88. package/dist/hooks/useQueryState.test.js +186 -302
  89. package/dist/index.d.ts +3 -2
  90. package/dist/index.d.ts.map +1 -1
  91. package/dist/index.js +3 -12
  92. package/dist/useSumBy.d.ts +1 -1
  93. package/dist/useSumBy.d.ts.map +1 -1
  94. package/dist/useSumBy.js +2 -2
  95. package/package.json +12 -11
  96. package/src/GraphTooltipArrow/useGraphTooltipMetaInfo/index.ts +11 -13
  97. package/src/ProfileExplorer/ProfileExplorerCompare.tsx +4 -9
  98. package/src/ProfileFlameChart/SamplesStrips/index.tsx +2 -2
  99. package/src/ProfileFlameChart/index.tsx +21 -28
  100. package/src/ProfileFlameGraph/FlameGraphArrow/ContextMenu.tsx +10 -9
  101. package/src/ProfileFlameGraph/FlameGraphArrow/TextWithEllipsis.tsx +5 -3
  102. package/src/ProfileFlameGraph/index.tsx +6 -9
  103. package/src/ProfileMetricsGraph/index.tsx +6 -8
  104. package/src/ProfileSelector/MetricsGraphSection.tsx +5 -10
  105. package/src/ProfileSelector/index.tsx +32 -31
  106. package/src/ProfileSelector/useAutoQuerySelector.ts +5 -0
  107. package/src/ProfileTypeSelector/index.tsx +4 -0
  108. package/src/ProfileView/components/ActionButtons/SortByDropdown.tsx +10 -6
  109. package/src/ProfileView/components/ColorStackLegend.tsx +2 -4
  110. package/src/ProfileView/components/InvertCallStack/index.tsx +5 -4
  111. package/src/ProfileView/components/ProfileFilters/useProfileFiltersUrlState.test.tsx +94 -192
  112. package/src/ProfileView/components/ProfileFilters/useProfileFiltersUrlState.ts +21 -21
  113. package/src/ProfileView/components/Toolbars/MultiLevelDropdown.tsx +24 -25
  114. package/src/ProfileView/components/Toolbars/TableColumnsDropdown.tsx +4 -5
  115. package/src/ProfileView/components/Toolbars/index.tsx +3 -3
  116. package/src/ProfileView/components/ViewSelector/index.tsx +9 -16
  117. package/src/ProfileView/context/DashboardContext.tsx +6 -6
  118. package/src/ProfileView/hooks/useResetFlameGraphState.ts +6 -4
  119. package/src/ProfileView/hooks/useResetStateOnProfileTypeChange.ts +24 -26
  120. package/src/ProfileView/hooks/useResetStateOnSeriesChange.ts +16 -8
  121. package/src/ProfileView/hooks/useVisualizationState.ts +61 -69
  122. package/src/ProfileViewWithData.tsx +29 -35
  123. package/src/Sandwich/index.tsx +4 -3
  124. package/src/SourceView/index.tsx +4 -2
  125. package/src/SourceView/useSelectedLineRange.ts +34 -19
  126. package/src/Table/MoreDropdown.tsx +9 -11
  127. package/src/Table/TableContextMenu.tsx +10 -13
  128. package/src/Table/hooks/useTableConfiguration.tsx +3 -4
  129. package/src/Table/index.tsx +12 -21
  130. package/src/TopTable/index.tsx +3 -4
  131. package/src/hooks/urlParsers.ts +38 -0
  132. package/src/hooks/useColorBy.ts +42 -0
  133. package/src/hooks/useCompareModeMeta.ts +61 -91
  134. package/src/hooks/useDashboardItems.ts +46 -0
  135. package/src/hooks/useQueryState.test.tsx +275 -345
  136. package/src/hooks/useQueryState.ts +136 -118
  137. package/src/index.tsx +16 -15
  138. package/src/useSumBy.ts +3 -3
@@ -11,100 +11,69 @@
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
13
  import { useCallback } from 'react';
14
- import { useURLState, useURLStateBatch } from '@parca/components';
14
+ import { useQueryStates } from 'nuqs';
15
+ import { boolParam, stringParam } from './urlParsers';
15
16
  /**
16
17
  * Hook to manage compare mode state and operations
17
18
  * Returns compare mode flags and a function to close compare mode
18
19
  */
19
20
  export const useCompareModeMeta = () => {
20
- const batchUpdates = useURLStateBatch();
21
- // Side A URL state (only setters needed)
22
- const [, setExpressionA] = useURLState('expression_a');
23
- const [, setFromA] = useURLState('from_a');
24
- const [, setToA] = useURLState('to_a');
25
- const [, setTimeSelectionA] = useURLState('time_selection_a');
26
- const [, setSumByA] = useURLState('sum_by_a');
27
- const [, setMergeFromA] = useURLState('merge_from_a');
28
- const [, setMergeToA] = useURLState('merge_to_a');
29
- const [, setSelectionA] = useURLState('selection_a');
30
- // Side B URL state
31
- const [expressionB, setExpressionB] = useURLState('expression_b');
32
- const [fromB, setFromB] = useURLState('from_b');
33
- const [toB, setToB] = useURLState('to_b');
34
- const [timeSelectionB, setTimeSelectionB] = useURLState('time_selection_b');
35
- const [sumByB, setSumByB] = useURLState('sum_by_b');
36
- const [mergeFromB, setMergeFromB] = useURLState('merge_from_b');
37
- const [mergeToB, setMergeToB] = useURLState('merge_to_b');
38
- const [selectionB, setSelectionB] = useURLState('selection_b');
39
- // Compare mode flags (expose values for routing decisions)
40
- const [compareA, setCompareA] = useURLState('compare_a');
41
- const [compareB, setCompareB] = useURLState('compare_b');
42
- const [compareAbsolute, setCompareAbsolute] = useURLState('compare_absolute');
21
+ const [state, setState] = useQueryStates({
22
+ // Side A
23
+ expression_a: stringParam,
24
+ from_a: stringParam,
25
+ to_a: stringParam,
26
+ time_selection_a: stringParam,
27
+ sum_by_a: stringParam,
28
+ merge_from_a: stringParam,
29
+ merge_to_a: stringParam,
30
+ selection_a: stringParam,
31
+ // Side B
32
+ expression_b: stringParam,
33
+ from_b: stringParam,
34
+ to_b: stringParam,
35
+ time_selection_b: stringParam,
36
+ sum_by_b: stringParam,
37
+ merge_from_b: stringParam,
38
+ merge_to_b: stringParam,
39
+ selection_b: stringParam,
40
+ // Compare flags
41
+ compare_a: boolParam,
42
+ compare_b: boolParam,
43
+ compare_absolute: boolParam,
44
+ }, { history: 'replace' });
43
45
  const closeCompareMode = useCallback((side) => {
44
- batchUpdates(() => {
45
- // If closing side A, swap A and B params first (keep B's data as the single view)
46
- if (side === 'A') {
47
- // Copy B to A
48
- setExpressionA(expressionB);
49
- setFromA(fromB);
50
- setToA(toB);
51
- setTimeSelectionA(timeSelectionB);
52
- setSumByA(sumByB);
53
- setMergeFromA(mergeFromB);
54
- setMergeToA(mergeToB);
55
- setSelectionA(selectionB);
46
+ // If closing side A, swap B → A first (keep B's data as the single view)
47
+ const swapAFromB = side === 'A'
48
+ ? {
49
+ expression_a: state.expression_b,
50
+ from_a: state.from_b,
51
+ to_a: state.to_b,
52
+ time_selection_a: state.time_selection_b,
53
+ sum_by_a: state.sum_by_b,
54
+ merge_from_a: state.merge_from_b,
55
+ merge_to_a: state.merge_to_b,
56
+ selection_a: state.selection_b,
56
57
  }
57
- // Clear all B params
58
- setExpressionB(undefined);
59
- setFromB(undefined);
60
- setToB(undefined);
61
- setTimeSelectionB(undefined);
62
- setSumByB(undefined);
63
- setMergeFromB(undefined);
64
- setMergeToB(undefined);
65
- setSelectionB(undefined);
66
- // Clear compare mode flags
67
- setCompareA(undefined);
68
- setCompareB(undefined);
69
- setCompareAbsolute(undefined);
58
+ : {};
59
+ // Atomic update: swap A (if needed), clear all B params and compare flags
60
+ void setState({
61
+ ...swapAFromB,
62
+ expression_b: null,
63
+ from_b: null,
64
+ to_b: null,
65
+ time_selection_b: null,
66
+ sum_by_b: null,
67
+ merge_from_b: null,
68
+ merge_to_b: null,
69
+ selection_b: null,
70
+ compare_a: null,
71
+ compare_b: null,
72
+ compare_absolute: null,
70
73
  });
71
- }, [
72
- batchUpdates,
73
- // Side A setters
74
- setExpressionA,
75
- setFromA,
76
- setToA,
77
- setTimeSelectionA,
78
- setSumByA,
79
- setMergeFromA,
80
- setMergeToA,
81
- setSelectionA,
82
- // Side B values (for swapping)
83
- expressionB,
84
- fromB,
85
- toB,
86
- timeSelectionB,
87
- sumByB,
88
- mergeFromB,
89
- mergeToB,
90
- selectionB,
91
- // Side B setters
92
- setExpressionB,
93
- setFromB,
94
- setToB,
95
- setTimeSelectionB,
96
- setSumByB,
97
- setMergeFromB,
98
- setMergeToB,
99
- setSelectionB,
100
- // Compare flags
101
- setCompareA,
102
- setCompareB,
103
- setCompareAbsolute,
104
- ]);
105
- // Derive isCompareMode from flags
106
- const isCompareMode = compareA === 'true' || compareB === 'true';
107
- const isCompareAbsolute = compareAbsolute === 'true';
74
+ }, [state, setState]);
75
+ const isCompareMode = state.compare_a === true || state.compare_b === true;
76
+ const isCompareAbsolute = state.compare_absolute === true;
108
77
  return {
109
78
  isCompareMode,
110
79
  isCompareAbsolute,
@@ -0,0 +1,5 @@
1
+ export declare const useDashboardItems: () => {
2
+ dashboardItems: string[];
3
+ setDashboardItems: (items: string[]) => void;
4
+ };
5
+ //# sourceMappingURL=useDashboardItems.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDashboardItems.d.ts","sourceRoot":"","sources":["../../src/hooks/useDashboardItems.ts"],"names":[],"mappings":"AAqBA,eAAO,MAAM,iBAAiB,QAAO;IACnC,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,iBAAiB,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;CAsB9C,CAAC"}
@@ -0,0 +1,27 @@
1
+ // Copyright 2022 The Parca Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ import { useCallback, useMemo } from 'react';
14
+ import { parseAsArrayOf, parseAsString, useQueryState } from 'nuqs';
15
+ import { useParcaContext } from '@parca/components';
16
+ const opts = { history: 'replace' };
17
+ export const useDashboardItems = () => {
18
+ const { defaultDashboardItems } = useParcaContext();
19
+ const parser = useMemo(() => parseAsArrayOf(parseAsString, ',')
20
+ .withDefault(defaultDashboardItems ?? ['flamegraph'])
21
+ .withOptions(opts), [defaultDashboardItems]);
22
+ const [dashboardItems, setRawDashboardItems] = useQueryState('dashboard_items', parser);
23
+ const setDashboardItems = useCallback((items) => {
24
+ void setRawDashboardItems(items);
25
+ }, [setRawDashboardItems]);
26
+ return { dashboardItems, setDashboardItems };
27
+ };
@@ -29,9 +29,9 @@ interface UseQueryStateReturn {
29
29
  sumByLoading: boolean;
30
30
  draftParsedQuery: Query | null;
31
31
  parsedQuery: Query | null;
32
- setExpressionParam: (value: string | undefined) => void;
33
- setSumByParam: (value: string | undefined) => void;
34
- setGroupByParam: (value: string[] | undefined) => void;
32
+ setExpressionParam: (value: string | null) => void;
33
+ setSumByParam: (value: string | null) => void;
34
+ setGroupByParam: (value: string[] | null) => void;
35
35
  }
36
36
  export declare const useQueryState: (options?: UseQueryStateOptions) => UseQueryStateReturn;
37
37
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"useQueryState.d.ts","sourceRoot":"","sources":["../../src/hooks/useQueryState.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAC,KAAK,EAAC,MAAM,eAAe,CAAC;AAEpC,OAAO,EAAC,cAAc,EAAC,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAC,gBAAgB,EAA8B,aAAa,EAAC,MAAM,kBAAkB,CAAC;AAK7F,UAAU,oBAAoB;IAC5B,MAAM,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;IACrB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,mBAAmB,CAAC,EAAE,MAAM,IAAI,CAAC;CAClC;AAED,UAAU,mBAAmB;IAE3B,cAAc,EAAE,cAAc,CAAC;IAG/B,cAAc,EAAE,cAAc,CAAC;IAG/B,kBAAkB,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;IACjD,iBAAiB,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7E,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,SAAS,KAAK,IAAI,CAAC;IACrD,mBAAmB,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,IAAI,CAAC;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M,GAAG,IAAI,KAAK,IAAI,CAAC;IAC9C,eAAe,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,KAAK,IAAI,CAAC;CACnD;AAED,eAAO,MAAM,aAAa,GAAI,UAAS,oBAAyB,KAAG,mBA0blE,CAAC"}
@@ -11,42 +11,60 @@
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
13
  import { useCallback, useEffect, useMemo, useState } from 'react';
14
- import { DateTimeRange, useParcaContext, useURLState, useURLStateBatch } from '@parca/components';
14
+ import { useQueryState as useNuqsQueryState, useQueryStates } from 'nuqs';
15
+ import { DateTimeRange, useParcaContext } from '@parca/components';
15
16
  import { Query } from '@parca/parser';
16
17
  import { ProfileSelectionFromParams } from '../ProfileSource';
17
18
  import { useResetFlameGraphState } from '../ProfileView/hooks/useResetFlameGraphState';
18
19
  import { useResetStateOnProfileTypeChange } from '../ProfileView/hooks/useResetStateOnProfileTypeChange';
19
20
  import { DEFAULT_EMPTY_SUM_BY, sumByToParam, useSumBy, useSumByFromParams } from '../useSumBy';
21
+ import { commaArrayParam, stringParam } from './urlParsers';
20
22
  export const useQueryState = (options = {}) => {
21
23
  const { queryServiceClient: queryClient } = useParcaContext();
22
24
  const { suffix = '', defaultExpression = '', defaultTimeSelection = 'relative:minute|15', // Default to 15 minutes relative
23
25
  defaultFrom, defaultTo, comparing = false, onProfileTypeChange, } = options;
24
- const batchUpdates = useURLStateBatch();
25
26
  const resetFlameGraphState = useResetFlameGraphState();
26
27
  const resetStateOnProfileTypeChange = useResetStateOnProfileTypeChange();
27
- // URL state hooks with appropriate suffixes
28
- const [expression, setExpressionState] = useURLState(`expression${suffix}`, {
29
- defaultValue: defaultExpression,
28
+ // URL state hooks with appropriate suffixes via useQueryStates
29
+ const [queryParams, setQueryParams] = useQueryStates({
30
+ expression: stringParam,
31
+ from: stringParam,
32
+ to: stringParam,
33
+ time_selection: stringParam,
34
+ sum_by: stringParam,
35
+ merge_from: stringParam,
36
+ merge_to: stringParam,
37
+ selection: stringParam,
38
+ }, {
39
+ history: 'replace',
40
+ urlKeys: {
41
+ expression: `expression${suffix}`,
42
+ from: `from${suffix}`,
43
+ to: `to${suffix}`,
44
+ time_selection: `time_selection${suffix}`,
45
+ sum_by: `sum_by${suffix}`,
46
+ merge_from: `merge_from${suffix}`,
47
+ merge_to: `merge_to${suffix}`,
48
+ selection: `selection${suffix}`,
49
+ },
30
50
  });
31
- const [from, setFromState] = useURLState(`from${suffix}`, {
32
- defaultValue: defaultFrom?.toString(),
33
- });
34
- const [to, setToState] = useURLState(`to${suffix}`, {
35
- defaultValue: defaultTo?.toString(),
36
- });
37
- const [timeSelection, setTimeSelectionState] = useURLState(`time_selection${suffix}`, {
38
- defaultValue: defaultTimeSelection,
39
- });
40
- const [sumByParam, setSumByParam] = useURLState(`sum_by${suffix}`);
41
- const [, setGroupByParam] = useURLState('group_by', {
42
- alwaysReturnArray: true,
43
- });
44
- const [mergeFrom, setMergeFromState] = useURLState(`merge_from${suffix}`);
45
- const [mergeTo, setMergeToState] = useURLState(`merge_to${suffix}`);
46
- // ProfileSelection URL state hooks - reuses merge_from/merge_to but adds selection
47
- const [selectionParam, setSelectionParam] = useURLState(`selection${suffix}`);
51
+ const expression = queryParams.expression ?? defaultExpression;
52
+ const from = queryParams.from ?? defaultFrom?.toString();
53
+ const to = queryParams.to ?? defaultTo?.toString();
54
+ const timeSelection = queryParams.time_selection ?? defaultTimeSelection;
55
+ const sumByParam = queryParams.sum_by;
56
+ const mergeFrom = queryParams.merge_from;
57
+ const mergeTo = queryParams.merge_to;
58
+ const selectionParam = queryParams.selection;
59
+ // Individual setters for direct access
60
+ const setExpressionState = useCallback((val) => void setQueryParams({ expression: val }), [setQueryParams]);
61
+ const setSumByParam = useCallback((val) => void setQueryParams({ sum_by: val }), [setQueryParams]);
62
+ const [, setRawGroupByParam] = useNuqsQueryState('group_by', commaArrayParam);
63
+ const setGroupByParam = useCallback((val) => {
64
+ void setRawGroupByParam(val);
65
+ }, [setRawGroupByParam]);
48
66
  // Parse sumBy from URL parameter format
49
- const sumBy = useSumByFromParams(sumByParam);
67
+ const sumBy = useSumByFromParams(sumByParam ?? undefined);
50
68
  // Draft state management
51
69
  const [draftExpression, setDraftExpression] = useState(expression ?? defaultExpression);
52
70
  const [draftFrom, setDraftFrom] = useState(from ?? defaultFrom?.toString() ?? '');
@@ -105,20 +123,20 @@ export const useQueryState = (options = {}) => {
105
123
  // Sync computed sumBy to URL if URL doesn't already have a value
106
124
  // to ensure the shared URL can always pick it up.
107
125
  useEffect(() => {
108
- if (sumByParam === undefined && computedSumByFromURL !== undefined && !sumBySelectionLoading) {
109
- setSumByParam(sumByToParam(computedSumByFromURL));
126
+ if (sumByParam === null && computedSumByFromURL !== undefined && !sumBySelectionLoading) {
127
+ void setSumByParam(sumByToParam(computedSumByFromURL));
110
128
  }
111
129
  }, [sumByParam, computedSumByFromURL, sumBySelectionLoading, setSumByParam]);
112
130
  // Construct the QuerySelection object (committed state from URL)
113
131
  const querySelection = useMemo(() => {
114
- const range = DateTimeRange.fromRangeKey(timeSelection ?? defaultTimeSelection, from !== undefined && from !== '' ? parseInt(from) : defaultFrom, to !== undefined && to !== '' ? parseInt(to) : defaultTo);
132
+ const range = DateTimeRange.fromRangeKey(timeSelection ?? defaultTimeSelection, from != null && from !== '' ? parseInt(from) : defaultFrom, to != null && to !== '' ? parseInt(to) : defaultTo);
115
133
  return {
116
134
  expression: expression ?? defaultExpression,
117
135
  from: range.getFromMs(),
118
136
  to: range.getToMs(),
119
137
  timeSelection: range.getRangeKey(),
120
138
  sumBy: computedSumByFromURL,
121
- ...(mergeFrom !== undefined && mergeFrom !== '' && mergeTo !== undefined && mergeTo !== ''
139
+ ...(mergeFrom != null && mergeFrom !== '' && mergeTo != null && mergeTo !== ''
122
140
  ? { mergeFrom, mergeTo }
123
141
  : {}),
124
142
  };
@@ -168,7 +186,7 @@ export const useQueryState = (options = {}) => {
168
186
  ]);
169
187
  // Compute ProfileSelection from URL params
170
188
  const profileSelection = useMemo(() => {
171
- return ProfileSelectionFromParams(mergeFrom, mergeTo, selectionParam);
189
+ return ProfileSelectionFromParams(mergeFrom ?? undefined, mergeTo ?? undefined, selectionParam ?? undefined);
172
190
  }, [mergeFrom, mergeTo, selectionParam]);
173
191
  // Compute ProfileSource from ProfileSelection
174
192
  const profileSource = useMemo(() => {
@@ -181,73 +199,62 @@ export const useQueryState = (options = {}) => {
181
199
  // to the current moment when the Search button is clicked
182
200
  // Optional expression parameter allows updating the expression before committing
183
201
  const commitDraft = useCallback((refreshedTimeRange, expression) => {
184
- batchUpdates(() => {
185
- // Use provided expression or current draft expression
186
- const finalExpression = expression ?? draftExpression;
187
- // Update draft state with new expression if provided
188
- if (expression !== undefined) {
189
- setDraftExpression(expression);
190
- }
191
- // Calculate the actual from/to values from draftSelection if not provided
192
- const calculatedFrom = draftSelection.from.toString();
193
- const calculatedTo = draftSelection.to.toString();
194
- const finalFrom = refreshedTimeRange?.from?.toString() ?? (draftFrom !== '' ? draftFrom : calculatedFrom);
195
- const finalTo = refreshedTimeRange?.to?.toString() ?? (draftTo !== '' ? draftTo : calculatedTo);
196
- const finalTimeSelection = refreshedTimeRange?.timeSelection ?? draftTimeSelection;
197
- // Update draft state with refreshed time range if provided
198
- if (refreshedTimeRange?.from !== undefined) {
199
- setDraftFrom(finalFrom);
200
- }
201
- if (refreshedTimeRange?.to !== undefined) {
202
- setDraftTo(finalTo);
203
- }
204
- if (refreshedTimeRange?.timeSelection !== undefined) {
205
- setDraftTimeSelection(finalTimeSelection);
206
- }
207
- setExpressionState(finalExpression);
208
- setFromState(finalFrom);
209
- setToState(finalTo);
210
- setTimeSelectionState(finalTimeSelection);
211
- // Auto-calculate merge parameters for delta profiles
212
- // Parse the final expression to check if it's a delta profile
213
- const finalQuery = Query.parse(finalExpression);
214
- const isDelta = finalQuery.profileType().delta;
215
- if (isDelta) {
216
- setSumByParam(sumByToParam(draftSumBy));
217
- }
218
- else {
219
- setSumByParam(DEFAULT_EMPTY_SUM_BY);
220
- }
221
- if (isDelta && finalFrom !== '' && finalTo !== '') {
222
- const fromMs = parseInt(finalFrom);
223
- const toMs = parseInt(finalTo);
224
- setMergeFromState((BigInt(fromMs) * 1000000n).toString());
225
- setMergeToState((BigInt(toMs) * 1000000n).toString());
226
- // Auto-select the time range for delta profiles (but not in compare mode)
227
- // This applies both on initial load AND when Search is clicked
228
- // The selection will use the final expression and the updated time range
229
- if (!comparing) {
230
- setSelectionParam(finalExpression);
231
- }
232
- else {
233
- setSelectionParam(undefined);
234
- }
235
- }
236
- else {
237
- setMergeFromState(undefined);
238
- setMergeToState(undefined);
239
- // Clear ProfileSelection for non-delta profiles
240
- setSelectionParam(undefined);
241
- }
242
- resetFlameGraphState();
243
- if (draftProfileType.toString() !==
244
- Query.parse(querySelection.expression).profileType().toString()) {
245
- resetStateOnProfileTypeChange();
246
- onProfileTypeChange?.();
202
+ // Use provided expression or current draft expression
203
+ const finalExpression = expression ?? draftExpression;
204
+ // Update draft state with new expression if provided
205
+ if (expression !== undefined) {
206
+ setDraftExpression(expression);
207
+ }
208
+ // Calculate the actual from/to values from draftSelection if not provided
209
+ const calculatedFrom = draftSelection.from.toString();
210
+ const calculatedTo = draftSelection.to.toString();
211
+ const finalFrom = refreshedTimeRange?.from?.toString() ?? (draftFrom !== '' ? draftFrom : calculatedFrom);
212
+ const finalTo = refreshedTimeRange?.to?.toString() ?? (draftTo !== '' ? draftTo : calculatedTo);
213
+ const finalTimeSelection = refreshedTimeRange?.timeSelection ?? draftTimeSelection;
214
+ // Update draft state with refreshed time range if provided
215
+ if (refreshedTimeRange?.from !== undefined) {
216
+ setDraftFrom(finalFrom);
217
+ }
218
+ if (refreshedTimeRange?.to !== undefined) {
219
+ setDraftTo(finalTo);
220
+ }
221
+ if (refreshedTimeRange?.timeSelection !== undefined) {
222
+ setDraftTimeSelection(finalTimeSelection);
223
+ }
224
+ // Auto-calculate merge parameters for delta profiles
225
+ const finalQuery = Query.parse(finalExpression);
226
+ const isDelta = finalQuery.profileType().delta;
227
+ const sumByValue = isDelta ? sumByToParam(draftSumBy) : sumByToParam(DEFAULT_EMPTY_SUM_BY);
228
+ let mergeFromValue = null;
229
+ let mergeToValue = null;
230
+ let selectionValue = null;
231
+ if (isDelta && finalFrom !== '' && finalTo !== '') {
232
+ const fromMs = parseInt(finalFrom);
233
+ const toMs = parseInt(finalTo);
234
+ mergeFromValue = (BigInt(fromMs) * 1000000n).toString();
235
+ mergeToValue = (BigInt(toMs) * 1000000n).toString();
236
+ if (!comparing) {
237
+ selectionValue = finalExpression;
247
238
  }
239
+ }
240
+ // Atomic URL update with all params at once
241
+ void setQueryParams({
242
+ expression: finalExpression,
243
+ from: finalFrom,
244
+ to: finalTo,
245
+ time_selection: finalTimeSelection,
246
+ sum_by: sumByValue,
247
+ merge_from: mergeFromValue,
248
+ merge_to: mergeToValue,
249
+ selection: selectionValue,
248
250
  });
251
+ resetFlameGraphState();
252
+ if (draftProfileType.toString() !==
253
+ Query.parse(querySelection.expression).profileType().toString()) {
254
+ resetStateOnProfileTypeChange();
255
+ onProfileTypeChange?.();
256
+ }
249
257
  }, [
250
- batchUpdates,
251
258
  draftExpression,
252
259
  draftFrom,
253
260
  draftTo,
@@ -256,14 +263,7 @@ export const useQueryState = (options = {}) => {
256
263
  draftSelection.from,
257
264
  draftSelection.to,
258
265
  comparing,
259
- setExpressionState,
260
- setFromState,
261
- setToState,
262
- setTimeSelectionState,
263
- setSumByParam,
264
- setMergeFromState,
265
- setMergeToState,
266
- setSelectionParam,
266
+ setQueryParams,
267
267
  resetFlameGraphState,
268
268
  resetStateOnProfileTypeChange,
269
269
  onProfileTypeChange,
@@ -293,12 +293,12 @@ export const useQueryState = (options = {}) => {
293
293
  }, [draftProfileName]);
294
294
  // Set ProfileSelection (auto-commits to URL immediately)
295
295
  const setProfileSelection = useCallback((mergeFrom, mergeTo, query) => {
296
- batchUpdates(() => {
297
- setSelectionParam(query.toString());
298
- setMergeFromState(mergeFrom.toString());
299
- setMergeToState(mergeTo.toString());
296
+ void setQueryParams({
297
+ selection: query.toString(),
298
+ merge_from: mergeFrom.toString(),
299
+ merge_to: mergeTo.toString(),
300
300
  });
301
- }, [batchUpdates, setSelectionParam, setMergeFromState, setMergeToState]);
301
+ }, [setQueryParams]);
302
302
  const draftParsedQuery = useMemo(() => {
303
303
  try {
304
304
  return Query.parse(draftSelection.expression ?? '');