mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-18 17:55:52 +08:00
feat: add check list filter value
This commit is contained in:
parent
b863dd7de2
commit
f6d0fd9848
@ -1,5 +1,6 @@
|
||||
import { BlockEnum } from '../../types'
|
||||
import type { NodeDefault } from '../../types'
|
||||
import { comparisonOperatorNotRequireValue } from '../if-else/utils'
|
||||
import { type ListFilterNodeType, OrderBy } from './types'
|
||||
import { ALL_CHAT_AVAILABLE_BLOCKS, ALL_COMPLETION_AVAILABLE_BLOCKS } from '@/app/components/workflow/constants'
|
||||
const i18nPrefix = 'workflow.errorMsg'
|
||||
@ -30,10 +31,19 @@ const nodeDefault: NodeDefault<ListFilterNodeType> = {
|
||||
},
|
||||
checkValid(payload: ListFilterNodeType, t: any) {
|
||||
let errorMessages = ''
|
||||
const { variable } = payload
|
||||
const { variable, filter_by } = payload
|
||||
|
||||
if (!errorMessages && !variable?.length)
|
||||
errorMessages = t(`${i18nPrefix}.fieldRequired`, { field: t('workflow.nodes.assigner.assignedVariable') })
|
||||
errorMessages = t(`${i18nPrefix}.fieldRequired`, { field: t('workflow.nodes.listFilter.inputVar') })
|
||||
|
||||
// Check filter condition
|
||||
if (!errorMessages) {
|
||||
if (!filter_by[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)
|
||||
errorMessages = t(`${i18nPrefix}.fieldRequired`, { field: t('workflow.nodes.listFilter.filterConditionComparisonValue') })
|
||||
}
|
||||
|
||||
return {
|
||||
isValid: !errorMessages,
|
||||
|
@ -4,7 +4,8 @@ import { useStoreApi } from 'reactflow'
|
||||
import type { ValueSelector, Var } from '../../types'
|
||||
import { VarType } from '../../types'
|
||||
import { getOperators } from '../if-else/utils'
|
||||
import type { Condition, Limit, ListFilterNodeType, OrderBy } from './types'
|
||||
import { OrderBy } from './types'
|
||||
import type { Condition, Limit, ListFilterNodeType } from './types'
|
||||
import useNodeCrud from '@/app/components/workflow/nodes/_base/hooks/use-node-crud'
|
||||
import {
|
||||
useIsChatMode,
|
||||
@ -80,10 +81,12 @@ const useConfig = (id: string, payload: ListFilterNodeType) => {
|
||||
draft.var_type = varType
|
||||
draft.item_var_type = itemVarType
|
||||
draft.filter_by = [{
|
||||
key: isFileArray ? 'name' : '',
|
||||
key: (isFileArray && !draft.filter_by[0].key) ? 'name' : '',
|
||||
comparison_operator: getOperators(itemVarType, isFileArray ? { key: 'name' } : undefined)[0],
|
||||
value: '',
|
||||
}]
|
||||
if (isFileArray && draft.order_by.enabled && !draft.order_by.key)
|
||||
draft.order_by.key = 'name'
|
||||
})
|
||||
setInputs(newInputs)
|
||||
}, [getType, inputs, setInputs])
|
||||
@ -110,9 +113,14 @@ const useConfig = (id: string, payload: ListFilterNodeType) => {
|
||||
const handleOrderByEnabledChange = useCallback((enabled: boolean) => {
|
||||
const newInputs = produce(inputs, (draft) => {
|
||||
draft.order_by.enabled = enabled
|
||||
if (enabled) {
|
||||
draft.order_by.value = OrderBy.ASC
|
||||
if (hasSubVariable && !draft.order_by.key)
|
||||
draft.order_by.key = 'name'
|
||||
}
|
||||
})
|
||||
setInputs(newInputs)
|
||||
}, [inputs, setInputs])
|
||||
}, [hasSubVariable, inputs, setInputs])
|
||||
|
||||
const handleOrderByKeyChange = useCallback((key: string) => {
|
||||
const newInputs = produce(inputs, (draft) => {
|
||||
|
@ -562,6 +562,8 @@ const translation = {
|
||||
listFilter: {
|
||||
inputVar: 'Input Variable',
|
||||
filterCondition: 'Filter Condition',
|
||||
filterConditionComparisonOperator: 'Filter Condition Comparison Operator',
|
||||
filterConditionComparisonValue: 'Filter Condition value',
|
||||
selectVariableKeyPlaceholder: 'Select sub variable key',
|
||||
limit: 'Limit',
|
||||
orderBy: 'Order by',
|
||||
|
@ -562,6 +562,8 @@ const translation = {
|
||||
listFilter: {
|
||||
inputVar: '输入变量',
|
||||
filterCondition: '过滤条件',
|
||||
filterConditionComparisonOperator: '过滤条件比较操作符',
|
||||
filterConditionComparisonValue: '过滤条件比较值',
|
||||
selectVariableKeyPlaceholder: '选择子变量的 Key',
|
||||
limit: '限制',
|
||||
orderBy: '排序',
|
||||
|
Loading…
x
Reference in New Issue
Block a user