diff --git a/web/app/components/workflow/nodes/list-operator/components/filter-condition.tsx b/web/app/components/workflow/nodes/list-operator/components/filter-condition.tsx index a7ea6d78e7..ac303acfd7 100644 --- a/web/app/components/workflow/nodes/list-operator/components/filter-condition.tsx +++ b/web/app/components/workflow/nodes/list-operator/components/filter-condition.tsx @@ -15,18 +15,21 @@ import cn from '@/utils/classnames' import { VarType } from '../../../types' const optionNameI18NPrefix = 'workflow.nodes.ifElse.optionName' +import { getConditionValueAsString } from '@/app/components/workflow/nodes/utils' const VAR_INPUT_SUPPORTED_KEYS: Record = { name: VarType.string, url: VarType.string, extension: VarType.string, mime_type: VarType.string, - related_id: VarType.number, + related_id: VarType.string, + size: VarType.number, } type Props = { condition: Condition onChange: (condition: Condition) => void + varType: VarType hasSubVariable: boolean readOnly: boolean nodeId: string @@ -34,6 +37,7 @@ type Props = { const FilterCondition: FC = ({ condition = { key: '', comparison_operator: ComparisonOperator.equal, value: '' }, + varType, onChange, hasSubVariable, readOnly, @@ -42,7 +46,7 @@ const FilterCondition: FC = ({ const { t } = useTranslation() const [isFocus, setIsFocus] = useState(false) - const expectedVarType = VAR_INPUT_SUPPORTED_KEYS[condition.key] + const expectedVarType = condition.key ? VAR_INPUT_SUPPORTED_KEYS[condition.key] : varType const supportVariableInput = !!expectedVarType const { availableVars, availableNodesWithParent } = useAvailableVarList(nodeId, { @@ -93,6 +97,59 @@ const FilterCondition: FC = ({ }) }, [onChange, expectedVarType]) + // Extract input rendering logic to avoid nested ternary + let inputElement: React.ReactNode = null + if (!comparisonOperatorNotRequireValue(condition.comparison_operator)) { + if (isSelect) { + inputElement = ( + + ) + } + else { + inputElement = ( + handleChange('value')(e.target.value)} + readOnly={readOnly} + /> + ) + } + } + return (
{hasSubVariable && ( @@ -111,46 +168,7 @@ const FilterCondition: FC = ({ file={hasSubVariable ? { key: condition.key } : undefined} disabled={readOnly} /> - {!comparisonOperatorNotRequireValue(condition.comparison_operator) && ( - <> - {isSelect ? ( - - ) : ( - handleChange('value')(e.target.value)} - readOnly={readOnly} - /> - )} - - )} + {inputElement}
) diff --git a/web/app/components/workflow/nodes/utils.ts b/web/app/components/workflow/nodes/utils.ts index 262dde62e7..9e7b1ada6b 100644 --- a/web/app/components/workflow/nodes/utils.ts +++ b/web/app/components/workflow/nodes/utils.ts @@ -28,3 +28,13 @@ export const findVariableWhenOnLLMVision = (valueSelector: ValueSelector, availa formType, } } + +export const getConditionValueAsString = (condition: { value: any }) => { + if (Array.isArray(condition.value)) + return condition.value[0] ?? '' + + if (typeof condition.value === 'number') + return String(condition.value) + + return condition.value ?? '' +}