Skip to content

Commit e655023

Browse files
authored
Merge pull request #5953 from parca-dev/toolbar-flamegraph-expansion
ui: Ensure Flame Graph is reset on all toolbar interactions
2 parents df1f4ce + 3275509 commit e655023

7 files changed

Lines changed: 21 additions & 22 deletions

File tree

ui/packages/shared/profile/src/ProfileExplorer/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {capitalizeOnlyFirstLetter, safeDecode, type NavigateFunction} from '@par
2323

2424
import {ProfileSelection, ProfileSelectionFromParams, SuffixParams} from '..';
2525
import {QuerySelection, useProfileTypes} from '../ProfileSelector';
26-
import {useResetStateOnNewSearch} from '../ProfileView/hooks/useResetStateOnNewSearch';
26+
import {useResetFlameGraphState} from '../ProfileView/hooks/useResetFlameGraphState';
2727
import {useResetStateOnProfileTypeChange} from '../ProfileView/hooks/useResetStateOnProfileTypeChange';
2828
import {sumByToParam, useSumByFromParams} from '../useSumBy';
2929
import ProfileExplorerCompare from './ProfileExplorerCompare';
@@ -162,7 +162,7 @@ const ProfileExplorerApp = ({
162162
const [profileB, setProfileB] = useState<ProfileSelection | null>(null);
163163

164164
const resetStateOnProfileTypeChange = useResetStateOnProfileTypeChange();
165-
const resetStateOnNewSearch = useResetStateOnNewSearch();
165+
const resetFlameGraphState = useResetFlameGraphState();
166166

167167
const sumByA = useSumByFromParams(sum_by_a);
168168
const sumByB = useSumByFromParams(sum_by_b);
@@ -250,7 +250,7 @@ const ProfileExplorerApp = ({
250250
resetStateOnProfileTypeChange();
251251
} else {
252252
// Reset the state when a new search is performed.
253-
resetStateOnNewSearch();
253+
resetFlameGraphState();
254254
}
255255
}
256256

ui/packages/shared/profile/src/ProfileView/components/DashboardItems/index.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ interface GetDashboardItemProps {
4242
profileSource: ProfileSource;
4343
total: bigint;
4444
filtered: bigint;
45-
curPath: string[];
46-
setNewCurPath: (path: string[]) => void;
4745
curPathArrow: CurrentPathFrame[];
4846
setNewCurPathArrow: (path: CurrentPathFrame[]) => void;
4947
perf?: {

ui/packages/shared/profile/src/ProfileView/components/ProfileFilters/useProfileFilters.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {useCallback, useEffect, useMemo, useRef, useState} from 'react';
1515

1616
import {type Filter, type NumberCondition, type StringCondition} from '@parca/client';
1717

18+
import {useResetFlameGraphState} from '../../hooks/useResetFlameGraphState';
1819
import {getPresetByKey, isPresetKey} from './filterPresets';
1920
import {useProfileFiltersUrlState} from './useProfileFiltersUrlState';
2021

@@ -226,6 +227,7 @@ export const useProfileFilters = (): {
226227
resetFilters: () => void;
227228
} => {
228229
const {appliedFilters, setAppliedFilters} = useProfileFiltersUrlState();
230+
const resetFlameGraphState = useResetFlameGraphState();
229231

230232
const [localFilters, setLocalFilters] = useState<ProfileFilter[]>(appliedFilters ?? []);
231233

@@ -327,9 +329,10 @@ export const useProfileFilters = (): {
327329
// Auto-apply the filter since it has a value
328330
const filtersToApply = [...(appliedFilters ?? []), newFilter];
329331
setAppliedFilters(filtersToApply);
332+
resetFlameGraphState();
330333
},
331334
// eslint-disable-next-line react-hooks/exhaustive-deps
332-
[setAppliedFilters]
335+
[setAppliedFilters, resetFlameGraphState]
333336
);
334337

335338
const removeExcludeBinary = useCallback(
@@ -349,12 +352,13 @@ export const useProfileFilters = (): {
349352
f => f.id !== filterToRemove.id
350353
);
351354
setAppliedFilters(updatedAppliedFilters);
355+
resetFlameGraphState();
352356

353357
// Also remove from local filters
354358
setLocalFilters(localFiltersRef.current.filter(f => f.id !== filterToRemove.id));
355359
}
356360
},
357-
[appliedFilters, setAppliedFilters]
361+
[appliedFilters, setAppliedFilters, resetFlameGraphState]
358362
);
359363

360364
const removeFilter = useCallback((id: string) => {
@@ -368,7 +372,8 @@ export const useProfileFilters = (): {
368372
const resetFilters = useCallback(() => {
369373
setLocalFilters([]);
370374
setAppliedFilters([]);
371-
}, [setAppliedFilters]);
375+
resetFlameGraphState();
376+
}, [setAppliedFilters, resetFlameGraphState]);
372377

373378
const onApplyFilters = useCallback((): void => {
374379
const validFilters = localFiltersRef.current.filter(f => {
@@ -386,7 +391,8 @@ export const useProfileFilters = (): {
386391
}));
387392

388393
setAppliedFilters(filtersToApply);
389-
}, [setAppliedFilters]);
394+
resetFlameGraphState();
395+
}, [setAppliedFilters, resetFlameGraphState]);
390396

391397
const protoFilters = useMemo(() => {
392398
return convertToProtoFilters(appliedFilters ?? []);

ui/packages/shared/profile/src/ProfileView/hooks/useResetStateOnNewSearch.ts renamed to ui/packages/shared/profile/src/ProfileView/hooks/useResetFlameGraphState.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
import {useURLState} from '@parca/components';
1515

16-
export const useResetStateOnNewSearch = (): (() => void) => {
16+
export const useResetFlameGraphState = (): (() => void) => {
1717
const [val, setCurPath] = useURLState('cur_path');
1818

1919
return () => {

ui/packages/shared/profile/src/ProfileView/hooks/useVisualizationState.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// See the License for the specific language governing permissions and
1212
// limitations under the License.
1313

14-
import {useCallback, useMemo, useState} from 'react';
14+
import {useCallback, useMemo} from 'react';
1515

1616
import {JSONParser, JSONSerializer, useURLState, useURLStateCustom} from '@parca/components';
1717

@@ -23,10 +23,9 @@ import {
2323
FIELD_MAPPING_FILE,
2424
} from '../../ProfileFlameGraph/FlameGraphArrow';
2525
import {CurrentPathFrame} from '../../ProfileFlameGraph/FlameGraphArrow/utils';
26+
import {useResetFlameGraphState} from './useResetFlameGraphState';
2627

2728
export const useVisualizationState = (): {
28-
curPath: string[];
29-
setCurPath: (path: string[]) => void;
3029
curPathArrow: CurrentPathFrame[];
3130
setCurPathArrow: (path: CurrentPathFrame[]) => void;
3231
colorStackLegend: string | undefined;
@@ -40,7 +39,6 @@ export const useVisualizationState = (): {
4039
setSandwichFunctionName: (sandwichFunctionName: string | undefined) => void;
4140
resetSandwichFunctionName: () => void;
4241
} => {
43-
const [curPath, setCurPath] = useState<string[]>([]);
4442
const [curPathArrow, setCurPathArrow] = useURLStateCustom<CurrentPathFrame[]>('cur_path', {
4543
parse: JSONParser<CurrentPathFrame[]>,
4644
stringify: JSONSerializer,
@@ -55,6 +53,7 @@ export const useVisualizationState = (): {
5553
const [sandwichFunctionName, setSandwichFunctionName] = useURLState<string | undefined>(
5654
'sandwich_function_name'
5755
);
56+
const resetFlameGraphState = useResetFlameGraphState();
5857

5958
const levelsOfProfiling = useMemo(
6059
() => [
@@ -81,8 +80,10 @@ export const useVisualizationState = (): {
8180
const filteredGroupBy = groupBy.filter(item => !levelsOfProfiling.includes(item));
8281
setGroupBy([...filteredGroupBy, key]); // add
8382
}
83+
84+
resetFlameGraphState();
8485
},
85-
[groupBy, setGroupBy, levelsOfProfiling]
86+
[groupBy, setGroupBy, levelsOfProfiling, resetFlameGraphState]
8687
);
8788

8889
const setGroupByLabels = useCallback(
@@ -97,8 +98,6 @@ export const useVisualizationState = (): {
9798
}, [setSandwichFunctionName]);
9899

99100
return {
100-
curPath,
101-
setCurPath,
102101
curPathArrow,
103102
setCurPathArrow,
104103
colorStackLegend,

ui/packages/shared/profile/src/ProfileView/index.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ export const ProfileView = ({
5656
const {ref, dimensions} = useContainerDimensions();
5757

5858
const {
59-
curPath,
60-
setCurPath,
6159
curPathArrow,
6260
setCurPathArrow,
6361
colorStackLegend,
@@ -100,8 +98,6 @@ export const ProfileView = ({
10098
profileSource,
10199
total,
102100
filtered,
103-
curPath,
104-
setNewCurPath: setCurPath,
105101
curPathArrow,
106102
setNewCurPathArrow: setCurPathArrow,
107103
perf,

ui/packages/shared/profile/src/ProfileViewWithData.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export const ProfileViewWithData = ({
5858

5959
useEffect(() => {
6060
// If profile type is not delta, remove flamechart from the dashboard items
61-
// and set it to flame if no other items are selected.
61+
// and set it to flame graph if no other items are selected.
6262
if (profileSource == null) {
6363
return;
6464
}

0 commit comments

Comments
 (0)