diff --git a/web/app/components/workflow/nodes/loop/components/loop-variables/item.tsx b/web/app/components/workflow/nodes/loop/components/loop-variables/item.tsx index 0e8650d743..db63286efb 100644 --- a/web/app/components/workflow/nodes/loop/components/loop-variables/item.tsx +++ b/web/app/components/workflow/nodes/loop/components/loop-variables/item.tsx @@ -12,6 +12,7 @@ import type { } from '@/app/components/workflow/nodes/loop/types' import { checkKeys, replaceSpaceWithUnderscreInVarNameInput } from '@/utils/var' import Toast from '@/app/components/base/toast' +import { ValueType, VarType } from '@/app/components/workflow/types' type ItemProps = { item: LoopVariable @@ -42,12 +43,25 @@ const Item = ({ handleUpdateLoopVariable(item.id, { label: e.target.value }) }, [item.id, handleUpdateLoopVariable]) + const getDefaultValue = useCallback((varType: VarType, valueType: ValueType) => { + if(valueType === ValueType.variable) + return undefined + switch (varType) { + case VarType.boolean: + return 'false' + case VarType.arrayBoolean: + return ['false'] + default: + return undefined + } + }, []) + const handleUpdateItemVarType = useCallback((value: any) => { - handleUpdateLoopVariable(item.id, { var_type: value, value: undefined }) + handleUpdateLoopVariable(item.id, { var_type: value, value: getDefaultValue(value, item.value_type) }) }, [item.id, handleUpdateLoopVariable]) const handleUpdateItemValueType = useCallback((value: any) => { - handleUpdateLoopVariable(item.id, { value_type: value, value: undefined }) + handleUpdateLoopVariable(item.id, { value_type: value, value: getDefaultValue(item.var_type, value) }) }, [item.id, handleUpdateLoopVariable]) const handleUpdateItemValue = useCallback((value: any) => {