Fixed nodes not deleting all at once
This commit is contained in:
parent
79215995fd
commit
a7a52755ec
3 changed files with 14 additions and 7 deletions
|
|
@ -92,14 +92,22 @@ export function TypesProvider({ children }: { children: ReactNode }) {
|
|||
}
|
||||
}
|
||||
|
||||
function deleteNode(idx: string) {
|
||||
function deleteNode(idx: string | Array<string>) {
|
||||
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 (
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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<string>) => void;
|
||||
types: typeof types;
|
||||
setTypes: (newState: {}) => void;
|
||||
templates: typeof template;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue