From eeff03211b3b11f7dcf628612c8529c61023b23a Mon Sep 17 00:00:00 2001 From: aranega Date: Fri, 11 Oct 2024 07:17:53 -0600 Subject: [PATCH] CELE-53 Fix neuron group not being removed from "visible" panel in 2D graph --- .../components/viewers/TwoD/ContextMenu.tsx | 1 + .../frontend/src/helpers/twoD/groupHelper.ts | 27 ++++++++++++------- .../visualizer/frontend/src/models/models.ts | 1 - 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/applications/visualizer/frontend/src/components/viewers/TwoD/ContextMenu.tsx b/applications/visualizer/frontend/src/components/viewers/TwoD/ContextMenu.tsx index dfdab25f..0f0d12a4 100644 --- a/applications/visualizer/frontend/src/components/viewers/TwoD/ContextMenu.tsx +++ b/applications/visualizer/frontend/src/components/viewers/TwoD/ContextMenu.tsx @@ -136,6 +136,7 @@ const ContextMenu: React.FC = ({ open, onClose, position, setS removeNodeFromGroup(cy, groupedNeuronId, true); } delete draft.neuronGroups[elementId]; // Delete the entire group + delete draft.visibilities[elementId]; if (openGroups.has(elementId)) { groupsToRemoveFromOpen.add(elementId); } diff --git a/applications/visualizer/frontend/src/helpers/twoD/groupHelper.ts b/applications/visualizer/frontend/src/helpers/twoD/groupHelper.ts index edd96f80..07599c31 100644 --- a/applications/visualizer/frontend/src/helpers/twoD/groupHelper.ts +++ b/applications/visualizer/frontend/src/helpers/twoD/groupHelper.ts @@ -2,8 +2,18 @@ import type { Core } from "cytoscape"; import type { NeuronGroup, Workspace } from "../../models"; import { SELECTED_CLASS } from "../../settings/twoDSettings.tsx"; +const _incrementInt = () => { + let i = 0; + return () => { + i++; + return i; + }; +}; + +const incrementInt = _incrementInt(); + export const groupNeurons = (selectedNeurons: Set, workspace: Workspace) => { - const newGroupId = `group_${Date.now()}`; + const newGroupId = `group_${incrementInt()}`; const newGroupNeurons = new Set(); const groupsToDelete = new Set(); let originalGroupName = ""; @@ -16,24 +26,24 @@ export const groupNeurons = (selectedNeurons: Set, workspace: Workspace) // Check if the neuronId is a group itself or part of another group if (group) { - group.neurons.forEach((groupedNeuronId) => { + for (const groupedNeuronId of group.neurons) { newGroupNeurons.add(groupedNeuronId); - }); + } groupsToDelete.add(neuronId); originalGroupName = group.name; originalGroupColor = group.color; } else { - Object.entries(workspace.neuronGroups).forEach(([groupId, existingGroup]) => { + for (const [groupId, existingGroup] of Object.entries(workspace.neuronGroups)) { if (existingGroup.neurons.has(neuronId)) { - existingGroup.neurons.forEach((groupedNeuronId) => { + for (const groupedNeuronId of existingGroup.neurons) { newGroupNeurons.add(groupedNeuronId); - }); + } groupsToDelete.add(groupId); originalGroupName = existingGroup.name; originalGroupColor = existingGroup.color; isPartOfAnotherGroup = true; } - }); + } // If neuronId is not part of any group, add it directly if (!isPartOfAnotherGroup) { @@ -48,7 +58,6 @@ export const groupNeurons = (selectedNeurons: Set, workspace: Workspace) name: originalGroupName || newGroupId, color: originalGroupColor, neurons: newGroupNeurons, - visible: true, }; return { newGroupId, newGroup, groupsToDelete }; @@ -56,7 +65,7 @@ export const groupNeurons = (selectedNeurons: Set, workspace: Workspace) export function removeNodeFromGroup(cy: Core, nodeId: string, setSelected: boolean) { const cyNode = cy.getElementById(nodeId); - if (cyNode && cyNode.isNode()) { + if (cyNode?.isNode()) { cyNode.move({ parent: null }); if (setSelected) { cyNode.addClass(SELECTED_CLASS); diff --git a/applications/visualizer/frontend/src/models/models.ts b/applications/visualizer/frontend/src/models/models.ts index a9a67cbb..503250e7 100644 --- a/applications/visualizer/frontend/src/models/models.ts +++ b/applications/visualizer/frontend/src/models/models.ts @@ -24,7 +24,6 @@ export interface NeuronGroup { name: string; color: string; neurons: Set; - visible: boolean; } export interface GraphViewerData {