Nodes connection after deleting a node with edge connected bug fixed

This commit is contained in:
Lucas Oliveira 2023-03-08 19:40:40 -03:00
commit 0e4bb1bc1d
3 changed files with 6 additions and 1 deletions

View file

@ -21,6 +21,7 @@ export function TypesProvider({ children }:{children:ReactNode}) {
reactFlowInstance.setNodes(
reactFlowInstance.getNodes().filter((n:Node) => n.id !== idx)
);
reactFlowInstance.setEdges(reactFlowInstance.getEdges().filter((ns) => ns.source !== idx && ns.target !== idx));
}
return (
<typesContext.Provider

View file

@ -153,7 +153,11 @@ export default function FlowPage({ flow }:{flow:FlowType}) {
// Specify dependencies for useCallback
[incrementNodeId, reactFlowInstance, setErrorData, setNodes]
);
const onDelete = (mynodes) => {
setEdges(edges.filter((ns) => !nodes.some((n) => ns.source === n.id || ns.target === n.id)));
}
return (
<div className="w-full h-full" ref={reactFlowWrapper}>
@ -174,6 +178,7 @@ export default function FlowPage({ flow }:{flow:FlowType}) {
connectionLineComponent={ConnectionLineComponent}
onDragOver={onDragOver}
onDrop={onDrop}
onNodesDelete={onDelete}
>
<Background className="dark:bg-gray-900"/>
<Controls className="[&>button]:text-black [&>button]:dark:bg-gray-800 hover:[&>button]:dark:bg-gray-700 [&>button]:dark:text-gray-400 [&>button]:dark:fill-gray-400 [&>button]:dark:border-gray-600">

View file

@ -315,7 +315,6 @@ export function isValidConnection(
{ source, target, sourceHandle, targetHandle }:Connection,
reactFlowInstance:ReactFlowInstance
) {
console.log(target)
if (
sourceHandle.split('|')[0] === targetHandle.split("|")[0] ||
sourceHandle.split('|').slice(2).some((t) => t === targetHandle.split("|")[0]) ||