From ff9d0516358751367fc6904eb89a2c119577a1f1 Mon Sep 17 00:00:00 2001 From: Joel Date: Mon, 28 Jul 2025 14:49:44 +0800 Subject: [PATCH] chore: fix if not value set value --- .../condition-list/condition-item.tsx | 2 +- .../workflow/nodes/if-else/use-config.ts | 2 +- .../components/bool-value.tsx | 18 ++++++++++++------ 3 files changed, 14 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 4bf2295158..df4f92ef1d 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 @@ -217,7 +217,7 @@ const ConditionItem = ({ const newCondition = produce(condition, (draft) => { draft.variable_selector = valueSelector draft.varType = resolvedVarType - draft.value = '' + draft.value = resolvedVarType === VarType.boolean ? 'false' : '' draft.comparison_operator = getOperators(resolvedVarType)[0] setTimeout(() => setControlPromptEditorRerenderKey(Date.now())) }) diff --git a/web/app/components/workflow/nodes/if-else/use-config.ts b/web/app/components/workflow/nodes/if-else/use-config.ts index 276d017b40..473b457e00 100644 --- a/web/app/components/workflow/nodes/if-else/use-config.ts +++ b/web/app/components/workflow/nodes/if-else/use-config.ts @@ -144,7 +144,7 @@ const useConfig = (id: string, payload: IfElseNodeType) => { varType: varItem.type, variable_selector: valueSelector, comparison_operator: getOperators(varItem.type, getIsVarFileAttribute(valueSelector) ? { key: valueSelector.slice(-1)[0] } : undefined)[0], - value: '', + value: varItem.type === VarType.boolean ? 'false' : '', }) } }) diff --git a/web/app/components/workflow/panel/chat-variable-panel/components/bool-value.tsx b/web/app/components/workflow/panel/chat-variable-panel/components/bool-value.tsx index 30618cfe8e..3de2b30975 100644 --- a/web/app/components/workflow/panel/chat-variable-panel/components/bool-value.tsx +++ b/web/app/components/workflow/panel/chat-variable-panel/components/bool-value.tsx @@ -1,31 +1,37 @@ 'use client' import type { FC } from 'react' -import React, { useCallback } from 'react' +import React, { useCallback, useMemo } from 'react' import OptionCard from '../../../nodes/_base/components/option-card' type Props = { - value: boolean - onChange: (value: boolean) => void + value: boolean | string + onChange: (value: string) => void } const BoolValue: FC = ({ value, onChange, }) => { + const booleanValue = useMemo(() => { + if(typeof value === 'boolean') + return value + return value === 'true' + }, [value]) const handleChange = useCallback((newValue: boolean) => { return () => { - onChange(newValue) + onChange(newValue.toString()) // the backend expects a string value: 'true' or 'false' } }, [onChange]) + return (