mirror of
https://github.com/langgenius/dify.git
synced 2026-06-07 07:52:50 +08:00
Split use-file-operations.ts (248 lines) into smaller focused hooks: - use-create-operations.ts for file/folder creation and upload - use-modify-operations.ts for rename and delete operations - use-file-operations.ts now serves as orchestrator maintaining backward compatibility Extract TreeNodeIcon component from tree-node.tsx for cleaner separation of concerns. Add brief comments to drag hooks explaining their purpose and relationships.
74 lines
2.1 KiB
TypeScript
74 lines
2.1 KiB
TypeScript
'use client'
|
|
|
|
// Orchestrator hook for file operations - combines create and modify operations
|
|
// Maintains backward compatibility for existing consumers
|
|
|
|
import type { NodeApi, TreeApi } from 'react-arborist'
|
|
import type { TreeNodeData } from '../type'
|
|
import { useStore as useAppStore } from '@/app/components/app/store'
|
|
import { useWorkflowStore } from '@/app/components/workflow/store'
|
|
import { useCreateOperations } from './use-create-operations'
|
|
import { useModifyOperations } from './use-modify-operations'
|
|
import { useSkillAssetTreeData } from './use-skill-asset-tree'
|
|
|
|
type UseFileOperationsOptions = {
|
|
nodeId?: string
|
|
onClose: () => void
|
|
treeRef?: React.RefObject<TreeApi<TreeNodeData> | null>
|
|
node?: NodeApi<TreeNodeData>
|
|
}
|
|
|
|
export function useFileOperations({
|
|
nodeId: explicitNodeId,
|
|
onClose,
|
|
treeRef,
|
|
node,
|
|
}: UseFileOperationsOptions) {
|
|
const nodeId = node?.data.id ?? explicitNodeId ?? ''
|
|
|
|
const appDetail = useAppStore(s => s.appDetail)
|
|
const appId = appDetail?.id || ''
|
|
const storeApi = useWorkflowStore()
|
|
const { data: treeData } = useSkillAssetTreeData()
|
|
|
|
const parentId = nodeId === 'root' ? null : nodeId
|
|
|
|
const createOps = useCreateOperations({
|
|
parentId,
|
|
appId,
|
|
storeApi,
|
|
onClose,
|
|
})
|
|
|
|
const modifyOps = useModifyOperations({
|
|
nodeId,
|
|
node,
|
|
treeRef,
|
|
appId,
|
|
storeApi,
|
|
treeData,
|
|
onClose,
|
|
})
|
|
|
|
return {
|
|
// Create operations
|
|
fileInputRef: createOps.fileInputRef,
|
|
folderInputRef: createOps.folderInputRef,
|
|
handleNewFile: createOps.handleNewFile,
|
|
handleNewFolder: createOps.handleNewFolder,
|
|
handleFileChange: createOps.handleFileChange,
|
|
handleFolderChange: createOps.handleFolderChange,
|
|
|
|
// Modify operations
|
|
showDeleteConfirm: modifyOps.showDeleteConfirm,
|
|
handleRename: modifyOps.handleRename,
|
|
handleDeleteClick: modifyOps.handleDeleteClick,
|
|
handleDeleteConfirm: modifyOps.handleDeleteConfirm,
|
|
handleDeleteCancel: modifyOps.handleDeleteCancel,
|
|
|
|
// Combined loading states
|
|
isLoading: createOps.isCreating || modifyOps.isDeleting,
|
|
isDeleting: modifyOps.isDeleting,
|
|
}
|
|
}
|