diff --git a/web/app/components/workflow/nodes/list-operator/default.ts b/web/app/components/workflow/nodes/list-operator/default.ts index 0cd17b6075..a7d411420c 100644 --- a/web/app/components/workflow/nodes/list-operator/default.ts +++ b/web/app/components/workflow/nodes/list-operator/default.ts @@ -8,7 +8,10 @@ const i18nPrefix = 'workflow.errorMsg' const nodeDefault: NodeDefault = { defaultValue: { variable: [], - filter_by: [], + filter_by: { + enabled: false, + conditions: [], + }, order_by: { enabled: false, key: '', @@ -37,14 +40,14 @@ const nodeDefault: NodeDefault = { errorMessages = t(`${i18nPrefix}.fieldRequired`, { field: t('workflow.nodes.listFilter.inputVar') }) // Check filter condition - if (!errorMessages) { - if (var_type === VarType.arrayFile && !filter_by[0]?.key) + if (!errorMessages && filter_by?.enabled) { + if (var_type === VarType.arrayFile && !filter_by.conditions[0]?.key) errorMessages = t(`${i18nPrefix}.fieldRequired`, { field: t('workflow.nodes.listFilter.filterConditionKey') }) - if (!errorMessages && !filter_by[0]?.comparison_operator) + if (!errorMessages && !filter_by.conditions[0]?.comparison_operator) errorMessages = t(`${i18nPrefix}.fieldRequired`, { field: t('workflow.nodes.listFilter.filterConditionComparisonOperator') }) - if (!errorMessages && !comparisonOperatorNotRequireValue(filter_by[0]?.comparison_operator) && !filter_by[0]?.value) + if (!errorMessages && !comparisonOperatorNotRequireValue(filter_by.conditions[0]?.comparison_operator) && !filter_by.conditions[0]?.value) errorMessages = t(`${i18nPrefix}.fieldRequired`, { field: t('workflow.nodes.listFilter.filterConditionComparisonValue') }) } diff --git a/web/app/components/workflow/nodes/list-operator/panel.tsx b/web/app/components/workflow/nodes/list-operator/panel.tsx index 9ae6991a13..a6b53196d9 100644 --- a/web/app/components/workflow/nodes/list-operator/panel.tsx +++ b/web/app/components/workflow/nodes/list-operator/panel.tsx @@ -30,6 +30,7 @@ const Panel: FC> = ({ hasSubVariable, handleVarChanges, filterVar, + handleFilterEnabledChange, handleFilterChange, handleLimitChange, handleOrderByEnabledChange, @@ -56,15 +57,26 @@ const Panel: FC> = ({ + } > - + {inputs.filter_by?.enabled + ? ( + + ) + : null} { draft.var_type = varType draft.item_var_type = itemVarType - draft.filter_by = [{ - key: (isFileArray && !draft.filter_by[0]?.key) ? 'name' : '', + draft.filter_by.conditions = [{ + key: (isFileArray && !draft.filter_by.conditions[0]?.key) ? 'name' : '', comparison_operator: getOperators(itemVarType, isFileArray ? { key: 'name' } : undefined)[0], value: '', }] @@ -96,9 +96,18 @@ const useConfig = (id: string, payload: ListFilterNodeType) => { return [VarType.arrayNumber, VarType.arrayString, VarType.arrayFile].includes(varPayload.type) }, []) + const handleFilterEnabledChange = useCallback((enabled: boolean) => { + const newInputs = produce(inputs, (draft) => { + draft.filter_by.enabled = enabled + if (enabled && !draft.filter_by.conditions) + draft.filter_by.conditions = [] + }) + setInputs(newInputs) + }, [hasSubVariable, inputs, setInputs]) + const handleFilterChange = useCallback((condition: Condition) => { const newInputs = produce(inputs, (draft) => { - draft.filter_by[0] = condition + draft.filter_by.conditions[0] = condition }) setInputs(newInputs) }, [inputs, setInputs]) @@ -147,6 +156,7 @@ const useConfig = (id: string, payload: ListFilterNodeType) => { itemVarTypeShowName, hasSubVariable, handleVarChanges, + handleFilterEnabledChange, handleFilterChange, handleLimitChange, handleOrderByEnabledChange,