@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.
- package/CHANGELOG.md +10 -0
- package/dist/GraphTooltipArrow/useGraphTooltipMetaInfo/index.d.ts.map +1 -1
- package/dist/GraphTooltipArrow/useGraphTooltipMetaInfo/index.js +11 -13
- package/dist/ProfileExplorer/ProfileExplorerCompare.d.ts.map +1 -1
- package/dist/ProfileExplorer/ProfileExplorerCompare.js +4 -9
- package/dist/ProfileFlameChart/SamplesStrips/index.d.ts +2 -2
- package/dist/ProfileFlameChart/SamplesStrips/index.d.ts.map +1 -1
- package/dist/ProfileFlameChart/index.d.ts.map +1 -1
- package/dist/ProfileFlameChart/index.js +13 -19
- package/dist/ProfileFlameGraph/FlameGraphArrow/ContextMenu.d.ts.map +1 -1
- package/dist/ProfileFlameGraph/FlameGraphArrow/ContextMenu.js +8 -8
- package/dist/ProfileFlameGraph/FlameGraphArrow/TextWithEllipsis.d.ts.map +1 -1
- package/dist/ProfileFlameGraph/FlameGraphArrow/TextWithEllipsis.js +4 -3
- package/dist/ProfileFlameGraph/index.d.ts.map +1 -1
- package/dist/ProfileFlameGraph/index.js +6 -4
- package/dist/ProfileMetricsGraph/index.d.ts.map +1 -1
- package/dist/ProfileMetricsGraph/index.js +4 -6
- package/dist/ProfileSelector/MetricsGraphSection.d.ts.map +1 -1
- package/dist/ProfileSelector/MetricsGraphSection.js +5 -10
- package/dist/ProfileSelector/index.d.ts.map +1 -1
- package/dist/ProfileSelector/index.js +27 -25
- package/dist/ProfileSelector/useAutoQuerySelector.d.ts.map +1 -1
- package/dist/ProfileSelector/useAutoQuerySelector.js +3 -0
- package/dist/ProfileTypeSelector/index.d.ts.map +1 -1
- package/dist/ProfileTypeSelector/index.js +4 -0
- package/dist/ProfileView/components/ActionButtons/SortByDropdown.d.ts.map +1 -1
- package/dist/ProfileView/components/ActionButtons/SortByDropdown.js +5 -5
- package/dist/ProfileView/components/ColorStackLegend.d.ts.map +1 -1
- package/dist/ProfileView/components/ColorStackLegend.js +2 -3
- package/dist/ProfileView/components/InvertCallStack/index.d.ts.map +1 -1
- package/dist/ProfileView/components/InvertCallStack/index.js +5 -4
- package/dist/ProfileView/components/ProfileFilters/useProfileFiltersUrlState.d.ts +1 -2
- package/dist/ProfileView/components/ProfileFilters/useProfileFiltersUrlState.d.ts.map +1 -1
- package/dist/ProfileView/components/ProfileFilters/useProfileFiltersUrlState.js +14 -16
- package/dist/ProfileView/components/ProfileFilters/useProfileFiltersUrlState.test.js +84 -170
- package/dist/ProfileView/components/Toolbars/MultiLevelDropdown.d.ts.map +1 -1
- package/dist/ProfileView/components/Toolbars/MultiLevelDropdown.js +16 -20
- package/dist/ProfileView/components/Toolbars/TableColumnsDropdown.d.ts.map +1 -1
- package/dist/ProfileView/components/Toolbars/TableColumnsDropdown.js +4 -5
- package/dist/ProfileView/components/Toolbars/index.d.ts +2 -2
- package/dist/ProfileView/components/Toolbars/index.d.ts.map +1 -1
- package/dist/ProfileView/components/Toolbars/index.js +1 -1
- package/dist/ProfileView/components/ViewSelector/index.d.ts.map +1 -1
- package/dist/ProfileView/components/ViewSelector/index.js +8 -14
- package/dist/ProfileView/context/DashboardContext.d.ts.map +1 -1
- package/dist/ProfileView/context/DashboardContext.js +6 -6
- package/dist/ProfileView/hooks/useResetFlameGraphState.d.ts.map +1 -1
- package/dist/ProfileView/hooks/useResetFlameGraphState.js +5 -4
- package/dist/ProfileView/hooks/useResetStateOnProfileTypeChange.d.ts.map +1 -1
- package/dist/ProfileView/hooks/useResetStateOnProfileTypeChange.js +25 -26
- package/dist/ProfileView/hooks/useResetStateOnSeriesChange.d.ts.map +1 -1
- package/dist/ProfileView/hooks/useResetStateOnSeriesChange.js +13 -8
- package/dist/ProfileView/hooks/useVisualizationState.d.ts +3 -3
- package/dist/ProfileView/hooks/useVisualizationState.d.ts.map +1 -1
- package/dist/ProfileView/hooks/useVisualizationState.js +35 -51
- package/dist/ProfileViewWithData.d.ts.map +1 -1
- package/dist/ProfileViewWithData.js +19 -28
- package/dist/Sandwich/index.d.ts.map +1 -1
- package/dist/Sandwich/index.js +4 -3
- package/dist/SourceView/index.d.ts.map +1 -1
- package/dist/SourceView/index.js +4 -2
- package/dist/SourceView/useSelectedLineRange.d.ts.map +1 -1
- package/dist/SourceView/useSelectedLineRange.js +21 -16
- package/dist/Table/MoreDropdown.d.ts.map +1 -1
- package/dist/Table/MoreDropdown.js +8 -11
- package/dist/Table/TableContextMenu.d.ts.map +1 -1
- package/dist/Table/TableContextMenu.js +10 -13
- package/dist/Table/hooks/useTableConfiguration.d.ts.map +1 -1
- package/dist/Table/hooks/useTableConfiguration.js +3 -4
- package/dist/Table/index.d.ts.map +1 -1
- package/dist/Table/index.js +11 -9
- package/dist/TopTable/index.d.ts.map +1 -1
- package/dist/TopTable/index.js +3 -4
- package/dist/hooks/urlParsers.d.ts +18 -0
- package/dist/hooks/urlParsers.d.ts.map +1 -0
- package/dist/hooks/urlParsers.js +32 -0
- package/dist/hooks/useColorBy.d.ts +5 -0
- package/dist/hooks/useColorBy.d.ts.map +1 -0
- package/dist/hooks/useColorBy.js +26 -0
- package/dist/hooks/useCompareModeMeta.d.ts.map +1 -1
- package/dist/hooks/useCompareModeMeta.js +55 -86
- package/dist/hooks/useDashboardItems.d.ts +5 -0
- package/dist/hooks/useDashboardItems.d.ts.map +1 -0
- package/dist/hooks/useDashboardItems.js +27 -0
- package/dist/hooks/useQueryState.d.ts +3 -3
- package/dist/hooks/useQueryState.d.ts.map +1 -1
- package/dist/hooks/useQueryState.js +105 -105
- package/dist/hooks/useQueryState.test.js +186 -302
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -12
- package/dist/useSumBy.d.ts +1 -1
- package/dist/useSumBy.d.ts.map +1 -1
- package/dist/useSumBy.js +2 -2
- package/package.json +12 -11
- package/src/GraphTooltipArrow/useGraphTooltipMetaInfo/index.ts +11 -13
- package/src/ProfileExplorer/ProfileExplorerCompare.tsx +4 -9
- package/src/ProfileFlameChart/SamplesStrips/index.tsx +2 -2
- package/src/ProfileFlameChart/index.tsx +21 -28
- package/src/ProfileFlameGraph/FlameGraphArrow/ContextMenu.tsx +10 -9
- package/src/ProfileFlameGraph/FlameGraphArrow/TextWithEllipsis.tsx +5 -3
- package/src/ProfileFlameGraph/index.tsx +6 -9
- package/src/ProfileMetricsGraph/index.tsx +6 -8
- package/src/ProfileSelector/MetricsGraphSection.tsx +5 -10
- package/src/ProfileSelector/index.tsx +32 -31
- package/src/ProfileSelector/useAutoQuerySelector.ts +5 -0
- package/src/ProfileTypeSelector/index.tsx +4 -0
- package/src/ProfileView/components/ActionButtons/SortByDropdown.tsx +10 -6
- package/src/ProfileView/components/ColorStackLegend.tsx +2 -4
- package/src/ProfileView/components/InvertCallStack/index.tsx +5 -4
- package/src/ProfileView/components/ProfileFilters/useProfileFiltersUrlState.test.tsx +94 -192
- package/src/ProfileView/components/ProfileFilters/useProfileFiltersUrlState.ts +21 -21
- package/src/ProfileView/components/Toolbars/MultiLevelDropdown.tsx +24 -25
- package/src/ProfileView/components/Toolbars/TableColumnsDropdown.tsx +4 -5
- package/src/ProfileView/components/Toolbars/index.tsx +3 -3
- package/src/ProfileView/components/ViewSelector/index.tsx +9 -16
- package/src/ProfileView/context/DashboardContext.tsx +6 -6
- package/src/ProfileView/hooks/useResetFlameGraphState.ts +6 -4
- package/src/ProfileView/hooks/useResetStateOnProfileTypeChange.ts +24 -26
- package/src/ProfileView/hooks/useResetStateOnSeriesChange.ts +16 -8
- package/src/ProfileView/hooks/useVisualizationState.ts +61 -69
- package/src/ProfileViewWithData.tsx +29 -35
- package/src/Sandwich/index.tsx +4 -3
- package/src/SourceView/index.tsx +4 -2
- package/src/SourceView/useSelectedLineRange.ts +34 -19
- package/src/Table/MoreDropdown.tsx +9 -11
- package/src/Table/TableContextMenu.tsx +10 -13
- package/src/Table/hooks/useTableConfiguration.tsx +3 -4
- package/src/Table/index.tsx +12 -21
- package/src/TopTable/index.tsx +3 -4
- package/src/hooks/urlParsers.ts +38 -0
- package/src/hooks/useColorBy.ts +42 -0
- package/src/hooks/useCompareModeMeta.ts +61 -91
- package/src/hooks/useDashboardItems.ts +46 -0
- package/src/hooks/useQueryState.test.tsx +275 -345
- package/src/hooks/useQueryState.ts +136 -118
- package/src/index.tsx +16 -15
- 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 {
|
|
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
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
73
|
-
|
|
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 @@
|
|
|
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 |
|
|
33
|
-
setSumByParam: (value: string |
|
|
34
|
-
setGroupByParam: (value: string[] |
|
|
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":"
|
|
1
|
+
{"version":3,"file":"useQueryState.d.ts","sourceRoot":"","sources":["../../src/hooks/useQueryState.ts"],"names":[],"mappings":"AAkBA,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;AAM7F,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;IACnD,gBAAgB,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IAG7C,WAAW,EAAE,CAAC,kBAAkB,CAAC,EAAE;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAA;KAAC,KAAK,IAAI,CAAC;IAG9F,gBAAgB,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAG1C,aAAa,EAAE,aAAa,GAAG,IAAI,CAAC;IAGpC,mBAAmB,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IAGhF,YAAY,EAAE,OAAO,CAAC;IAGtB,gBAAgB,EAAE,KAAK,GAAG,IAAI,CAAC;IAG/B,WAAW,EAAE,KAAK,GAAG,IAAI,CAAC;IAE1B,kBAAkB,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;IACnD,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,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 {
|
|
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 [
|
|
29
|
-
|
|
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
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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 ===
|
|
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
|
|
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
|
|
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
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
const
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
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
|
-
|
|
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
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
296
|
+
void setQueryParams({
|
|
297
|
+
selection: query.toString(),
|
|
298
|
+
merge_from: mergeFrom.toString(),
|
|
299
|
+
merge_to: mergeTo.toString(),
|
|
300
300
|
});
|
|
301
|
-
}, [
|
|
301
|
+
}, [setQueryParams]);
|
|
302
302
|
const draftParsedQuery = useMemo(() => {
|
|
303
303
|
try {
|
|
304
304
|
return Query.parse(draftSelection.expression ?? '');
|