mirror of
https://github.com/langgenius/dify.git
synced 2026-05-02 23:28:51 +08:00
fix : loop var default value
This commit is contained in:
parent
590c14c977
commit
269d34304e
@ -12,6 +12,7 @@ import type {
|
|||||||
} from '@/app/components/workflow/nodes/loop/types'
|
} from '@/app/components/workflow/nodes/loop/types'
|
||||||
import { checkKeys, replaceSpaceWithUnderscreInVarNameInput } from '@/utils/var'
|
import { checkKeys, replaceSpaceWithUnderscreInVarNameInput } from '@/utils/var'
|
||||||
import Toast from '@/app/components/base/toast'
|
import Toast from '@/app/components/base/toast'
|
||||||
|
import { ValueType, VarType } from '@/app/components/workflow/types'
|
||||||
|
|
||||||
type ItemProps = {
|
type ItemProps = {
|
||||||
item: LoopVariable
|
item: LoopVariable
|
||||||
@ -42,12 +43,25 @@ const Item = ({
|
|||||||
handleUpdateLoopVariable(item.id, { label: e.target.value })
|
handleUpdateLoopVariable(item.id, { label: e.target.value })
|
||||||
}, [item.id, handleUpdateLoopVariable])
|
}, [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) => {
|
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])
|
}, [item.id, handleUpdateLoopVariable])
|
||||||
|
|
||||||
const handleUpdateItemValueType = useCallback((value: any) => {
|
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])
|
}, [item.id, handleUpdateLoopVariable])
|
||||||
|
|
||||||
const handleUpdateItemValue = useCallback((value: any) => {
|
const handleUpdateItemValue = useCallback((value: any) => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user