From d0cd01cbf6208bcc4f5ccbd5c7fb23b6131a6df9 Mon Sep 17 00:00:00 2001 From: mlogclub Date: Sat, 27 Jun 2026 17:14:29 +0800 Subject: [PATCH] feat: add condition configuration handling and improve branch summary display in workflow editor --- .../_components/node-config-panel.tsx | 4 +- .../_components/workflow-editor.tsx | 123 ++++++++++++------ 2 files changed, 87 insertions(+), 40 deletions(-) diff --git a/web/app/dashboard/ai-workflows/_components/node-config-panel.tsx b/web/app/dashboard/ai-workflows/_components/node-config-panel.tsx index 96c6f55..3a5d7b9 100644 --- a/web/app/dashboard/ai-workflows/_components/node-config-panel.tsx +++ b/web/app/dashboard/ai-workflows/_components/node-config-panel.tsx @@ -31,6 +31,7 @@ export type WorkflowBranchSummary = { targetNodeId: string targetName: string conditionLabel: string + conditionSet: boolean isDefault: boolean } @@ -555,7 +556,8 @@ function decodeConditionRight(value: string, variable?: WorkflowVariableRef) { function normalizeBranch(branch: WorkflowConditionBranch): WorkflowConditionBranch { if (branch.default) { - const { condition: _condition, ...rest } = branch + const rest = { ...branch } + delete rest.condition return rest } return { diff --git a/web/app/dashboard/ai-workflows/_components/workflow-editor.tsx b/web/app/dashboard/ai-workflows/_components/workflow-editor.tsx index 3f37c83..4af018e 100644 --- a/web/app/dashboard/ai-workflows/_components/workflow-editor.tsx +++ b/web/app/dashboard/ai-workflows/_components/workflow-editor.tsx @@ -31,6 +31,7 @@ import { import { AlertCircleIcon, CheckCircle2Icon, + GitBranchIcon, PanelLeftCloseIcon, PanelLeftOpenIcon, PlusIcon, @@ -1095,6 +1096,7 @@ function getBranchSummaries( targetNodeId: branch.targetNodeId, targetName: target?.data.name ?? target?.data.title ?? branch.targetNodeId, conditionLabel: branch.condition ? formatConditionLabel(branch.condition, nodes, nodeSpecs) : "无条件匹配", + conditionSet: Boolean(branch.default || (branch.condition && isConditionConfigured(branch.condition))), isDefault: Boolean(branch.default), } }) @@ -1119,6 +1121,16 @@ function formatConditionLabel( return `${left} ${operator} ${formatConditionRight(condition.right, variable)}` } +function isConditionConfigured(condition: WorkflowCondition) { + if (!condition.left?.nodeId || !condition.left.field || !condition.operator) { + return false + } + if (["exists", "not_exists", "truthy", "is_true", "falsy", "is_false"].includes(condition.operator)) { + return true + } + return condition.right !== undefined && condition.right !== null && condition.right !== "" +} + function formatConditionRight(value: unknown, variable?: WorkflowVariableSpec) { if (value === undefined || value === null || value === "") { return "未填写比较值" @@ -1272,11 +1284,13 @@ function WorkflowNodeHandle({ type, position, className, + showIcon = true, }: { id?: string type: "source" | "target" position: Position className?: string + showIcon?: boolean }) { return ( - + {showIcon ? : null} ) } @@ -1362,12 +1376,19 @@ function WorkflowCanvasNode({ id, data, selected }: NodeProps) "flex items-center justify-center opacity-0 transition-all duration-150", showHandles ? "pointer-events-auto opacity-100" : "pointer-events-none" ) + const conditionBranchHandleClassName = cn( + "!z-[1] !size-4 !rounded-none !border-none !bg-transparent !outline-none", + "after:absolute after:right-1.5 after:top-1 after:h-2 after:w-0.5 after:rounded-sm after:bg-muted-foreground/45", + "transition-all hover:scale-125" + ) if (isConditionNode) { const branches = data.branchSummaries ?? [] + const caseBranches = branches.filter((branch) => !branch.isDefault) + const defaultBranch = branches.find((branch) => branch.isDefault) return (
) -
-
+
+
- {hasIssue ? ( - - ) : ( - - )} +
-
-
{data.name ?? data.title}
-
条件分支
+
+ {data.name ?? data.title}
-
- {branches.length > 0 ? branches.map((branch, index) => ( -
- - {branch.isDefault ? "ELSE" : index === 0 ? "IF" : "ELIF"} - -
-
{branch.conditionLabel}
-
- {branch.targetNodeId ? `连接到:${branch.targetName}` : "未连接目标节点"} +
+ {caseBranches.length > 0 ? caseBranches.map((branch, index) => ( +
+
+
+
+ {caseBranches.length > 1 ? `CASE ${index + 1}` : ""} +
+
+ {index === 0 ? "IF" : "ELIF"} +
+
+ +
+
+
+ + {branch.conditionSet ? branch.conditionLabel : "条件未配置"} +
-
)) : ( -
当前还没有分支
+
+ 条件未配置 +
)} +
+
ELSE
+ {defaultBranch ? ( + + ) : null} +