refactor(skill): unify root/blank constants and eliminate magic strings

- Add constants.ts with ROOT_ID, CONTEXT_MENU_TYPE, NODE_MENU_TYPE
- Add root utilities to tree-utils.ts (isRootId, toApiParentId, etc.)
- Replace '__root__' with ROOT_ID for consistent root identifier
- Replace inline 'blank'/'root' strings with constants
- Use NodeMenuType for type-safe menu type props
- Remove duplicate ContextMenuType from types.ts, use from constants.ts
This commit is contained in:
yyh
2026-01-19 23:04:18 +08:00
parent 9080607028
commit 31a7db2657
9 changed files with 78 additions and 22 deletions

View File

@ -9,6 +9,7 @@ import { useStore as useAppStore } from '@/app/components/app/store'
import Toast from '@/app/components/base/toast'
import { useWorkflowStore } from '@/app/components/workflow/store'
import { useCreateAppAssetFile } from '@/service/use-app-asset'
import { ROOT_ID } from '../constants'
type FileDropTarget = {
folderId: string | null
@ -32,8 +33,8 @@ export function useFileDrop() {
e.dataTransfer.dropEffect = 'copy'
// Use '__root__' to indicate dragging over root (to distinguish from "not dragging")
storeApi.getState().setDragOverFolderId(target.folderId ?? '__root__')
// Use ROOT_ID to indicate dragging over root (to distinguish from null = "not dragging")
storeApi.getState().setDragOverFolderId(target.folderId ?? ROOT_ID)
}, [storeApi])
const handleDragLeave = useCallback((e: React.DragEvent) => {

View File

@ -7,6 +7,7 @@ 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 { toApiParentId } from '../utils/tree-utils'
import { useCreateOperations } from './use-create-operations'
import { useModifyOperations } from './use-modify-operations'
import { useSkillAssetTreeData } from './use-skill-asset-tree'
@ -31,7 +32,7 @@ export function useFileOperations({
const storeApi = useWorkflowStore()
const { data: treeData } = useSkillAssetTreeData()
const parentId = nodeId === 'root' ? null : nodeId
const parentId = toApiParentId(nodeId)
const createOps = useCreateOperations({
parentId,