Skip to content

Commit 906cee4

Browse files
committed
fix updateModel call on scope / group change
1 parent dabe7b2 commit 906cee4

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
@@ -55,6 +55,7 @@ import { STEP_INTO_EVENT, FILTER_EVENT } from './styles/styleNode';
5555
export const HOVER_EVENT = 'hover';
5656

5757
let requestFit = false;
58+
let waitForMetrics = false;
5859
let lastNodeIdsFound: string[] = [];
5960

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

93+
const prevMetrics = usePrevious(metrics);
9294
const prevMetricFunction = usePrevious(metricFunction);
9395
const prevMetricType = usePrevious(metricType);
9496
const prevOptions = usePrevious(options);
@@ -302,7 +304,10 @@ const TopologyContent: React.FC<{
302304
return;
303305
} else if (!controller.hasGraph()) {
304306
console.error('updateModel called while controller has no graph');
307+
} else if (waitForMetrics && prevMetrics === metrics) {
308+
return;
305309
}
310+
waitForMetrics = false;
306311

307312
//highlight either hoveredId or selected id
308313
let highlightedId = hoveredId;
@@ -336,14 +341,25 @@ const TopologyContent: React.FC<{
336341
}
337342
});
338343
controller.fromModel(updatedModel);
339-
}, [controller, hoveredId, selectedIds, metrics, getOptions, searchValue, filters, t]);
344+
}, [controller, prevMetrics, metrics, hoveredId, selectedIds, getOptions, searchValue, filters, t]);
340345

341346
//update model on layout / metrics / filters change
342347
React.useEffect(() => {
343348
//update graph
344-
if (!controller.hasGraph() || prevOptions?.layout !== options.layout) {
349+
if (
350+
!controller.hasGraph() ||
351+
prevOptions?.layout !== options.layout ||
352+
prevOptions.startCollapsed !== options.startCollapsed
353+
) {
345354
resetGraph();
346355
}
356+
357+
//skip refresh if scope / group changed. It will refresh after getting new metrics
358+
if (prevOptions && (prevOptions.scope !== options.scope || prevOptions.groupTypes !== options.groupTypes)) {
359+
waitForMetrics = true;
360+
return;
361+
}
362+
347363
//then update model
348364
updateModel();
349365
}, [controller, metrics, filters, options, prevOptions, resetGraph, updateModel]);

0 commit comments

Comments
 (0)