dify/web/app/components/workflow/nodes/loop/use-is-var-file-attribute.ts
yyh 119b6532fd
refactor(workflow): remove hook barrel exports (#39588)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-07-26 14:16:18 +00:00

34 lines
1.0 KiB
TypeScript

import type { ValueSelector } from '../../types'
import { useMemo } from 'react'
import { useIsChatMode, useWorkflow } from '../../hooks/use-workflow'
import { useWorkflowVariables } from '../../hooks/use-workflow-variables'
import { VarType } from '../../types'
type Params = {
nodeId: string
}
const useIsVarFileAttribute = ({ nodeId }: Params) => {
const isChatMode = useIsChatMode()
const { getBeforeNodesInSameBranch } = useWorkflow()
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({
valueSelector: parentVariable,
availableNodes,
isChatMode,
isConstant: false,
})
return varType === VarType.file
}
return {
getIsVarFileAttribute,
}
}
export default useIsVarFileAttribute