2021-06-23 05:37:08 -04:00
|
|
|
import { useState } from 'react'
|
2021-04-29 04:16:42 -04:00
|
|
|
import { findDOMNode } from 'react-dom'
|
2020-11-26 09:22:30 -05:00
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
import withoutPropagation from '../../../../infrastructure/without-propagation'
|
|
|
|
|
2021-11-09 06:01:08 -05:00
|
|
|
import { Button } from 'react-bootstrap'
|
2020-11-26 09:22:30 -05:00
|
|
|
import Icon from '../../../../shared/components/icon'
|
|
|
|
|
2021-11-09 06:01:08 -05:00
|
|
|
import { useFileTreeMainContext } from '../../contexts/file-tree-main'
|
2020-11-26 09:22:30 -05:00
|
|
|
|
|
|
|
function FileTreeItemMenu({ id }) {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
|
2021-11-09 06:01:08 -05:00
|
|
|
const { contextMenuCoords, setContextMenuCoords } = useFileTreeMainContext()
|
2021-04-29 04:16:42 -04:00
|
|
|
const [dropdownTarget, setDropdownTarget] = useState()
|
2020-11-26 09:22:30 -05:00
|
|
|
|
2021-11-09 06:01:08 -05:00
|
|
|
function handleClick(_ev) {
|
|
|
|
const target = dropdownTarget.getBoundingClientRect()
|
|
|
|
if (!contextMenuCoords) {
|
|
|
|
setContextMenuCoords({
|
|
|
|
top: target.top + target.height / 2,
|
|
|
|
left: target.right,
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
setContextMenuCoords(null)
|
|
|
|
}
|
2020-11-26 09:22:30 -05:00
|
|
|
}
|
|
|
|
|
2021-11-09 06:01:08 -05:00
|
|
|
const menuButtonRef = component => {
|
2021-04-29 04:16:42 -04:00
|
|
|
if (component) {
|
|
|
|
// eslint-disable-next-line react/no-find-dom-node
|
|
|
|
setDropdownTarget(findDOMNode(component))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-26 09:22:30 -05:00
|
|
|
return (
|
2021-11-09 06:01:08 -05:00
|
|
|
<div className="menu-button btn-group">
|
|
|
|
<Button
|
2022-05-11 07:27:09 -04:00
|
|
|
className="entity-menu-toggle"
|
|
|
|
bsSize="sm"
|
2021-11-09 06:01:08 -05:00
|
|
|
id={`menu-button-${id}`}
|
|
|
|
onClick={withoutPropagation(handleClick)}
|
|
|
|
ref={menuButtonRef}
|
2020-11-26 09:22:30 -05:00
|
|
|
>
|
|
|
|
<Icon type="ellipsis-v" accessibilityLabel={t('menu')} />
|
2021-11-09 06:01:08 -05:00
|
|
|
</Button>
|
|
|
|
</div>
|
2020-11-26 09:22:30 -05:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
FileTreeItemMenu.propTypes = {
|
2021-04-27 03:52:58 -04:00
|
|
|
id: PropTypes.string.isRequired,
|
2020-11-26 09:22:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export default FileTreeItemMenu
|