import React, { Component } from 'react'
import PropTypes from 'prop-types'
import MetacodeSelect from '../MetacodeSelect'
class ContextMenu extends Component {
static propTypes = {
topicId: PropTypes.string,
contextNode: PropTypes.object,
contextEdge: PropTypes.object,
contextPos: PropTypes.object,
contextFetchingSiblingsData: PropTypes.bool,
contextSiblingsData: PropTypes.object,
metacodeSets: PropTypes.array,
contextReset: PropTypes.func,
contextDelete: PropTypes.func,
contextRemove: PropTypes.func,
contextHide: PropTypes.func,
contextCenterOn: PropTypes.func,
contextPopoutTopic: PropTypes.func,
contextUpdatePermissions: PropTypes.func,
contextOnMetacodeSelect: PropTypes.func,
contextFetchSiblings: PropTypes.func,
contextPopulateSiblings: PropTypes.func
}
constructor(props) {
super(props)
this.state = {
populateSiblingsSent: false
}
}
render () {
const { contextNode, contextPos, contextOnMetacodeSelect, metacodeSets,
contextSiblingsData, contextFetchSiblings,
contextPopulateSiblings, contextFetchingSiblingsData,
topicId } = this.props
const style = {
position: 'absolute',
top: contextPos.y + 'px',
left: contextPos.x + 'px'
}
const populateSiblings = () => {
if (!this.state.populateSiblingsSent) {
contextPopulateSiblings(contextNode.id)
this.setState({populateSiblingsSent: true})
}
}
// TODO: add checks for logged in and other context
return
-
Hide until refresh
Ctrl+H
-
Remove from map
Ctrl+M
-
Delete
Ctrl+D
-
Open in new tab
-
Change permissions
-
Change metacode
{contextNode && topicId && -
Reveal siblings
- contextFetchSiblings(contextNode)}>All
Alt+R
{contextSiblingsData && Object.keys(contextSiblingsData).map(key => {
return - contextFetchSiblings(contextNode, key)}>
{contextSiblingsData[key]}
})}
{contextFetchingSiblingsData && - loading
}
}
// position the menu where the click happened
/*const position = {}
const RIGHTCLICK_WIDTH = 300
const RIGHTCLICK_HEIGHT = 144 // this does vary somewhat, but we can use static
const SUBMENUS_WIDTH = 256
const MAX_SUBMENU_HEIGHT = 270
const windowWidth = $(window).width()
const windowHeight = $(window).height()
if (windowWidth - e.clientX < SUBMENUS_WIDTH) {
position.right = windowWidth - e.clientX
$(rightclickmenu).addClass('moveMenusToLeft')
} else if (windowWidth - e.clientX < RIGHTCLICK_WIDTH) {
position.right = windowWidth - e.clientX
} else if (windowWidth - e.clientX < RIGHTCLICK_WIDTH + SUBMENUS_WIDTH) {
position.left = e.clientX
$(rightclickmenu).addClass('moveMenusToLeft')
} else {
position.left = e.clientX
}
if (windowHeight - e.clientY < MAX_SUBMENU_HEIGHT) {
position.bottom = windowHeight - e.clientY
$(rightclickmenu).addClass('moveMenusUp')
} else if (windowHeight - e.clientY < RIGHTCLICK_HEIGHT + MAX_SUBMENU_HEIGHT) {
position.top = e.clientY
$(rightclickmenu).addClass('moveMenusUp')
} else {
position.top = e.clientY
}*/
}
}
export default ContextMenu