mirror of https://github.com/langgenius/dify.git
feat: if node support bool
This commit is contained in:
parent
79bdb22f79
commit
9ac629bcf5
|
|
@ -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 = ({
|
|||
/>
|
||||
</div>
|
||||
{
|
||||
!comparisonOperatorNotRequireValue(condition.comparison_operator) && !isNotInput && condition.varType !== VarType.number && (
|
||||
!comparisonOperatorNotRequireValue(condition.comparison_operator) && !isNotInput && condition.varType !== VarType.number && condition.varType !== VarType.boolean && (
|
||||
<div className='max-h-[100px] overflow-y-auto border-t border-t-divider-subtle px-2 py-1'>
|
||||
<ConditionInput
|
||||
disabled={disabled}
|
||||
|
|
@ -269,6 +270,16 @@ const ConditionItem = ({
|
|||
</div>
|
||||
)
|
||||
}
|
||||
{
|
||||
!comparisonOperatorNotRequireValue(condition.comparison_operator) && !isNotInput && condition.varType === VarType.boolean && (
|
||||
<div className='p-1'>
|
||||
<BoolValue
|
||||
value={condition.value as boolean}
|
||||
onChange={handleUpdateConditionValue}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
{
|
||||
!comparisonOperatorNotRequireValue(condition.comparison_operator) && !isNotInput && condition.varType === VarType.number && (
|
||||
<div className='border-t border-t-divider-subtle px-2 py-1 pt-[3px]'>
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ const IfElseNode: FC<NodeProps<IfElseNodeType>> = (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<NodeProps<IfElseNodeType>> = (props) => {
|
|||
if (isEmptyRelatedOperator(condition.comparison_operator!))
|
||||
return true
|
||||
|
||||
return !!condition.value
|
||||
return typeof condition.value === 'boolean' ? true : !!condition.value
|
||||
}
|
||||
}, [])
|
||||
const conditionNotSet = (<div className='flex h-6 items-center space-x-1 rounded-md bg-workflow-block-parma-bg px-1 text-xs font-normal text-text-secondary'>
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue