2021-03-18 05:52:36 -04:00
|
|
|
import React from 'react'
|
2020-11-26 09:22:30 -05:00
|
|
|
import ReactDOM from 'react-dom'
|
|
|
|
|
|
|
|
import { Dropdown } from 'react-bootstrap'
|
2021-03-18 05:52:36 -04:00
|
|
|
import { useFileTreeMainContext } from '../contexts/file-tree-main'
|
2020-11-26 09:22:30 -05:00
|
|
|
|
|
|
|
import FileTreeItemMenuItems from './file-tree-item/file-tree-item-menu-items'
|
|
|
|
|
|
|
|
function FileTreeContextMenu() {
|
|
|
|
const {
|
|
|
|
hasWritePermissions,
|
|
|
|
contextMenuCoords,
|
|
|
|
setContextMenuCoords
|
2021-03-18 05:52:36 -04:00
|
|
|
} = useFileTreeMainContext()
|
2020-11-26 09:22:30 -05:00
|
|
|
|
|
|
|
if (!hasWritePermissions || !contextMenuCoords) return null
|
|
|
|
|
|
|
|
function close() {
|
|
|
|
// reset context menu
|
|
|
|
setContextMenuCoords(null)
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleToggle(wantOpen) {
|
|
|
|
if (!wantOpen) close()
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleClick() {
|
|
|
|
handleToggle(false)
|
|
|
|
}
|
|
|
|
|
|
|
|
return ReactDOM.createPortal(
|
|
|
|
<Dropdown
|
|
|
|
onClick={handleClick}
|
|
|
|
open
|
2020-12-09 06:56:24 -05:00
|
|
|
id="dropdown-file-tree-context-menu"
|
2020-11-26 09:22:30 -05:00
|
|
|
onToggle={handleToggle}
|
|
|
|
>
|
|
|
|
<FakeDropDownToggle bsRole="toggle" />
|
|
|
|
<Dropdown.Menu className="context-menu" style={contextMenuCoords}>
|
|
|
|
<FileTreeItemMenuItems />
|
|
|
|
</Dropdown.Menu>
|
|
|
|
</Dropdown>,
|
|
|
|
document.querySelector('body')
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// fake component required as Dropdowns require a Toggle, even tho we don't want
|
|
|
|
// one for the context menu
|
|
|
|
const FakeDropDownToggle = React.forwardRef((props, ref) => {
|
|
|
|
return null
|
|
|
|
})
|
|
|
|
|
|
|
|
export default FileTreeContextMenu
|