fix: Update condition items to support variable type acquisition (#22414)
This commit is contained in:
@@ -37,6 +37,8 @@ import { VarType } from '@/app/components/workflow/types'
|
|||||||
import cn from '@/utils/classnames'
|
import cn from '@/utils/classnames'
|
||||||
import { SimpleSelect as Select } from '@/app/components/base/select'
|
import { SimpleSelect as Select } from '@/app/components/base/select'
|
||||||
import { Variable02 } from '@/app/components/base/icons/src/vender/solid/development'
|
import { Variable02 } from '@/app/components/base/icons/src/vender/solid/development'
|
||||||
|
import { getVarType } from '@/app/components/workflow/nodes/_base/components/variable/utils'
|
||||||
|
import { useIsChatMode } from '@/app/components/workflow/hooks/use-workflow'
|
||||||
const optionNameI18NPrefix = 'workflow.nodes.ifElse.optionName'
|
const optionNameI18NPrefix = 'workflow.nodes.ifElse.optionName'
|
||||||
|
|
||||||
type ConditionItemProps = {
|
type ConditionItemProps = {
|
||||||
@@ -82,7 +84,7 @@ const ConditionItem = ({
|
|||||||
filterVar,
|
filterVar,
|
||||||
}: ConditionItemProps) => {
|
}: ConditionItemProps) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
const isChatMode = useIsChatMode()
|
||||||
const [isHovered, setIsHovered] = useState(false)
|
const [isHovered, setIsHovered] = useState(false)
|
||||||
const [open, setOpen] = useState(false)
|
const [open, setOpen] = useState(false)
|
||||||
|
|
||||||
@@ -120,6 +122,7 @@ const ConditionItem = ({
|
|||||||
}, [condition, doUpdateCondition])
|
}, [condition, doUpdateCondition])
|
||||||
|
|
||||||
const isSubVariable = condition.varType === VarType.arrayFile && [ComparisonOperator.contains, ComparisonOperator.notContains, ComparisonOperator.allOf].includes(condition.comparison_operator!)
|
const isSubVariable = condition.varType === VarType.arrayFile && [ComparisonOperator.contains, ComparisonOperator.notContains, ComparisonOperator.allOf].includes(condition.comparison_operator!)
|
||||||
|
|
||||||
const fileAttr = useMemo(() => {
|
const fileAttr = useMemo(() => {
|
||||||
if (file)
|
if (file)
|
||||||
return file
|
return file
|
||||||
@@ -194,15 +197,21 @@ const ConditionItem = ({
|
|||||||
}, [caseId, condition, conditionId, isSubVariableKey, onRemoveCondition, onRemoveSubVariableCondition])
|
}, [caseId, condition, conditionId, isSubVariableKey, onRemoveCondition, onRemoveSubVariableCondition])
|
||||||
|
|
||||||
const handleVarChange = useCallback((valueSelector: ValueSelector, varItem: Var) => {
|
const handleVarChange = useCallback((valueSelector: ValueSelector, varItem: Var) => {
|
||||||
|
const resolvedVarType = getVarType({
|
||||||
|
valueSelector,
|
||||||
|
availableNodes,
|
||||||
|
isChatMode,
|
||||||
|
})
|
||||||
|
|
||||||
const newCondition = produce(condition, (draft) => {
|
const newCondition = produce(condition, (draft) => {
|
||||||
draft.variable_selector = valueSelector
|
draft.variable_selector = valueSelector
|
||||||
draft.varType = varItem.type
|
draft.varType = resolvedVarType
|
||||||
draft.value = ''
|
draft.value = ''
|
||||||
draft.comparison_operator = getOperators(varItem.type)[0]
|
draft.comparison_operator = getOperators(resolvedVarType)[0]
|
||||||
})
|
})
|
||||||
doUpdateCondition(newCondition)
|
doUpdateCondition(newCondition)
|
||||||
setOpen(false)
|
setOpen(false)
|
||||||
}, [condition, doUpdateCondition])
|
}, [condition, doUpdateCondition, availableNodes, isChatMode])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={cn('mb-1 flex last-of-type:mb-0', className)}>
|
<div className={cn('mb-1 flex last-of-type:mb-0', className)}>
|
||||||
|
Reference in New Issue
Block a user