From 33c664737545c6a8801a9e1546d7843e24ac0f54 Mon Sep 17 00:00:00 2001 From: mlogclub Date: Sun, 28 Jun 2026 10:07:00 +0800 Subject: [PATCH] feat: add delete functionality for condition branches in node forms and improve edge filtering in workflow normalization --- .../_components/flowgram-node-registries.tsx | 18 +++++++++++++- .../_components/node-config-panel.tsx | 20 +++++++++------- .../_components/workflow-utils.ts | 24 +++++++++++++++++-- 3 files changed, 50 insertions(+), 12 deletions(-) diff --git a/web/app/dashboard/ai-workflows/_components/flowgram-node-registries.tsx b/web/app/dashboard/ai-workflows/_components/flowgram-node-registries.tsx index 621c384..4d2b717 100644 --- a/web/app/dashboard/ai-workflows/_components/flowgram-node-registries.tsx +++ b/web/app/dashboard/ai-workflows/_components/flowgram-node-registries.tsx @@ -1,5 +1,5 @@ import { Field, type WorkflowNodeRegistry } from "@flowgram.ai/free-layout-editor" -import { PlusIcon } from "lucide-react" +import { PlusIcon, XIcon } from "lucide-react" import { Button } from "@/components/ui/button" import type { AIWorkflowNodeSpec } from "@/lib/api/admin" @@ -99,6 +99,9 @@ function ConditionNodeForm({ fallbackTitle }: { fallbackTitle: string }) { branches: ensureConditionBranches(nextBranches), }) } + const deleteBranch = (branchId: string) => { + updateBranches(branches.filter((branch) => branch.id !== branchId)) + } return (
@@ -114,6 +117,19 @@ function ConditionNodeForm({ fallbackTitle }: { fallbackTitle: string }) { {branch.default ? "else" : index === 0 ? "if" : "elseif"} + {branch.default ? null : ( + + )} onChange({ ...branch, name: event.target.value })} /> - + {branch.default ? null : ( + + )}
diff --git a/web/app/dashboard/ai-workflows/_components/workflow-utils.ts b/web/app/dashboard/ai-workflows/_components/workflow-utils.ts index 4ee0c86..3894e3a 100644 --- a/web/app/dashboard/ai-workflows/_components/workflow-utils.ts +++ b/web/app/dashboard/ai-workflows/_components/workflow-utils.ts @@ -241,18 +241,32 @@ export function deleteConditionBranch( return definition } const config = normalizeNodeConfig(node.data?.config) - return updateWorkflowNodeData(definition, nodeId, { + const nextDefinition = updateWorkflowNodeData(definition, nodeId, { ...(node.data ?? {}), config: { ...config, branches: (config.branches ?? []).filter((branch) => branch.id !== branchId), }, }) + return { + ...nextDefinition, + edges: nextDefinition.edges.filter((edge) => !(edge.sourceNodeID === nodeId && edge.sourcePortID === branchId)), + } } export function normalizeConditionPortsForFlowgram( definition: AIWorkflowDefinition ): AIWorkflowDefinition { + const branchIdsByNodeId = new Map>() + for (const node of definition.nodes) { + if (node.type !== "condition") { + continue + } + const config = normalizeNodeConfig(node.data?.config) + const branches = ensureConditionBranches(config.branches ?? []) + branchIdsByNodeId.set(node.id, new Set(branches.map((branch) => branch.id))) + } + return { ...definition, nodes: definition.nodes.map((node) => { @@ -271,7 +285,13 @@ export function normalizeConditionPortsForFlowgram( }, } }), - edges: definition.edges.map((edge) => { + edges: definition.edges.filter((edge) => { + if (!edge.sourcePortID) { + return true + } + const branchIds = branchIdsByNodeId.get(edge.sourceNodeID) + return !branchIds || branchIds.has(edge.sourcePortID) + }).map((edge) => { const source = definition.nodes.find((node) => node.id === edge.sourceNodeID) if (!source || source.type !== "condition" || edge.sourcePortID) { return edge