From a7a52755ecaa51bd19d776a3bdf2d5662c903def Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Wed, 27 Sep 2023 22:13:33 -0300 Subject: [PATCH] Fixed nodes not deleting all at once --- src/frontend/src/contexts/typesContext.tsx | 14 +++++++++++--- .../FlowPage/components/PageComponent/index.tsx | 5 ++--- src/frontend/src/types/typesContext/index.ts | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/frontend/src/contexts/typesContext.tsx b/src/frontend/src/contexts/typesContext.tsx index 7caf5eccc..9d8745bee 100644 --- a/src/frontend/src/contexts/typesContext.tsx +++ b/src/frontend/src/contexts/typesContext.tsx @@ -92,14 +92,22 @@ export function TypesProvider({ children }: { children: ReactNode }) { } } - function deleteNode(idx: string) { + function deleteNode(idx: string | Array) { reactFlowInstance!.setNodes( - reactFlowInstance!.getNodes().filter((node: Node) => node.id !== idx) + reactFlowInstance! + .getNodes() + .filter((node: Node) => + typeof idx === "string" ? node.id !== idx : !idx.includes(node.id) + ) ); reactFlowInstance!.setEdges( reactFlowInstance! .getEdges() - .filter((edge) => edge.source !== idx && edge.target !== idx) + .filter((edge) => + typeof idx === "string" + ? edge.source !== idx && edge.target !== idx + : !idx.includes(edge.source) && !idx.includes(edge.target) + ) ); } return ( diff --git a/src/frontend/src/pages/FlowPage/components/PageComponent/index.tsx b/src/frontend/src/pages/FlowPage/components/PageComponent/index.tsx index e5692f90e..a1036de87 100644 --- a/src/frontend/src/pages/FlowPage/components/PageComponent/index.tsx +++ b/src/frontend/src/pages/FlowPage/components/PageComponent/index.tsx @@ -120,9 +120,8 @@ export default function Page({ lastSelection ) { event.preventDefault(); - lastSelection.nodes.forEach((k) => { - deleteNode(k.id); - }); + console.log(lastSelection); + deleteNode(lastSelection.nodes.map((node) => node.id)); } } }; diff --git a/src/frontend/src/types/typesContext/index.ts b/src/frontend/src/types/typesContext/index.ts index ff877b9d4..e64d50ce6 100644 --- a/src/frontend/src/types/typesContext/index.ts +++ b/src/frontend/src/types/typesContext/index.ts @@ -9,7 +9,7 @@ const data: { [char: string]: string } = {}; export type typesContextType = { reactFlowInstance: ReactFlowInstance | null; setReactFlowInstance: (newState: ReactFlowInstance) => void; - deleteNode: (idx: string) => void; + deleteNode: (idx: string | Array) => void; types: typeof types; setTypes: (newState: {}) => void; templates: typeof template;