mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
9daa8f5d98
[web] rename all the JSX files to .jsx/.tsx GitOrigin-RevId: 82056ae47e017523722cf258dcc83c8a925a28f7
58 lines
1.6 KiB
JavaScript
58 lines
1.6 KiB
JavaScript
import React from 'react'
|
|
import ReactDOM from 'react-dom'
|
|
import PropTypes from 'prop-types'
|
|
|
|
import { Dropdown } from 'react-bootstrap'
|
|
import { useEditorContext } from '../../../shared/context/editor-context'
|
|
import { useFileTreeMainContext } from '../contexts/file-tree-main'
|
|
|
|
import FileTreeItemMenuItems from './file-tree-item/file-tree-item-menu-items'
|
|
|
|
function FileTreeContextMenu() {
|
|
const { permissionsLevel } = useEditorContext(editorContextPropTypes)
|
|
const { contextMenuCoords, setContextMenuCoords } = useFileTreeMainContext()
|
|
|
|
if (permissionsLevel === 'readOnly' || !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
|
|
id="dropdown-file-tree-context-menu"
|
|
onToggle={handleToggle}
|
|
>
|
|
<FakeDropDownToggle bsRole="toggle" />
|
|
<Dropdown.Menu className="context-menu" style={contextMenuCoords}>
|
|
<FileTreeItemMenuItems />
|
|
</Dropdown.Menu>
|
|
</Dropdown>,
|
|
document.querySelector('body')
|
|
)
|
|
}
|
|
|
|
const editorContextPropTypes = {
|
|
permissionsLevel: PropTypes.oneOf(['readOnly', 'readAndWrite', 'owner']),
|
|
}
|
|
|
|
// 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
|
|
})
|
|
|
|
FakeDropDownToggle.displayName = 'FakeDropDownToggle'
|
|
|
|
export default FileTreeContextMenu
|