Skip to content

Commit 2490608

Browse files
authored
Merge pull request #161 from jpinsonneau/364
NETOBSERV-364 Topology crash on scope change with groups
2 parents b075e80 + 906cee4 commit 2490608

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

web/src/components/netflow-topology/netflow-topology.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import { STEP_INTO_EVENT, FILTER_EVENT } from './styles/styleNode';
5656
export const HOVER_EVENT = 'hover';
5757

5858
let requestFit = false;
59+
let waitForMetrics = false;
5960
let lastNodeIdsFound: string[] = [];
6061

6162
const ZOOM_IN = 4 / 3;
@@ -90,6 +91,7 @@ const TopologyContent: React.FC<{
9091
const { t } = useTranslation('plugin__network-observability-plugin');
9192
const controller = useVisualizationController();
9293

94+
const prevMetrics = usePrevious(metrics);
9395
const prevMetricFunction = usePrevious(metricFunction);
9496
const prevMetricType = usePrevious(metricType);
9597
const prevOptions = usePrevious(options);
@@ -313,7 +315,10 @@ const TopologyContent: React.FC<{
313315
return;
314316
} else if (!controller.hasGraph()) {
315317
console.error('updateModel called while controller has no graph');
318+
} else if (waitForMetrics && prevMetrics === metrics) {
319+
return;
316320
}
321+
waitForMetrics = false;
317322

318323
//highlight either hoveredId or selected id
319324
let highlightedId = hoveredId;
@@ -347,14 +352,25 @@ const TopologyContent: React.FC<{
347352
}
348353
});
349354
controller.fromModel(updatedModel);
350-
}, [controller, hoveredId, selectedIds, metrics, getOptions, searchValue, filters, t]);
355+
}, [controller, prevMetrics, metrics, hoveredId, selectedIds, getOptions, searchValue, filters, t]);
351356

352357
//update model on layout / metrics / filters change
353358
React.useEffect(() => {
354359
//update graph
355-
if (!controller.hasGraph() || prevOptions?.layout !== options.layout) {
360+
if (
361+
!controller.hasGraph() ||
362+
prevOptions?.layout !== options.layout ||
363+
prevOptions.startCollapsed !== options.startCollapsed
364+
) {
356365
resetGraph();
357366
}
367+
368+
//skip refresh if scope / group changed. It will refresh after getting new metrics
369+
if (prevOptions && (prevOptions.scope !== options.scope || prevOptions.groupTypes !== options.groupTypes)) {
370+
waitForMetrics = true;
371+
return;
372+
}
373+
358374
//then update model
359375
updateModel();
360376
}, [controller, metrics, filters, options, prevOptions, resetGraph, updateModel]);

0 commit comments

Comments
 (0)