Merge branch 'feat/attachments' into deploy/dev

This commit is contained in:
Joel 2024-10-17 11:30:03 +08:00
commit 66d9d1f759
4 changed files with 45 additions and 17 deletions

View File

@ -8,7 +8,10 @@ const i18nPrefix = 'workflow.errorMsg'
const nodeDefault: NodeDefault<ListFilterNodeType> = { const nodeDefault: NodeDefault<ListFilterNodeType> = {
defaultValue: { defaultValue: {
variable: [], variable: [],
filter_by: [], filter_by: {
enabled: false,
conditions: [],
},
order_by: { order_by: {
enabled: false, enabled: false,
key: '', key: '',
@ -37,14 +40,14 @@ const nodeDefault: NodeDefault<ListFilterNodeType> = {
errorMessages = t(`${i18nPrefix}.fieldRequired`, { field: t('workflow.nodes.listFilter.inputVar') }) errorMessages = t(`${i18nPrefix}.fieldRequired`, { field: t('workflow.nodes.listFilter.inputVar') })
// Check filter condition // Check filter condition
if (!errorMessages) { if (!errorMessages && filter_by?.enabled) {
if (var_type === VarType.arrayFile && !filter_by[0]?.key) if (var_type === VarType.arrayFile && !filter_by.conditions[0]?.key)
errorMessages = t(`${i18nPrefix}.fieldRequired`, { field: t('workflow.nodes.listFilter.filterConditionKey') }) 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') }) 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') }) errorMessages = t(`${i18nPrefix}.fieldRequired`, { field: t('workflow.nodes.listFilter.filterConditionComparisonValue') })
} }

View File

@ -30,6 +30,7 @@ const Panel: FC<NodePanelProps<ListFilterNodeType>> = ({
hasSubVariable, hasSubVariable,
handleVarChanges, handleVarChanges,
filterVar, filterVar,
handleFilterEnabledChange,
handleFilterChange, handleFilterChange,
handleLimitChange, handleLimitChange,
handleOrderByEnabledChange, handleOrderByEnabledChange,
@ -56,15 +57,26 @@ const Panel: FC<NodePanelProps<ListFilterNodeType>> = ({
<Field <Field
title={t(`${i18nPrefix}.filterCondition`)} title={t(`${i18nPrefix}.filterCondition`)}
isSubTitle operations={
<Switch
defaultValue={inputs.filter_by?.enabled}
onChange={handleFilterEnabledChange}
size='md'
disabled={readOnly}
/>
}
> >
<FilterCondition {inputs.filter_by?.enabled
condition={inputs.filter_by[0]} ? (
onChange={handleFilterChange} <FilterCondition
varType={itemVarType} condition={inputs.filter_by.conditions[0]}
hasSubVariable={hasSubVariable} onChange={handleFilterChange}
readOnly={readOnly} varType={itemVarType}
/> hasSubVariable={hasSubVariable}
readOnly={readOnly}
/>
)
: null}
</Field> </Field>
<Split /> <Split />
<Field <Field

View File

@ -21,7 +21,10 @@ export type ListFilterNodeType = CommonNodeType & {
variable: ValueSelector variable: ValueSelector
var_type: VarType // Cache for the type of output variable var_type: VarType // Cache for the type of output variable
item_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: { order_by: {
enabled: boolean enabled: boolean
key: ValueSelector | string key: ValueSelector | string

View File

@ -80,8 +80,8 @@ const useConfig = (id: string, payload: ListFilterNodeType) => {
draft.var_type = varType draft.var_type = varType
draft.item_var_type = itemVarType draft.item_var_type = itemVarType
draft.filter_by = [{ draft.filter_by.conditions = [{
key: (isFileArray && !draft.filter_by[0]?.key) ? 'name' : '', key: (isFileArray && !draft.filter_by.conditions[0]?.key) ? 'name' : '',
comparison_operator: getOperators(itemVarType, isFileArray ? { key: 'name' } : undefined)[0], comparison_operator: getOperators(itemVarType, isFileArray ? { key: 'name' } : undefined)[0],
value: '', value: '',
}] }]
@ -96,9 +96,18 @@ const useConfig = (id: string, payload: ListFilterNodeType) => {
return [VarType.arrayNumber, VarType.arrayString, VarType.arrayFile].includes(varPayload.type) 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 handleFilterChange = useCallback((condition: Condition) => {
const newInputs = produce(inputs, (draft) => { const newInputs = produce(inputs, (draft) => {
draft.filter_by[0] = condition draft.filter_by.conditions[0] = condition
}) })
setInputs(newInputs) setInputs(newInputs)
}, [inputs, setInputs]) }, [inputs, setInputs])
@ -147,6 +156,7 @@ const useConfig = (id: string, payload: ListFilterNodeType) => {
itemVarTypeShowName, itemVarTypeShowName,
hasSubVariable, hasSubVariable,
handleVarChanges, handleVarChanges,
handleFilterEnabledChange,
handleFilterChange, handleFilterChange,
handleLimitChange, handleLimitChange,
handleOrderByEnabledChange, handleOrderByEnabledChange,