mirror of
https://github.com/langgenius/dify.git
synced 2024-11-16 19:59:50 +08:00
Merge branch 'feat/attachments' into deploy/dev
This commit is contained in:
commit
66d9d1f759
|
@ -8,7 +8,10 @@ const i18nPrefix = 'workflow.errorMsg'
|
|||
const nodeDefault: NodeDefault<ListFilterNodeType> = {
|
||||
defaultValue: {
|
||||
variable: [],
|
||||
filter_by: [],
|
||||
filter_by: {
|
||||
enabled: false,
|
||||
conditions: [],
|
||||
},
|
||||
order_by: {
|
||||
enabled: false,
|
||||
key: '',
|
||||
|
@ -37,14 +40,14 @@ const nodeDefault: NodeDefault<ListFilterNodeType> = {
|
|||
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') })
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ const Panel: FC<NodePanelProps<ListFilterNodeType>> = ({
|
|||
hasSubVariable,
|
||||
handleVarChanges,
|
||||
filterVar,
|
||||
handleFilterEnabledChange,
|
||||
handleFilterChange,
|
||||
handleLimitChange,
|
||||
handleOrderByEnabledChange,
|
||||
|
@ -56,15 +57,26 @@ const Panel: FC<NodePanelProps<ListFilterNodeType>> = ({
|
|||
|
||||
<Field
|
||||
title={t(`${i18nPrefix}.filterCondition`)}
|
||||
isSubTitle
|
||||
operations={
|
||||
<Switch
|
||||
defaultValue={inputs.filter_by?.enabled}
|
||||
onChange={handleFilterEnabledChange}
|
||||
size='md'
|
||||
disabled={readOnly}
|
||||
/>
|
||||
}
|
||||
>
|
||||
{inputs.filter_by?.enabled
|
||||
? (
|
||||
<FilterCondition
|
||||
condition={inputs.filter_by[0]}
|
||||
condition={inputs.filter_by.conditions[0]}
|
||||
onChange={handleFilterChange}
|
||||
varType={itemVarType}
|
||||
hasSubVariable={hasSubVariable}
|
||||
readOnly={readOnly}
|
||||
/>
|
||||
)
|
||||
: null}
|
||||
</Field>
|
||||
<Split />
|
||||
<Field
|
||||
|
|
|
@ -21,7 +21,10 @@ export type ListFilterNodeType = CommonNodeType & {
|
|||
variable: ValueSelector
|
||||
var_type: VarType // Cache for the type of output variable
|
||||
item_var_type: VarType // Cache for the type of output variable
|
||||
filter_by: Condition[]
|
||||
filter_by: {
|
||||
enabled: boolean
|
||||
conditions: Condition[]
|
||||
}
|
||||
order_by: {
|
||||
enabled: boolean
|
||||
key: ValueSelector | string
|
||||
|
|
|
@ -80,8 +80,8 @@ const useConfig = (id: string, payload: ListFilterNodeType) => {
|
|||
|
||||
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,
|
||||
|
|
Loading…
Reference in New Issue
Block a user