diff --git a/web/app/components/workflow/constants.ts b/web/app/components/workflow/constants.ts index e786579e14..0eaad601ef 100644 --- a/web/app/components/workflow/constants.ts +++ b/web/app/components/workflow/constants.ts @@ -438,7 +438,23 @@ export const FILE_STRUCT: Var[] = [ }, { variable: 'type', - type: VarType.number, + type: VarType.string, + }, + { + variable: 'extension', + type: VarType.string, + }, + { + variable: 'mimetype', + type: VarType.string, + }, + { + variable: 'transfer_method', + type: VarType.string, + }, + { + variable: 'url', + type: VarType.string, }, ] diff --git a/web/app/components/workflow/nodes/if-else/types.ts b/web/app/components/workflow/nodes/if-else/types.ts index 693dce1784..41406d977d 100644 --- a/web/app/components/workflow/nodes/if-else/types.ts +++ b/web/app/components/workflow/nodes/if-else/types.ts @@ -28,6 +28,8 @@ export enum ComparisonOperator { lessThanOrEqual = '≤', isNull = 'is null', isNotNull = 'is not null', + in = 'in', + notIn = 'not in', } export type Condition = { @@ -49,6 +51,7 @@ export type IfElseNodeType = CommonNodeType & { logical_operator?: LogicalOperator conditions?: Condition[] cases: CaseItem[] + isInIteration: boolean } export type HandleAddCondition = (caseId: string, valueSelector: ValueSelector, varItem: Var) => void diff --git a/web/app/components/workflow/nodes/if-else/use-config.ts b/web/app/components/workflow/nodes/if-else/use-config.ts index d3e2785986..55362bab3b 100644 --- a/web/app/components/workflow/nodes/if-else/use-config.ts +++ b/web/app/components/workflow/nodes/if-else/use-config.ts @@ -1,4 +1,4 @@ -import { useCallback } from 'react' +import { useCallback, useMemo } from 'react' import produce from 'immer' import { v4 as uuid4 } from 'uuid' import type { @@ -18,6 +18,7 @@ import { branchNameCorrect, getOperators, } from './utils' +import useIsVarFileAttribute from './use-is-var-file-attribute' import useNodeCrud from '@/app/components/workflow/nodes/_base/hooks/use-node-crud' import { useEdgesInteractions, @@ -46,6 +47,23 @@ const useConfig = (id: string, payload: IfElseNodeType) => { return varPayload.type === VarType.number }, []) + const { + getIsVarFileAttribute, + } = useIsVarFileAttribute({ + nodeId: id, + isInIteration: payload.isInIteration, + }) + + const varsIsVarFileAttribute = useMemo(() => { + const conditions: Record = {} + inputs.cases?.forEach((c) => { + c.conditions.forEach((condition) => { + conditions[condition.id] = getIsVarFileAttribute(condition.variable_selector) + }) + }) + return conditions + }, [inputs.cases, getIsVarFileAttribute]) + const { availableVars: availableNumberVars, availableNodesWithParent: availableNumberNodesWithParent, diff --git a/web/app/components/workflow/nodes/if-else/use-is-var-file-attribute.ts b/web/app/components/workflow/nodes/if-else/use-is-var-file-attribute.ts new file mode 100644 index 0000000000..81552dbef6 --- /dev/null +++ b/web/app/components/workflow/nodes/if-else/use-is-var-file-attribute.ts @@ -0,0 +1,45 @@ +import { useStoreApi } from 'reactflow' +import { useMemo } from 'react' +import { useIsChatMode, useWorkflow, useWorkflowVariables } from '../../hooks' +import type { ValueSelector } from '../../types' +import { VarType } from '../../types' + +type Params = { + nodeId: string + isInIteration: boolean +} +const useIsVarFileAttribute = ({ + nodeId, + isInIteration, +}: Params) => { + const isChatMode = useIsChatMode() + const store = useStoreApi() + const { getBeforeNodesInSameBranch } = useWorkflow() + const { + getNodes, + } = store.getState() + const currentNode = getNodes().find(n => n.id === nodeId) + const iterationNode = isInIteration ? getNodes().find(n => n.id === currentNode!.parentId) : null + const availableNodes = useMemo(() => { + return getBeforeNodesInSameBranch(nodeId) + }, [getBeforeNodesInSameBranch, nodeId]) + const { getCurrentVariableType } = useWorkflowVariables() + const getIsVarFileAttribute = (variable: ValueSelector) => { + if (variable.length !== 3) + return false + const parentVariable = variable.slice(0, 2) + const varType = getCurrentVariableType({ + parentNode: iterationNode, + valueSelector: parentVariable, + availableNodes, + isChatMode, + isConstant: false, + }) + return varType === VarType.file + } + return { + getIsVarFileAttribute, + } +} + +export default useIsVarFileAttribute diff --git a/web/app/components/workflow/nodes/if-else/utils.ts b/web/app/components/workflow/nodes/if-else/utils.ts index ffb6758bba..f034761ca0 100644 --- a/web/app/components/workflow/nodes/if-else/utils.ts +++ b/web/app/components/workflow/nodes/if-else/utils.ts @@ -18,7 +18,30 @@ export const isComparisonOperatorNeedTranslate = (operator?: ComparisonOperator) return !notTranslateKey.includes(operator) } -export const getOperators = (type?: VarType) => { +export const getOperators = (type?: VarType, file?: { key: string }) => { + const isFile = !!file + if (isFile) { + const { key } = file + + switch (key) { + case 'name': + return [ + ComparisonOperator.contains, + ComparisonOperator.notContains, + ComparisonOperator.startWith, + ComparisonOperator.endWith, + ComparisonOperator.is, + ComparisonOperator.isNot, + ComparisonOperator.empty, + ComparisonOperator.notEmpty, + ] + case 'type': + return [ + ComparisonOperator.in, + ComparisonOperator.notIn, + ] + } + } switch (type) { case VarType.string: return [