dify/web/app/components/workflow/nodes/if-else/use-is-var-file-attribute.ts
Stephen Zhou a84c2d36a3
style: format with vp fmt (#38803)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-07-12 15:57:46 +00:00

44 lines
1.5 KiB
TypeScript

import type { ValueSelector } from '../../types'
import { useMemo } from 'react'
import { useStoreApi } from 'reactflow'
import { useIsChatMode, useWorkflow, useWorkflowVariables } from '../../hooks'
import { VarType } from '../../types'
type Params = {
nodeId: string
isInIteration: boolean
isInLoop: boolean
}
const useIsVarFileAttribute = ({ nodeId, isInIteration, isInLoop }: 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 loopNode = isInLoop ? 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: isInIteration ? iterationNode : loopNode,
valueSelector: parentVariable,
availableNodes,
isChatMode,
isConstant: false,
})
return varType === VarType.file
}
return {
getIsVarFileAttribute,
}
}
export default useIsVarFileAttribute