mirror of
https://github.com/langgenius/dify.git
synced 2026-05-13 08:57:28 +08:00
The previous refactor inadvertently passed undefined nodeId for blank area menus, causing root-level folder creation/upload to fail. This restores the original behavior by explicitly passing 'root' when the context menu type is 'blank'.
58 lines
1.4 KiB
TypeScript
58 lines
1.4 KiB
TypeScript
'use client'
|
|
|
|
import type { FC } from 'react'
|
|
import type { TreeApi } from 'react-arborist'
|
|
import type { TreeNodeData } from '../type'
|
|
import { useClickAway } from 'ahooks'
|
|
import * as React from 'react'
|
|
import { useCallback, useRef } from 'react'
|
|
import { useStore, useWorkflowStore } from '@/app/components/workflow/store'
|
|
import NodeMenu from './node-menu'
|
|
|
|
type TreeContextMenuProps = {
|
|
treeRef: React.RefObject<TreeApi<TreeNodeData> | null>
|
|
}
|
|
|
|
function getMenuType(contextMenu: { type: string, isFolder?: boolean }): 'root' | 'folder' | 'file' {
|
|
if (contextMenu.type === 'blank')
|
|
return 'root'
|
|
return contextMenu.isFolder ? 'folder' : 'file'
|
|
}
|
|
|
|
const TreeContextMenu: FC<TreeContextMenuProps> = ({ treeRef }) => {
|
|
const ref = useRef<HTMLDivElement>(null)
|
|
const contextMenu = useStore(s => s.contextMenu)
|
|
const storeApi = useWorkflowStore()
|
|
|
|
const handleClose = useCallback(() => {
|
|
storeApi.getState().setContextMenu(null)
|
|
}, [storeApi])
|
|
|
|
useClickAway(() => {
|
|
handleClose()
|
|
}, ref)
|
|
|
|
if (!contextMenu)
|
|
return null
|
|
|
|
return (
|
|
<div
|
|
ref={ref}
|
|
className="fixed z-[100]"
|
|
style={{
|
|
top: contextMenu.top,
|
|
left: contextMenu.left,
|
|
}}
|
|
>
|
|
<NodeMenu
|
|
type={getMenuType(contextMenu)}
|
|
nodeId={contextMenu.type === 'blank' ? 'root' : contextMenu.nodeId}
|
|
onClose={handleClose}
|
|
treeRef={treeRef}
|
|
/>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default React.memo(TreeContextMenu)
|