From 5c5707fb5d738adcda15549e380cc3fbb346dd80 Mon Sep 17 00:00:00 2001 From: afonso Date: Thu, 1 Aug 2024 17:07:02 +0100 Subject: [PATCH] CELE-32 fix: Improve use effect dependencies --- .../src/components/viewers/TwoD/TwoDViewer.tsx | 7 +++++-- applications/visualizer/frontend/src/helpers/utils.ts | 11 +++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 applications/visualizer/frontend/src/helpers/utils.ts diff --git a/applications/visualizer/frontend/src/components/viewers/TwoD/TwoDViewer.tsx b/applications/visualizer/frontend/src/components/viewers/TwoD/TwoDViewer.tsx index 73ddb075..38532bd1 100644 --- a/applications/visualizer/frontend/src/components/viewers/TwoD/TwoDViewer.tsx +++ b/applications/visualizer/frontend/src/components/viewers/TwoD/TwoDViewer.tsx @@ -19,6 +19,7 @@ import {Box} from "@mui/material"; import {ColoringOptions, getColor} from "../../../helpers/twoD/coloringHelper"; import ContextMenu from "./ContextMenu"; import {computeGraphDifferences, updateHighlighted} from "../../../helpers/twoD/graphRendering.ts"; +import {areSetsEqual} from "../../../helpers/utils.ts"; cytoscape.use(fcose); cytoscape.use(dagre); @@ -118,7 +119,7 @@ const TwoDViewer = () => { if (cyRef.current) { updateGraphElements(cyRef.current, connections); } - }, [connections, hiddenNodes, workspace.neuronGroups, includePostEmbryonic]); + }, [connections, hiddenNodes, workspace.neuronGroups, includePostEmbryonic, splitJoinState]); useEffect(() => { if (cyRef.current) { @@ -241,7 +242,9 @@ const TwoDViewer = () => { } }); - workspace.setActiveNeurons(activeNeurons); + if(!areSetsEqual(activeNeurons, workspace.activeNeurons)){ + workspace.setActiveNeurons(activeNeurons); + } }, [splitJoinState, workspace.id]); // Effect to handle includeLabels state diff --git a/applications/visualizer/frontend/src/helpers/utils.ts b/applications/visualizer/frontend/src/helpers/utils.ts new file mode 100644 index 00000000..a35af0f6 --- /dev/null +++ b/applications/visualizer/frontend/src/helpers/utils.ts @@ -0,0 +1,11 @@ +export function areSetsEqual(setA: Set, setB: Set): boolean { + if (setA.size !== setB.size) { + return false; + } + for (let item of setA) { + if (!setB.has(item)) { + return false; + } + } + return true; +} \ No newline at end of file