mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-19 23:19:15 +08:00
feat: condition operation
This commit is contained in:
parent
20922fde1c
commit
ae098ad121
@ -26,6 +26,7 @@ type ConditionItemProps = {
|
|||||||
disabled?: boolean
|
disabled?: boolean
|
||||||
caseId: string
|
caseId: string
|
||||||
condition: Condition
|
condition: Condition
|
||||||
|
file?: { key: string }
|
||||||
onRemoveCondition: HandleRemoveCondition
|
onRemoveCondition: HandleRemoveCondition
|
||||||
onUpdateCondition: HandleUpdateCondition
|
onUpdateCondition: HandleUpdateCondition
|
||||||
nodesOutputVars: NodeOutPutVar[]
|
nodesOutputVars: NodeOutPutVar[]
|
||||||
@ -36,6 +37,7 @@ const ConditionItem = ({
|
|||||||
disabled,
|
disabled,
|
||||||
caseId,
|
caseId,
|
||||||
condition,
|
condition,
|
||||||
|
file,
|
||||||
onRemoveCondition,
|
onRemoveCondition,
|
||||||
onUpdateCondition,
|
onUpdateCondition,
|
||||||
nodesOutputVars,
|
nodesOutputVars,
|
||||||
@ -88,6 +90,7 @@ const ConditionItem = ({
|
|||||||
varType={condition.varType}
|
varType={condition.varType}
|
||||||
value={condition.comparison_operator}
|
value={condition.comparison_operator}
|
||||||
onSelect={handleUpdateConditionOperator}
|
onSelect={handleUpdateConditionOperator}
|
||||||
|
file={file}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{
|
{
|
||||||
|
@ -19,12 +19,14 @@ const i18nPrefix = 'workflow.nodes.ifElse'
|
|||||||
type ConditionOperatorProps = {
|
type ConditionOperatorProps = {
|
||||||
disabled?: boolean
|
disabled?: boolean
|
||||||
varType: VarType
|
varType: VarType
|
||||||
|
file?: { key: string }
|
||||||
value?: string
|
value?: string
|
||||||
onSelect: (value: ComparisonOperator) => void
|
onSelect: (value: ComparisonOperator) => void
|
||||||
}
|
}
|
||||||
const ConditionOperator = ({
|
const ConditionOperator = ({
|
||||||
disabled,
|
disabled,
|
||||||
varType,
|
varType,
|
||||||
|
file,
|
||||||
value,
|
value,
|
||||||
onSelect,
|
onSelect,
|
||||||
}: ConditionOperatorProps) => {
|
}: ConditionOperatorProps) => {
|
||||||
@ -32,13 +34,13 @@ const ConditionOperator = ({
|
|||||||
const [open, setOpen] = useState(false)
|
const [open, setOpen] = useState(false)
|
||||||
|
|
||||||
const options = useMemo(() => {
|
const options = useMemo(() => {
|
||||||
return getOperators(varType).map((o) => {
|
return getOperators(varType, file).map((o) => {
|
||||||
return {
|
return {
|
||||||
label: isComparisonOperatorNeedTranslate(o) ? t(`${i18nPrefix}.comparisonOperator.${o}`) : o,
|
label: isComparisonOperatorNeedTranslate(o) ? t(`${i18nPrefix}.comparisonOperator.${o}`) : o,
|
||||||
value: o,
|
value: o,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}, [t, varType])
|
}, [t, varType, file])
|
||||||
const selectedOption = options.find(o => o.value === value)
|
const selectedOption = options.find(o => o.value === value)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -21,6 +21,7 @@ type ConditionListProps = {
|
|||||||
nodesOutputVars: NodeOutPutVar[]
|
nodesOutputVars: NodeOutPutVar[]
|
||||||
availableNodes: Node[]
|
availableNodes: Node[]
|
||||||
numberVariables: NodeOutPutVar[]
|
numberVariables: NodeOutPutVar[]
|
||||||
|
varsIsVarFileAttribute: Record<string, boolean>
|
||||||
}
|
}
|
||||||
const ConditionList = ({
|
const ConditionList = ({
|
||||||
disabled,
|
disabled,
|
||||||
@ -31,6 +32,7 @@ const ConditionList = ({
|
|||||||
nodesOutputVars,
|
nodesOutputVars,
|
||||||
availableNodes,
|
availableNodes,
|
||||||
numberVariables,
|
numberVariables,
|
||||||
|
varsIsVarFileAttribute,
|
||||||
}: ConditionListProps) => {
|
}: ConditionListProps) => {
|
||||||
const { conditions, logical_operator } = caseItem
|
const { conditions, logical_operator } = caseItem
|
||||||
|
|
||||||
@ -65,6 +67,7 @@ const ConditionList = ({
|
|||||||
nodesOutputVars={nodesOutputVars}
|
nodesOutputVars={nodesOutputVars}
|
||||||
availableNodes={availableNodes}
|
availableNodes={availableNodes}
|
||||||
numberVariables={numberVariables}
|
numberVariables={numberVariables}
|
||||||
|
file={varsIsVarFileAttribute[condition.id] ? { key: condition.variable_selector.slice(-1)[0] } : undefined}
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,7 @@ const Panel: FC<NodePanelProps<IfElseNodeType>> = ({
|
|||||||
handleUpdateConditionLogicalOperator,
|
handleUpdateConditionLogicalOperator,
|
||||||
nodesOutputVars,
|
nodesOutputVars,
|
||||||
availableNodes,
|
availableNodes,
|
||||||
|
varsIsVarFileAttribute,
|
||||||
} = useConfig(id, data)
|
} = useConfig(id, data)
|
||||||
const [willDeleteCaseId, setWillDeleteCaseId] = useState('')
|
const [willDeleteCaseId, setWillDeleteCaseId] = useState('')
|
||||||
const cases = inputs.cases || []
|
const cases = inputs.cases || []
|
||||||
@ -93,6 +94,7 @@ const Panel: FC<NodePanelProps<IfElseNodeType>> = ({
|
|||||||
nodesOutputVars={nodesOutputVars}
|
nodesOutputVars={nodesOutputVars}
|
||||||
availableNodes={availableNodes}
|
availableNodes={availableNodes}
|
||||||
numberVariables={getAvailableVars(id, '', filterNumberVar)}
|
numberVariables={getAvailableVars(id, '', filterNumberVar)}
|
||||||
|
varsIsVarFileAttribute={varsIsVarFileAttribute}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
@ -190,6 +190,7 @@ const useConfig = (id: string, payload: IfElseNodeType) => {
|
|||||||
availableNodes: availableNodesWithParent,
|
availableNodes: availableNodesWithParent,
|
||||||
nodesOutputNumberVars: availableNumberVars,
|
nodesOutputNumberVars: availableNumberVars,
|
||||||
availableNumberNodes: availableNumberNodesWithParent,
|
availableNumberNodes: availableNumberNodesWithParent,
|
||||||
|
varsIsVarFileAttribute,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,6 +40,47 @@ export const getOperators = (type?: VarType, file?: { key: string }) => {
|
|||||||
ComparisonOperator.in,
|
ComparisonOperator.in,
|
||||||
ComparisonOperator.notIn,
|
ComparisonOperator.notIn,
|
||||||
]
|
]
|
||||||
|
case 'size':
|
||||||
|
return [
|
||||||
|
ComparisonOperator.largerThan,
|
||||||
|
ComparisonOperator.largerThanOrEqual,
|
||||||
|
ComparisonOperator.lessThan,
|
||||||
|
ComparisonOperator.lessThanOrEqual,
|
||||||
|
]
|
||||||
|
case 'extension':
|
||||||
|
return [
|
||||||
|
ComparisonOperator.is,
|
||||||
|
ComparisonOperator.isNot,
|
||||||
|
ComparisonOperator.contains,
|
||||||
|
ComparisonOperator.notContains,
|
||||||
|
]
|
||||||
|
case 'mimetype':
|
||||||
|
return [
|
||||||
|
ComparisonOperator.contains,
|
||||||
|
ComparisonOperator.notContains,
|
||||||
|
ComparisonOperator.startWith,
|
||||||
|
ComparisonOperator.endWith,
|
||||||
|
ComparisonOperator.is,
|
||||||
|
ComparisonOperator.isNot,
|
||||||
|
ComparisonOperator.empty,
|
||||||
|
ComparisonOperator.notEmpty,
|
||||||
|
]
|
||||||
|
case 'transfer_method':
|
||||||
|
return [
|
||||||
|
ComparisonOperator.in,
|
||||||
|
ComparisonOperator.notIn,
|
||||||
|
]
|
||||||
|
case 'url':
|
||||||
|
return [
|
||||||
|
ComparisonOperator.contains,
|
||||||
|
ComparisonOperator.notContains,
|
||||||
|
ComparisonOperator.startWith,
|
||||||
|
ComparisonOperator.endWith,
|
||||||
|
ComparisonOperator.is,
|
||||||
|
ComparisonOperator.isNot,
|
||||||
|
ComparisonOperator.empty,
|
||||||
|
ComparisonOperator.notEmpty,
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
@ -387,6 +387,8 @@ const translation = {
|
|||||||
'not empty': 'is not empty',
|
'not empty': 'is not empty',
|
||||||
'null': 'is null',
|
'null': 'is null',
|
||||||
'not null': 'is not null',
|
'not null': 'is not null',
|
||||||
|
'in': 'in',
|
||||||
|
'not in': 'not in',
|
||||||
},
|
},
|
||||||
enterValue: 'Enter value',
|
enterValue: 'Enter value',
|
||||||
addCondition: 'Add Condition',
|
addCondition: 'Add Condition',
|
||||||
|
@ -387,6 +387,8 @@ const translation = {
|
|||||||
'not empty': '不为空',
|
'not empty': '不为空',
|
||||||
'null': '空',
|
'null': '空',
|
||||||
'not null': '不为空',
|
'not null': '不为空',
|
||||||
|
'in': '在',
|
||||||
|
'not in': '不在',
|
||||||
},
|
},
|
||||||
enterValue: '输入值',
|
enterValue: '输入值',
|
||||||
addCondition: '添加条件',
|
addCondition: '添加条件',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user