Skip to content

Commit 4946b56

Browse files
authored
ui: Reset visualisation state on selection of series point (#5746)
1 parent 1a6da3c commit 4946b56

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

ui/packages/shared/profile/src/ProfileSelector/MetricsGraphSection.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {MergedProfileSelection, ProfileSelection} from '..';
2121
import UtilizationMetricsGraph from '../MetricsGraph/UtilizationMetrics';
2222
import AreaChart from '../MetricsGraph/UtilizationMetrics/Throughput';
2323
import ProfileMetricsGraph, {ProfileMetricsEmptyState} from '../ProfileMetricsGraph';
24+
import {useResetStateOnSeriesChange} from '../ProfileView/hooks/useResetStateOnSeriesChange';
2425
import {QuerySelection, type UtilizationMetrics as UtilizationMetricsType} from './index';
2526

2627
interface MetricsGraphSectionProps {
@@ -69,6 +70,7 @@ export function MetricsGraphSection({
6970
utilizationMetricsLoading,
7071
onUtilizationSeriesSelect,
7172
}: MetricsGraphSectionProps): JSX.Element {
73+
const resetStateOnSeriesChange = useResetStateOnSeriesChange();
7274
const handleTimeRangeChange = (range: DateTimeRange): void => {
7375
const from = range.getFromMs();
7476
const to = range.getToMs();
@@ -137,6 +139,8 @@ export function MetricsGraphSection({
137139
const durationInMilliseconds = duration / 1000000; // duration is in nanoseconds
138140
const mergeFrom = timestamp;
139141
const mergeTo = query.profileType().delta ? mergeFrom + durationInMilliseconds : mergeFrom;
142+
143+
resetStateOnSeriesChange(); // reset some state when a new series is selected
140144
selectProfile(new MergedProfileSelection(mergeFrom, mergeTo, query));
141145
};
142146

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const useResetStateOnProfileTypeChange = (): (() => void) => {
1919
const [excludeFunction, setExcludeFunction] = useURLState('exclude_function');
2020
const [searchString, setSearchString] = useURLState('search_string');
2121
const [curPath, setCurPath] = useURLState('cur_path');
22+
const [sandwichFunctionName, setSandwichFunctionName] = useURLState('sandwich_function_name');
2223

2324
return () => {
2425
setTimeout(() => {
@@ -37,6 +38,9 @@ export const useResetStateOnProfileTypeChange = (): (() => void) => {
3738
if (curPath !== undefined) {
3839
setCurPath(undefined);
3940
}
41+
if (sandwichFunctionName !== undefined) {
42+
setSandwichFunctionName(undefined);
43+
}
4044
});
4145
};
4246
};
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
14+
import {useURLState} from '@parca/components';
15+
16+
export const useResetStateOnSeriesChange = (): (() => void) => {
17+
const [curPath, setCurPath] = useURLState('cur_path');
18+
const [sandwichFunctionName, setSandwichFunctionName] = useURLState('sandwich_function_name');
19+
20+
return () => {
21+
setTimeout(() => {
22+
if (curPath !== undefined) {
23+
setCurPath(undefined);
24+
}
25+
if (sandwichFunctionName !== undefined) {
26+
setSandwichFunctionName(undefined);
27+
}
28+
});
29+
};
30+
};

ui/packages/shared/profile/src/Sandwich/components/TableSection.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ export function TableSection({
4343
height,
4444
sandwichFunctionName,
4545
}: TableSectionProps): JSX.Element {
46-
console.log(height);
4746
return (
4847
<div
4948
style={{height: height !== undefined ? `${height}px` : '80vh'}}

0 commit comments

Comments
 (0)