@parca/profile 0.19.73 → 0.19.74
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 +4 -0
- package/dist/MatchersInput/index.d.ts.map +1 -1
- package/dist/MatchersInput/index.js +4 -2
- package/dist/ProfileExplorer/ProfileExplorerCompare.d.ts +1 -12
- package/dist/ProfileExplorer/ProfileExplorerCompare.d.ts.map +1 -1
- package/dist/ProfileExplorer/ProfileExplorerCompare.js +52 -11
- package/dist/ProfileExplorer/ProfileExplorerSingle.d.ts +1 -7
- package/dist/ProfileExplorer/ProfileExplorerSingle.d.ts.map +1 -1
- package/dist/ProfileExplorer/ProfileExplorerSingle.js +4 -2
- package/dist/ProfileExplorer/index.d.ts +1 -4
- package/dist/ProfileExplorer/index.d.ts.map +1 -1
- package/dist/ProfileExplorer/index.js +11 -225
- package/dist/ProfileMetricsGraph/index.d.ts +1 -1
- package/dist/ProfileMetricsGraph/index.d.ts.map +1 -1
- package/dist/ProfileMetricsGraph/index.js +16 -20
- package/dist/ProfileSelector/MetricsGraphSection.d.ts +3 -3
- package/dist/ProfileSelector/MetricsGraphSection.d.ts.map +1 -1
- package/dist/ProfileSelector/MetricsGraphSection.js +10 -6
- package/dist/ProfileSelector/index.d.ts +2 -7
- package/dist/ProfileSelector/index.d.ts.map +1 -1
- package/dist/ProfileSelector/index.js +40 -46
- package/dist/ProfileSelector/useAutoQuerySelector.d.ts.map +1 -1
- package/dist/ProfileSelector/useAutoQuerySelector.js +19 -4
- package/dist/ProfileTypeSelector/index.d.ts.map +1 -1
- package/dist/ProfileTypeSelector/index.js +1 -1
- package/dist/ProfileView/components/ViewSelector/index.d.ts.map +1 -1
- package/dist/ProfileView/components/ViewSelector/index.js +10 -4
- package/dist/ProfileView/hooks/useResetStateOnProfileTypeChange.d.ts.map +1 -1
- package/dist/ProfileView/hooks/useResetStateOnProfileTypeChange.js +4 -2
- package/dist/ProfileView/hooks/useVisualizationState.d.ts.map +1 -1
- package/dist/ProfileView/hooks/useVisualizationState.js +20 -13
- package/dist/Table/MoreDropdown.d.ts.map +1 -1
- package/dist/Table/MoreDropdown.js +7 -3
- package/dist/Table/TableContextMenu.d.ts.map +1 -1
- package/dist/Table/TableContextMenu.js +9 -5
- package/dist/hooks/useCompareModeMeta.d.ts +10 -0
- package/dist/hooks/useCompareModeMeta.d.ts.map +1 -0
- package/dist/hooks/useCompareModeMeta.js +113 -0
- package/dist/hooks/useQueryState.d.ts +32 -0
- package/dist/hooks/useQueryState.d.ts.map +1 -0
- package/dist/hooks/useQueryState.js +285 -0
- package/dist/hooks/useQueryState.test.d.ts +2 -0
- package/dist/hooks/useQueryState.test.d.ts.map +1 -0
- package/dist/hooks/useQueryState.test.js +910 -0
- package/dist/index.d.ts +4 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -3
- package/dist/useSumBy.d.ts +7 -0
- package/dist/useSumBy.d.ts.map +1 -1
- package/dist/useSumBy.js +31 -6
- package/package.json +6 -6
- package/src/MatchersInput/index.tsx +4 -2
- package/src/ProfileExplorer/ProfileExplorerCompare.tsx +64 -46
- package/src/ProfileExplorer/ProfileExplorerSingle.tsx +7 -19
- package/src/ProfileExplorer/index.tsx +11 -339
- package/src/ProfileMetricsGraph/index.tsx +16 -20
- package/src/ProfileSelector/MetricsGraphSection.tsx +14 -10
- package/src/ProfileSelector/index.tsx +65 -83
- package/src/ProfileSelector/useAutoQuerySelector.ts +23 -5
- package/src/ProfileTypeSelector/index.tsx +3 -1
- package/src/ProfileView/components/ViewSelector/index.tsx +9 -4
- package/src/ProfileView/hooks/useResetStateOnProfileTypeChange.ts +4 -2
- package/src/ProfileView/hooks/useVisualizationState.ts +25 -12
- package/src/Table/MoreDropdown.tsx +7 -3
- package/src/Table/TableContextMenu.tsx +9 -5
- package/src/hooks/useCompareModeMeta.ts +131 -0
- package/src/hooks/useQueryState.test.tsx +1202 -0
- package/src/hooks/useQueryState.ts +414 -0
- package/src/index.tsx +9 -11
- package/src/useSumBy.ts +62 -7
- package/src/ProfileExplorer/index.test.ts +0 -97
|
@@ -0,0 +1,113 @@
|
|
|
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 } from 'react';
|
|
14
|
+
import { useURLState, useURLStateBatch } from '@parca/components';
|
|
15
|
+
/**
|
|
16
|
+
* Hook to manage compare mode state and operations
|
|
17
|
+
* Returns compare mode flags and a function to close compare mode
|
|
18
|
+
*/
|
|
19
|
+
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');
|
|
43
|
+
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);
|
|
56
|
+
}
|
|
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);
|
|
70
|
+
});
|
|
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';
|
|
108
|
+
return {
|
|
109
|
+
isCompareMode,
|
|
110
|
+
isCompareAbsolute,
|
|
111
|
+
closeCompareMode,
|
|
112
|
+
};
|
|
113
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Query } from '@parca/parser';
|
|
2
|
+
import { QuerySelection } from '../ProfileSelector';
|
|
3
|
+
import { ProfileSelection, ProfileSource } from '../ProfileSource';
|
|
4
|
+
interface UseQueryStateOptions {
|
|
5
|
+
suffix?: '_a' | '_b';
|
|
6
|
+
defaultExpression?: string;
|
|
7
|
+
defaultTimeSelection?: string;
|
|
8
|
+
defaultFrom?: number;
|
|
9
|
+
defaultTo?: number;
|
|
10
|
+
comparing?: boolean;
|
|
11
|
+
}
|
|
12
|
+
interface UseQueryStateReturn {
|
|
13
|
+
querySelection: QuerySelection;
|
|
14
|
+
draftSelection: QuerySelection;
|
|
15
|
+
setDraftExpression: (expression: string, commit?: boolean) => void;
|
|
16
|
+
setDraftTimeRange: (from: number, to: number, timeSelection: string) => void;
|
|
17
|
+
setDraftSumBy: (sumBy: string[] | undefined) => void;
|
|
18
|
+
setDraftProfileName: (profileName: string) => void;
|
|
19
|
+
setDraftMatchers: (matchers: string) => void;
|
|
20
|
+
commitDraft: (refreshedTimeRange?: {
|
|
21
|
+
from: number;
|
|
22
|
+
to: number;
|
|
23
|
+
timeSelection: string;
|
|
24
|
+
}) => void;
|
|
25
|
+
profileSelection: ProfileSelection | null;
|
|
26
|
+
profileSource: ProfileSource | null;
|
|
27
|
+
setProfileSelection: (mergeFrom: bigint, mergeTo: bigint, query: Query) => void;
|
|
28
|
+
sumByLoading: boolean;
|
|
29
|
+
}
|
|
30
|
+
export declare const useQueryState: (options?: UseQueryStateOptions) => UseQueryStateReturn;
|
|
31
|
+
export {};
|
|
32
|
+
//# sourceMappingURL=useQueryState.d.ts.map
|
|
@@ -0,0 +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;AAG7F,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;CACrB;AAED,UAAU,mBAAmB;IAE3B,cAAc,EAAE,cAAc,CAAC;IAG/B,cAAc,EAAE,cAAc,CAAC;IAG/B,kBAAkB,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IACnE,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;CACvB;AAED,eAAO,MAAM,aAAa,GAAI,UAAS,oBAAyB,KAAG,mBAgWlE,CAAC"}
|
|
@@ -0,0 +1,285 @@
|
|
|
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, useEffect, useMemo, useState } from 'react';
|
|
14
|
+
import { DateTimeRange, useParcaContext, useURLState, useURLStateBatch } from '@parca/components';
|
|
15
|
+
import { Query } from '@parca/parser';
|
|
16
|
+
import { ProfileSelectionFromParams } from '../ProfileSource';
|
|
17
|
+
import { sumByToParam, useSumBy, useSumByFromParams } from '../useSumBy';
|
|
18
|
+
export const useQueryState = (options = {}) => {
|
|
19
|
+
const { queryServiceClient: queryClient } = useParcaContext();
|
|
20
|
+
const { suffix = '', defaultExpression = '', defaultTimeSelection = 'relative:minute|15', // Default to 15 minutes relative
|
|
21
|
+
defaultFrom, defaultTo, comparing = false, } = options;
|
|
22
|
+
const batchUpdates = useURLStateBatch();
|
|
23
|
+
// URL state hooks with appropriate suffixes
|
|
24
|
+
const [expression, setExpressionState] = useURLState(`expression${suffix}`, {
|
|
25
|
+
defaultValue: defaultExpression,
|
|
26
|
+
});
|
|
27
|
+
const [from, setFromState] = useURLState(`from${suffix}`, {
|
|
28
|
+
defaultValue: defaultFrom?.toString(),
|
|
29
|
+
});
|
|
30
|
+
const [to, setToState] = useURLState(`to${suffix}`, {
|
|
31
|
+
defaultValue: defaultTo?.toString(),
|
|
32
|
+
});
|
|
33
|
+
const [timeSelection, setTimeSelectionState] = useURLState(`time_selection${suffix}`, {
|
|
34
|
+
defaultValue: defaultTimeSelection,
|
|
35
|
+
});
|
|
36
|
+
const [sumByParam, setSumByParam] = useURLState(`sum_by${suffix}`);
|
|
37
|
+
const [mergeFrom, setMergeFromState] = useURLState(`merge_from${suffix}`);
|
|
38
|
+
const [mergeTo, setMergeToState] = useURLState(`merge_to${suffix}`);
|
|
39
|
+
// ProfileSelection URL state hooks - reuses merge_from/merge_to but adds selection
|
|
40
|
+
const [selectionParam, setSelectionParam] = useURLState(`selection${suffix}`);
|
|
41
|
+
// Parse sumBy from URL parameter format
|
|
42
|
+
const sumBy = useSumByFromParams(sumByParam);
|
|
43
|
+
// Draft state management
|
|
44
|
+
const [draftExpression, setDraftExpression] = useState(expression ?? defaultExpression);
|
|
45
|
+
const [draftFrom, setDraftFrom] = useState(from ?? defaultFrom?.toString() ?? '');
|
|
46
|
+
const [draftTo, setDraftTo] = useState(to ?? defaultTo?.toString() ?? '');
|
|
47
|
+
const [draftTimeSelection, setDraftTimeSelection] = useState(timeSelection ?? defaultTimeSelection);
|
|
48
|
+
const [draftSumBy, setDraftSumBy] = useState(sumBy);
|
|
49
|
+
// Sync draft state with URL state when URL changes externally
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
setDraftExpression(expression ?? defaultExpression);
|
|
52
|
+
}, [expression, defaultExpression]);
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
setDraftFrom(from ?? defaultFrom?.toString() ?? '');
|
|
55
|
+
}, [from, defaultFrom]);
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
setDraftTo(to ?? defaultTo?.toString() ?? '');
|
|
58
|
+
}, [to, defaultTo]);
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
setDraftTimeSelection(timeSelection ?? defaultTimeSelection);
|
|
61
|
+
}, [timeSelection, defaultTimeSelection]);
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
setDraftSumBy(sumBy);
|
|
64
|
+
}, [sumBy]);
|
|
65
|
+
// Parse the draft query to extract profile information
|
|
66
|
+
const draftQuery = useMemo(() => {
|
|
67
|
+
try {
|
|
68
|
+
return Query.parse(draftExpression ?? '');
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
return Query.parse('');
|
|
72
|
+
}
|
|
73
|
+
}, [draftExpression]);
|
|
74
|
+
const draftProfileType = useMemo(() => draftQuery.profileType(), [draftQuery]);
|
|
75
|
+
const draftProfileName = useMemo(() => draftQuery.profileName(), [draftQuery]);
|
|
76
|
+
// Compute draft time range for label fetching
|
|
77
|
+
const draftTimeRange = useMemo(() => {
|
|
78
|
+
return DateTimeRange.fromRangeKey(draftTimeSelection ?? defaultTimeSelection, draftFrom !== '' ? parseInt(draftFrom) : defaultFrom, draftTo !== '' ? parseInt(draftTo) : defaultTo);
|
|
79
|
+
}, [draftTimeSelection, draftFrom, draftTo, defaultTimeSelection, defaultFrom, defaultTo]);
|
|
80
|
+
// Use combined sumBy hook for fetching labels and computing defaults (based on committed state)
|
|
81
|
+
const { sumBy: computedSumByFromURL, isLoading: sumBySelectionLoading } = useSumBy(queryClient, draftProfileType, draftTimeRange, sumBy);
|
|
82
|
+
// Construct the QuerySelection object (committed state from URL)
|
|
83
|
+
const querySelection = useMemo(() => {
|
|
84
|
+
const range = DateTimeRange.fromRangeKey(timeSelection ?? defaultTimeSelection, from !== undefined && from !== '' ? parseInt(from) : defaultFrom, to !== undefined && to !== '' ? parseInt(to) : defaultTo);
|
|
85
|
+
return {
|
|
86
|
+
expression: expression ?? defaultExpression,
|
|
87
|
+
from: range.getFromMs(),
|
|
88
|
+
to: range.getToMs(),
|
|
89
|
+
timeSelection: range.getRangeKey(),
|
|
90
|
+
sumBy: computedSumByFromURL,
|
|
91
|
+
...(mergeFrom !== undefined && mergeFrom !== '' && mergeTo !== undefined && mergeTo !== ''
|
|
92
|
+
? { mergeFrom, mergeTo }
|
|
93
|
+
: {}),
|
|
94
|
+
};
|
|
95
|
+
}, [
|
|
96
|
+
expression,
|
|
97
|
+
from,
|
|
98
|
+
to,
|
|
99
|
+
timeSelection,
|
|
100
|
+
computedSumByFromURL,
|
|
101
|
+
mergeFrom,
|
|
102
|
+
mergeTo,
|
|
103
|
+
defaultExpression,
|
|
104
|
+
defaultTimeSelection,
|
|
105
|
+
defaultFrom,
|
|
106
|
+
defaultTo,
|
|
107
|
+
]);
|
|
108
|
+
// Construct the draft QuerySelection object (local draft state)
|
|
109
|
+
const draftSelection = useMemo(() => {
|
|
110
|
+
const isDelta = draftProfileType.delta;
|
|
111
|
+
const draftMergeFrom = isDelta
|
|
112
|
+
? (BigInt(draftTimeRange.getFromMs()) * 1000000n).toString()
|
|
113
|
+
: undefined;
|
|
114
|
+
const draftMergeTo = isDelta
|
|
115
|
+
? (BigInt(draftTimeRange.getToMs()) * 1000000n).toString()
|
|
116
|
+
: undefined;
|
|
117
|
+
return {
|
|
118
|
+
expression: draftExpression ?? defaultExpression,
|
|
119
|
+
from: draftTimeRange.getFromMs(),
|
|
120
|
+
to: draftTimeRange.getToMs(),
|
|
121
|
+
timeSelection: draftTimeRange.getRangeKey(),
|
|
122
|
+
sumBy: draftSumBy ?? computedSumByFromURL, // Use draft if set, otherwise fallback to computed
|
|
123
|
+
...(draftMergeFrom !== undefined &&
|
|
124
|
+
draftMergeFrom !== '' &&
|
|
125
|
+
draftMergeTo !== undefined &&
|
|
126
|
+
draftMergeTo !== ''
|
|
127
|
+
? { mergeFrom: draftMergeFrom, mergeTo: draftMergeTo }
|
|
128
|
+
: {}),
|
|
129
|
+
};
|
|
130
|
+
}, [
|
|
131
|
+
draftExpression,
|
|
132
|
+
draftTimeRange,
|
|
133
|
+
draftSumBy,
|
|
134
|
+
computedSumByFromURL,
|
|
135
|
+
draftProfileType.delta,
|
|
136
|
+
defaultExpression,
|
|
137
|
+
]);
|
|
138
|
+
// Compute ProfileSelection from URL params
|
|
139
|
+
const profileSelection = useMemo(() => {
|
|
140
|
+
return ProfileSelectionFromParams(mergeFrom, mergeTo, selectionParam);
|
|
141
|
+
}, [mergeFrom, mergeTo, selectionParam]);
|
|
142
|
+
// Compute ProfileSource from ProfileSelection
|
|
143
|
+
const profileSource = useMemo(() => {
|
|
144
|
+
if (profileSelection === null)
|
|
145
|
+
return null;
|
|
146
|
+
return profileSelection.ProfileSource();
|
|
147
|
+
}, [profileSelection]);
|
|
148
|
+
// Commit draft changes to URL
|
|
149
|
+
// Optional refreshedTimeRange parameter allows re-evaluating relative time ranges (e.g., "last 15 minutes")
|
|
150
|
+
// to the current moment when the Search button is clicked
|
|
151
|
+
// Optional expression parameter allows updating the expression before committing
|
|
152
|
+
const commitDraft = useCallback((refreshedTimeRange, expression) => {
|
|
153
|
+
batchUpdates(() => {
|
|
154
|
+
// Use provided expression or current draft expression
|
|
155
|
+
const finalExpression = expression ?? draftExpression;
|
|
156
|
+
// Update draft state with new expression if provided
|
|
157
|
+
if (expression !== undefined) {
|
|
158
|
+
setDraftExpression(expression);
|
|
159
|
+
}
|
|
160
|
+
// Calculate the actual from/to values from draftSelection if not provided
|
|
161
|
+
const calculatedFrom = draftSelection.from.toString();
|
|
162
|
+
const calculatedTo = draftSelection.to.toString();
|
|
163
|
+
const finalFrom = refreshedTimeRange?.from?.toString() ?? (draftFrom !== '' ? draftFrom : calculatedFrom);
|
|
164
|
+
const finalTo = refreshedTimeRange?.to?.toString() ?? (draftTo !== '' ? draftTo : calculatedTo);
|
|
165
|
+
const finalTimeSelection = refreshedTimeRange?.timeSelection ?? draftTimeSelection;
|
|
166
|
+
// Update draft state with refreshed time range if provided
|
|
167
|
+
if (refreshedTimeRange?.from !== undefined) {
|
|
168
|
+
setDraftFrom(finalFrom);
|
|
169
|
+
}
|
|
170
|
+
if (refreshedTimeRange?.to !== undefined) {
|
|
171
|
+
setDraftTo(finalTo);
|
|
172
|
+
}
|
|
173
|
+
if (refreshedTimeRange?.timeSelection !== undefined) {
|
|
174
|
+
setDraftTimeSelection(finalTimeSelection);
|
|
175
|
+
}
|
|
176
|
+
setExpressionState(finalExpression);
|
|
177
|
+
setFromState(finalFrom);
|
|
178
|
+
setToState(finalTo);
|
|
179
|
+
setTimeSelectionState(finalTimeSelection);
|
|
180
|
+
setSumByParam(sumByToParam(draftSumBy));
|
|
181
|
+
// Auto-calculate merge parameters for delta profiles
|
|
182
|
+
// Parse the final expression to check if it's a delta profile
|
|
183
|
+
const finalQuery = Query.parse(finalExpression);
|
|
184
|
+
const isDelta = finalQuery.profileType().delta;
|
|
185
|
+
if (isDelta && finalFrom !== '' && finalTo !== '') {
|
|
186
|
+
const fromMs = parseInt(finalFrom);
|
|
187
|
+
const toMs = parseInt(finalTo);
|
|
188
|
+
setMergeFromState((BigInt(fromMs) * 1000000n).toString());
|
|
189
|
+
setMergeToState((BigInt(toMs) * 1000000n).toString());
|
|
190
|
+
// Auto-select the time range for delta profiles (but not in compare mode)
|
|
191
|
+
// This applies both on initial load AND when Search is clicked
|
|
192
|
+
// The selection will use the final expression and the updated time range
|
|
193
|
+
if (!comparing) {
|
|
194
|
+
setSelectionParam(finalExpression);
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
setSelectionParam(undefined);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
setMergeFromState(undefined);
|
|
202
|
+
setMergeToState(undefined);
|
|
203
|
+
// Clear ProfileSelection for non-delta profiles
|
|
204
|
+
setSelectionParam(undefined);
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
}, [
|
|
208
|
+
batchUpdates,
|
|
209
|
+
draftExpression,
|
|
210
|
+
draftFrom,
|
|
211
|
+
draftTo,
|
|
212
|
+
draftTimeSelection,
|
|
213
|
+
draftSumBy,
|
|
214
|
+
draftSelection.from,
|
|
215
|
+
draftSelection.to,
|
|
216
|
+
comparing,
|
|
217
|
+
setExpressionState,
|
|
218
|
+
setFromState,
|
|
219
|
+
setToState,
|
|
220
|
+
setTimeSelectionState,
|
|
221
|
+
setSumByParam,
|
|
222
|
+
setMergeFromState,
|
|
223
|
+
setMergeToState,
|
|
224
|
+
setSelectionParam,
|
|
225
|
+
]);
|
|
226
|
+
// Draft setters (update local state only, or commit directly if specified)
|
|
227
|
+
const setDraftExpressionCallback = useCallback((newExpression, commit = false) => {
|
|
228
|
+
if (commit) {
|
|
229
|
+
// Commit with the new expression, which will also update merge params and selection
|
|
230
|
+
commitDraft(undefined, newExpression);
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
// Only update draft state
|
|
234
|
+
setDraftExpression(newExpression);
|
|
235
|
+
}
|
|
236
|
+
}, [commitDraft]);
|
|
237
|
+
const setDraftTimeRange = useCallback((newFrom, newTo, newTimeSelection) => {
|
|
238
|
+
setDraftFrom(newFrom.toString());
|
|
239
|
+
setDraftTo(newTo.toString());
|
|
240
|
+
setDraftTimeSelection(newTimeSelection);
|
|
241
|
+
}, []);
|
|
242
|
+
const setDraftSumByCallback = useCallback((newSumBy) => {
|
|
243
|
+
setDraftSumBy(newSumBy);
|
|
244
|
+
}, []);
|
|
245
|
+
const setDraftProfileName = useCallback((newProfileName) => {
|
|
246
|
+
if (newProfileName === '')
|
|
247
|
+
return;
|
|
248
|
+
const [newQuery, changed] = draftQuery.setProfileName(newProfileName);
|
|
249
|
+
if (changed) {
|
|
250
|
+
setDraftExpression(newQuery.toString());
|
|
251
|
+
}
|
|
252
|
+
}, [draftQuery]);
|
|
253
|
+
const setDraftMatchers = useCallback((matchers) => {
|
|
254
|
+
const newExpression = `${draftProfileName}{${matchers}}`;
|
|
255
|
+
setDraftExpression(newExpression);
|
|
256
|
+
}, [draftProfileName]);
|
|
257
|
+
// Set ProfileSelection (auto-commits to URL immediately)
|
|
258
|
+
const setProfileSelection = useCallback((mergeFrom, mergeTo, query) => {
|
|
259
|
+
batchUpdates(() => {
|
|
260
|
+
setSelectionParam(query.toString());
|
|
261
|
+
setMergeFromState(mergeFrom.toString());
|
|
262
|
+
setMergeToState(mergeTo.toString());
|
|
263
|
+
});
|
|
264
|
+
}, [batchUpdates, setSelectionParam, setMergeFromState, setMergeToState]);
|
|
265
|
+
return {
|
|
266
|
+
// Current committed state
|
|
267
|
+
querySelection,
|
|
268
|
+
// Draft state
|
|
269
|
+
draftSelection,
|
|
270
|
+
// Draft setters
|
|
271
|
+
setDraftExpression: setDraftExpressionCallback,
|
|
272
|
+
setDraftTimeRange,
|
|
273
|
+
setDraftSumBy: setDraftSumByCallback,
|
|
274
|
+
setDraftProfileName,
|
|
275
|
+
setDraftMatchers,
|
|
276
|
+
// Commit function
|
|
277
|
+
commitDraft,
|
|
278
|
+
// ProfileSelection state
|
|
279
|
+
profileSelection,
|
|
280
|
+
profileSource,
|
|
281
|
+
setProfileSelection,
|
|
282
|
+
// Loading state
|
|
283
|
+
sumByLoading: sumBySelectionLoading,
|
|
284
|
+
};
|
|
285
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useQueryState.test.d.ts","sourceRoot":"","sources":["../../src/hooks/useQueryState.test.tsx"],"names":[],"mappings":""}
|