From 9ac629bcf57bcbab822dae9522507b7cf0021873 Mon Sep 17 00:00:00 2001 From: Joel Date: Tue, 8 Jul 2025 16:30:54 +0800 Subject: [PATCH] feat: if node support bool --- .../condition-list/condition-item.tsx | 19 +++++++++++++++---- .../if-else/components/condition-value.tsx | 5 ++++- .../workflow/nodes/if-else/node.tsx | 4 ++-- .../workflow/nodes/if-else/types.ts | 2 +- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/web/app/components/workflow/nodes/if-else/components/condition-list/condition-item.tsx b/web/app/components/workflow/nodes/if-else/components/condition-list/condition-item.tsx index ef94f7c82e..032daa7476 100644 --- a/web/app/components/workflow/nodes/if-else/components/condition-list/condition-item.tsx +++ b/web/app/components/workflow/nodes/if-else/components/condition-list/condition-item.tsx @@ -37,6 +37,7 @@ import { VarType } from '@/app/components/workflow/types' import cn from '@/utils/classnames' import { SimpleSelect as Select } from '@/app/components/base/select' import { Variable02 } from '@/app/components/base/icons/src/vender/solid/development' +import BoolValue from '@/app/components/workflow/panel/chat-variable-panel/components/bool-value' const optionNameI18NPrefix = 'workflow.nodes.ifElse.optionName' type ConditionItemProps = { @@ -133,12 +134,12 @@ const ConditionItem = ({ const isArrayValue = fileAttr?.key === 'transfer_method' || fileAttr?.key === 'type' - const handleUpdateConditionValue = useCallback((value: string) => { - if (value === condition.value || (isArrayValue && value === condition.value?.[0])) + const handleUpdateConditionValue = useCallback((value: string | boolean) => { + if (value === condition.value || (isArrayValue && value === (condition.value as string[])?.[0])) return const newCondition = { ...condition, - value: isArrayValue ? [value] : value, + value: isArrayValue ? [value as string] : value, } doUpdateCondition(newCondition) }, [condition, doUpdateCondition, isArrayValue]) @@ -257,7 +258,7 @@ const ConditionItem = ({ /> { - !comparisonOperatorNotRequireValue(condition.comparison_operator) && !isNotInput && condition.varType !== VarType.number && ( + !comparisonOperatorNotRequireValue(condition.comparison_operator) && !isNotInput && condition.varType !== VarType.number && condition.varType !== VarType.boolean && (
) } + { + !comparisonOperatorNotRequireValue(condition.comparison_operator) && !isNotInput && condition.varType === VarType.boolean && ( +
+ +
+ ) + } { !comparisonOperatorNotRequireValue(condition.comparison_operator) && !isNotInput && condition.varType === VarType.number && (
diff --git a/web/app/components/workflow/nodes/if-else/components/condition-value.tsx b/web/app/components/workflow/nodes/if-else/components/condition-value.tsx index 53dac65217..88caf11e4c 100644 --- a/web/app/components/workflow/nodes/if-else/components/condition-value.tsx +++ b/web/app/components/workflow/nodes/if-else/components/condition-value.tsx @@ -24,7 +24,7 @@ type ConditionValueProps = { variableSelector: string[] labelName?: string operator: ComparisonOperator - value: string | string[] + value: string | string[] | boolean } const ConditionValue = ({ variableSelector, @@ -48,6 +48,9 @@ const ConditionValue = ({ if (Array.isArray(value)) // transfer method return value[0] + if(value === true || value === false) + return value ? 'True' : 'False' + return value.replace(/{{#([^#]*)#}}/g, (a, b) => { const arr: string[] = b.split('.') if (isSystemVar(arr)) diff --git a/web/app/components/workflow/nodes/if-else/node.tsx b/web/app/components/workflow/nodes/if-else/node.tsx index 6bc2e5c7a0..c77286d3cd 100644 --- a/web/app/components/workflow/nodes/if-else/node.tsx +++ b/web/app/components/workflow/nodes/if-else/node.tsx @@ -26,7 +26,7 @@ const IfElseNode: FC> = (props) => { if (isEmptyRelatedOperator(c.comparison_operator!)) return true - return !!c.value + return typeof c.value === 'boolean' ? true : !!c.value }) return isSet } @@ -34,7 +34,7 @@ const IfElseNode: FC> = (props) => { if (isEmptyRelatedOperator(condition.comparison_operator!)) return true - return !!condition.value + return typeof condition.value === 'boolean' ? true : !!condition.value } }, []) const conditionNotSet = (
diff --git a/web/app/components/workflow/nodes/if-else/types.ts b/web/app/components/workflow/nodes/if-else/types.ts index 0559b949b5..5b9128860e 100644 --- a/web/app/components/workflow/nodes/if-else/types.ts +++ b/web/app/components/workflow/nodes/if-else/types.ts @@ -41,7 +41,7 @@ export type Condition = { variable_selector?: ValueSelector key?: string // sub variable key comparison_operator?: ComparisonOperator - value: string | string[] + value: string | string[] | boolean numberVarType?: NumberVarType sub_variable_condition?: CaseItem }