mirror of
https://github.com/langgenius/dify.git
synced 2026-05-04 17:38:04 +08:00
refactor(skill): regroup skill body, file tree, and tree hooks
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
import type { AppAssetTreeResponse, AppAssetTreeView } from '@/types/app-asset'
|
||||
import { useStore as useAppStore } from '@/app/components/app/store'
|
||||
import { useGetAppAssetTree } from '@/service/use-app-asset'
|
||||
import { buildNodeMap } from '../utils/tree-utils'
|
||||
import { buildNodeMap } from '../../../utils/tree-utils'
|
||||
|
||||
/**
|
||||
* Get the current app ID from the app store.
|
||||
@ -9,9 +9,9 @@ import { useStore as useAppStore } from '@/app/components/app/store'
|
||||
import Toast from '@/app/components/base/toast'
|
||||
import { useWorkflowStore } from '@/app/components/workflow/store'
|
||||
import { useUploadFileWithPresignedUrl } from '@/service/use-app-asset'
|
||||
import { ROOT_ID } from '../constants'
|
||||
import { prepareSkillUploadFile } from '../utils/skill-upload-utils'
|
||||
import { useSkillTreeUpdateEmitter } from './use-skill-tree-collaboration'
|
||||
import { ROOT_ID } from '../../../constants'
|
||||
import { prepareSkillUploadFile } from '../../../utils/skill-upload-utils'
|
||||
import { useSkillTreeUpdateEmitter } from '../data/use-skill-tree-collaboration'
|
||||
|
||||
type FileDropTarget = {
|
||||
folderId: string | null
|
||||
@ -5,11 +5,11 @@
|
||||
// Auto-expand is triggered by Zustand isDragOver state (single source of truth)
|
||||
|
||||
import type { NodeApi } from 'react-arborist'
|
||||
import type { TreeNodeData } from '../type'
|
||||
import type { TreeNodeData } from '../../../type'
|
||||
import type { AppAssetTreeView } from '@/types/app-asset'
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
||||
import { useStore } from '@/app/components/workflow/store'
|
||||
import { isDragEvent } from '../utils/drag-utils'
|
||||
import { isDragEvent } from '../../../utils/drag-utils'
|
||||
import { useUnifiedDrag } from './use-unified-drag'
|
||||
|
||||
type UseFolderFileDropReturn = {
|
||||
@ -4,7 +4,7 @@
|
||||
|
||||
import type { AppAssetTreeView } from '@/types/app-asset'
|
||||
import { useCallback, useRef } from 'react'
|
||||
import { isDragEvent } from '../utils/drag-utils'
|
||||
import { isDragEvent } from '../../../utils/drag-utils'
|
||||
import { useUnifiedDrag } from './use-unified-drag'
|
||||
|
||||
type UseRootFileDropReturn = {
|
||||
@ -4,7 +4,7 @@
|
||||
// Internal node drag-move is now handled by react-arborist's built-in drag system
|
||||
|
||||
import { useCallback } from 'react'
|
||||
import { isFileDrag } from '../utils/drag-utils'
|
||||
import { isFileDrag } from '../../../utils/drag-utils'
|
||||
import { useFileDrop } from './use-file-drop'
|
||||
|
||||
type DragTarget = {
|
||||
@ -1,12 +1,12 @@
|
||||
import type { ReactNode } from 'react'
|
||||
import type { TreeApi } from 'react-arborist'
|
||||
import type { TreeNodeData } from '../type'
|
||||
import type { TreeNodeData } from '../../../type'
|
||||
import type { App, AppSSO } from '@/types/app'
|
||||
import { act, renderHook } from '@testing-library/react'
|
||||
import { useStore as useAppStore } from '@/app/components/app/store'
|
||||
import { WorkflowContext } from '@/app/components/workflow/context'
|
||||
import { createWorkflowStore } from '@/app/components/workflow/store'
|
||||
import { START_TAB_ID } from '../constants'
|
||||
import { START_TAB_ID } from '../../../constants'
|
||||
import { useInlineCreateNode } from './use-inline-create-node'
|
||||
|
||||
const {
|
||||
@ -35,7 +35,7 @@ vi.mock('@/service/use-app-asset', () => ({
|
||||
}),
|
||||
}))
|
||||
|
||||
vi.mock('./use-skill-tree-collaboration', () => ({
|
||||
vi.mock('../data/use-skill-tree-collaboration', () => ({
|
||||
useSkillTreeUpdateEmitter: () => mockEmitTreeUpdate,
|
||||
}))
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
'use client'
|
||||
|
||||
import type { NodeApi, TreeApi } from 'react-arborist'
|
||||
import type { TreeNodeData } from '../type'
|
||||
import type { TreeNodeData } from '../../../type'
|
||||
import { useCallback, useEffect, useMemo } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useStore as useAppStore } from '@/app/components/app/store'
|
||||
@ -12,9 +12,9 @@ import {
|
||||
useRenameAppAssetNode,
|
||||
useUploadFileWithPresignedUrl,
|
||||
} from '@/service/use-app-asset'
|
||||
import { getFileExtension, isTextLikeFile } from '../utils/file-utils'
|
||||
import { createDraftTreeNode, insertDraftTreeNode } from '../utils/tree-utils'
|
||||
import { useSkillTreeUpdateEmitter } from './use-skill-tree-collaboration'
|
||||
import { getFileExtension, isTextLikeFile } from '../../../utils/file-utils'
|
||||
import { createDraftTreeNode, insertDraftTreeNode } from '../../../utils/tree-utils'
|
||||
import { useSkillTreeUpdateEmitter } from '../data/use-skill-tree-collaboration'
|
||||
|
||||
type UseInlineCreateNodeOptions = {
|
||||
treeRef: React.RefObject<TreeApi<TreeNodeData> | null>
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
import type { RefObject } from 'react'
|
||||
import type { TreeApi } from 'react-arborist'
|
||||
import type { TreeNodeData } from '../type'
|
||||
import type { TreeNodeData } from '../../../type'
|
||||
import { useKeyPress } from 'ahooks'
|
||||
import { useCallback, useEffect, useRef } from 'react'
|
||||
import { useWorkflowStore } from '@/app/components/workflow/store'
|
||||
@ -1,10 +1,10 @@
|
||||
import type { ReactNode, RefObject } from 'react'
|
||||
import type { TreeApi } from 'react-arborist'
|
||||
import type { TreeNodeData } from '../type'
|
||||
import type { TreeNodeData } from '../../../type'
|
||||
import { renderHook } from '@testing-library/react'
|
||||
import { WorkflowContext } from '@/app/components/workflow/context'
|
||||
import { createWorkflowStore } from '@/app/components/workflow/store'
|
||||
import { START_TAB_ID } from '../constants'
|
||||
import { START_TAB_ID } from '../../../constants'
|
||||
import { useSyncTreeWithActiveTab } from './use-sync-tree-with-active-tab'
|
||||
|
||||
type MockTreeNode = {
|
||||
@ -1,7 +1,7 @@
|
||||
'use client'
|
||||
|
||||
import type { TreeApi } from 'react-arborist'
|
||||
import type { TreeNodeData } from '../type'
|
||||
import type { TreeNodeData } from '../../../type'
|
||||
import { useEffect } from 'react'
|
||||
import { isArtifactTab, START_TAB_ID } from '@/app/components/workflow/skill/constants'
|
||||
import { useWorkflowStore } from '@/app/components/workflow/store'
|
||||
@ -1,7 +1,7 @@
|
||||
'use client'
|
||||
|
||||
import type { NodeApi } from 'react-arborist'
|
||||
import type { TreeNodeData } from '../type'
|
||||
import type { TreeNodeData } from '../../../type'
|
||||
import { throttle } from 'es-toolkit/function'
|
||||
import { useCallback, useMemo, useRef } from 'react'
|
||||
import { useWorkflowStore } from '@/app/components/workflow/store'
|
||||
@ -9,8 +9,8 @@ import {
|
||||
useCreateAppAssetFolder,
|
||||
useUploadFileWithPresignedUrl,
|
||||
} from '@/service/use-app-asset'
|
||||
import { prepareSkillUploadFile } from '../utils/skill-upload-utils'
|
||||
import { useSkillTreeUpdateEmitter } from './use-skill-tree-collaboration'
|
||||
import { prepareSkillUploadFile } from '../../../utils/skill-upload-utils'
|
||||
import { useSkillTreeUpdateEmitter } from '../data/use-skill-tree-collaboration'
|
||||
|
||||
type UseCreateOperationsOptions = {
|
||||
parentId: string | null
|
||||
@ -4,14 +4,14 @@
|
||||
// Maintains backward compatibility for existing consumers
|
||||
|
||||
import type { NodeApi, TreeApi } from 'react-arborist'
|
||||
import type { TreeNodeData } from '../type'
|
||||
import type { TreeNodeData } from '../../../type'
|
||||
import { useStore as useAppStore } from '@/app/components/app/store'
|
||||
import { useWorkflowStore } from '@/app/components/workflow/store'
|
||||
import { toApiParentId } from '../utils/tree-utils'
|
||||
import { toApiParentId } from '../../../utils/tree-utils'
|
||||
import { useSkillAssetTreeData } from '../data/use-skill-asset-tree'
|
||||
import { useCreateOperations } from './use-create-operations'
|
||||
import { useDownloadOperation } from './use-download-operation'
|
||||
import { useModifyOperations } from './use-modify-operations'
|
||||
import { useSkillAssetTreeData } from './use-skill-asset-tree'
|
||||
|
||||
type UseFileOperationsOptions = {
|
||||
nodeId?: string
|
||||
@ -4,15 +4,15 @@
|
||||
|
||||
import type { NodeApi, TreeApi } from 'react-arborist'
|
||||
import type { StoreApi } from 'zustand'
|
||||
import type { TreeNodeData } from '../type'
|
||||
import type { TreeNodeData } from '../../../type'
|
||||
import type { SkillEditorSliceShape } from '@/app/components/workflow/store/workflow/skill-editor/types'
|
||||
import type { AppAssetTreeResponse } from '@/types/app-asset'
|
||||
import { useCallback, useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import Toast from '@/app/components/base/toast'
|
||||
import { useDeleteAppAssetNode } from '@/service/use-app-asset'
|
||||
import { getAllDescendantFileIds } from '../utils/tree-utils'
|
||||
import { useSkillTreeUpdateEmitter } from './use-skill-tree-collaboration'
|
||||
import { getAllDescendantFileIds } from '../../../utils/tree-utils'
|
||||
import { useSkillTreeUpdateEmitter } from '../data/use-skill-tree-collaboration'
|
||||
|
||||
type UseModifyOperationsOptions = {
|
||||
nodeId: string
|
||||
@ -8,8 +8,8 @@ import { useTranslation } from 'react-i18next'
|
||||
import { useStore as useAppStore } from '@/app/components/app/store'
|
||||
import Toast from '@/app/components/base/toast'
|
||||
import { useMoveAppAssetNode } from '@/service/use-app-asset'
|
||||
import { toApiParentId } from '../utils/tree-utils'
|
||||
import { useSkillTreeUpdateEmitter } from './use-skill-tree-collaboration'
|
||||
import { toApiParentId } from '../../../utils/tree-utils'
|
||||
import { useSkillTreeUpdateEmitter } from '../data/use-skill-tree-collaboration'
|
||||
|
||||
export function useNodeMove() {
|
||||
const { t } = useTranslation('workflow')
|
||||
@ -7,7 +7,7 @@ import { useTranslation } from 'react-i18next'
|
||||
import { useStore as useAppStore } from '@/app/components/app/store'
|
||||
import Toast from '@/app/components/base/toast'
|
||||
import { useReorderAppAssetNode } from '@/service/use-app-asset'
|
||||
import { useSkillTreeUpdateEmitter } from './use-skill-tree-collaboration'
|
||||
import { useSkillTreeUpdateEmitter } from '../data/use-skill-tree-collaboration'
|
||||
|
||||
export function useNodeReorder() {
|
||||
const { t } = useTranslation('workflow')
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
import type { RefObject } from 'react'
|
||||
import type { TreeApi } from 'react-arborist'
|
||||
import type { TreeNodeData } from '../type'
|
||||
import type { TreeNodeData } from '../../../type'
|
||||
import type { AppAssetTreeResponse } from '@/types/app-asset'
|
||||
import { useCallback, useEffect, useRef } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
@ -10,8 +10,8 @@ import { useStore as useAppStore } from '@/app/components/app/store'
|
||||
import Toast from '@/app/components/base/toast'
|
||||
import { useWorkflowStore } from '@/app/components/workflow/store'
|
||||
import { useMoveAppAssetNode } from '@/service/use-app-asset'
|
||||
import { findNodeById, getTargetFolderIdFromSelection, toApiParentId } from '../utils/tree-utils'
|
||||
import { useSkillTreeUpdateEmitter } from './use-skill-tree-collaboration'
|
||||
import { findNodeById, getTargetFolderIdFromSelection, toApiParentId } from '../../../utils/tree-utils'
|
||||
import { useSkillTreeUpdateEmitter } from '../data/use-skill-tree-collaboration'
|
||||
|
||||
type UsePasteOperationOptions = {
|
||||
treeRef: RefObject<TreeApi<TreeNodeData> | null>
|
||||
@ -5,7 +5,7 @@ const { mockSaveAllDirty } = vi.hoisted(() => ({
|
||||
mockSaveAllDirty: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('./use-skill-save-manager', () => ({
|
||||
vi.mock('./skill-save-context', () => ({
|
||||
useSkillSaveManager: () => ({
|
||||
saveAllDirty: mockSaveAllDirty,
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user