Skip to content

Commit

Permalink
fix: deleting node initiate edge handle freezing bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
MXerFix committed Jul 28, 2024
1 parent 1149cd2 commit e0fbed3
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions frontend/src/contexts/flowContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import React, { createContext, useCallback, useEffect, useState } from "react"
import toast from "react-hot-toast"
import { useParams } from "react-router-dom"
import { Edge } from "reactflow"
import { v4 } from "uuid"
import { get_flows, save_flows } from "../api/flows"
import { FLOW_COLORS } from "../consts"
Expand Down Expand Up @@ -156,12 +157,16 @@ export const FlowProvider = ({ children }: { children: React.ReactNode }) => {
// any_node.data.flags?.push("fallback")
}
const newNodes = flow.data.nodes.filter((node) => node.id !== id)
saveFlows(
flows.map((flow) =>
flow.name === flowId ? { ...flow, data: { ...flow.data, nodes: newNodes } } : flow
)
const newEdges = flow.data.edges.filter(
(edge: Edge) => edge.source !== id && edge.target !== id
)
const newFlows = flows.map((flow) =>
flow.name === flowId
? { ...flow, data: { ...flow.data, nodes: newNodes, edges: newEdges } }
: flow
)
setFlows((flows) => flows.map((flow) => ({ ...flow, data: { ...flow.data, nodes: newNodes } })))
saveFlows(newFlows)
setFlows(newFlows)
}

const deleteEdge = (id: string) => {
Expand Down

0 comments on commit e0fbed3

Please sign in to comment.