2018-09-12 02:32:31 +00:00
|
|
|
import React, { Component } from 'react';
|
2018-10-16 10:19:51 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2019-01-18 08:41:26 +00:00
|
|
|
import { gettext } from '../../utils/constants';
|
|
|
|
import { Dropdown, DropdownMenu, DropdownToggle, DropdownItem } from 'reactstrap';
|
2018-09-12 02:32:31 +00:00
|
|
|
import TreeView from '../../components/tree-view/tree-view';
|
2018-10-16 06:27:21 +00:00
|
|
|
import NodeMenu from '../../components/tree-view/node-menu';
|
2019-01-18 08:41:26 +00:00
|
|
|
import Logo from '../../components/logo';
|
|
|
|
import ModalPortal from '../../components/modal-portal';
|
2018-10-16 06:27:21 +00:00
|
|
|
import Delete from '../../components/dialog/delete-dialog';
|
|
|
|
import Rename from '../../components/dialog/rename-dialog';
|
|
|
|
import CreateFolder from '../../components/dialog/create-folder-dialog';
|
|
|
|
import CreateFile from '../../components/dialog/create-file-dialog';
|
2018-09-12 02:32:31 +00:00
|
|
|
|
2018-10-16 10:19:51 +00:00
|
|
|
const propTypes = {
|
2018-11-22 03:26:00 +00:00
|
|
|
currentNode: PropTypes.object,
|
2018-10-16 10:19:51 +00:00
|
|
|
treeData: PropTypes.object.isRequired,
|
2018-11-22 03:26:00 +00:00
|
|
|
currentPath: PropTypes.string.isRequired,
|
2018-10-16 10:19:51 +00:00
|
|
|
closeSideBar: PropTypes.bool.isRequired,
|
|
|
|
onCloseSide: PropTypes.func.isRequired,
|
|
|
|
onDirCollapse: PropTypes.func.isRequired,
|
|
|
|
onNodeClick: PropTypes.func.isRequired,
|
|
|
|
onRenameNode: PropTypes.func.isRequired,
|
|
|
|
onDeleteNode: PropTypes.func.isRequired,
|
|
|
|
onAddFileNode: PropTypes.func.isRequired,
|
|
|
|
onAddFolderNode: PropTypes.func.isRequired,
|
|
|
|
};
|
|
|
|
|
2018-09-12 02:32:31 +00:00
|
|
|
class SidePanel extends Component {
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
currentNode: null,
|
|
|
|
isNodeItemFrezee: false,
|
|
|
|
isShowMenu: false,
|
|
|
|
menuPosition: {
|
|
|
|
left: 0,
|
|
|
|
top: 0
|
|
|
|
},
|
|
|
|
isLoadFailed: false,
|
2018-09-12 06:15:27 +00:00
|
|
|
isMenuIconShow: false,
|
2019-01-18 08:41:26 +00:00
|
|
|
isHeaderMenuShow: false,
|
|
|
|
isDeleteDialogShow: false,
|
|
|
|
isAddFileDialogShow: false,
|
|
|
|
isAddFolderDialogShow: false,
|
|
|
|
isRenameDialogShow: false,
|
2018-09-29 10:32:53 +00:00
|
|
|
};
|
2018-09-12 02:32:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onMouseEnter = () => {
|
2019-01-18 08:41:26 +00:00
|
|
|
this.setState({isMenuIconShow: true});
|
2018-09-12 02:32:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onMouseLeave = () => {
|
2019-01-18 08:41:26 +00:00
|
|
|
this.setState({isMenuIconShow: false});
|
|
|
|
}
|
|
|
|
|
|
|
|
onDropdownToggleClick = (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
this.toggleOperationMenu();
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleOperationMenu = () => {
|
|
|
|
this.setState({isHeaderMenuShow: !this.state.isHeaderMenuShow});
|
2018-09-12 02:32:31 +00:00
|
|
|
}
|
|
|
|
|
2018-11-22 03:26:00 +00:00
|
|
|
onNodeClick = (node) => {
|
2018-09-29 10:32:53 +00:00
|
|
|
this.setState({currentNode: node});
|
2018-11-22 03:26:00 +00:00
|
|
|
this.props.onNodeClick(node);
|
2018-09-12 02:32:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onShowContextMenu = (e, node) => {
|
|
|
|
let left = e.clientX - 8*16;
|
|
|
|
let top = e.clientY + 10;
|
|
|
|
let position = Object.assign({},this.state.menuPosition, {left: left, top: top});
|
|
|
|
this.setState({
|
|
|
|
isShowMenu: !this.state.isShowMenu,
|
|
|
|
currentNode: node,
|
|
|
|
menuPosition: position,
|
|
|
|
isNodeItemFrezee: true
|
2018-09-29 10:32:53 +00:00
|
|
|
});
|
2018-09-12 02:32:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onHideContextMenu = () => {
|
2018-09-12 06:15:27 +00:00
|
|
|
if (!this.state.isShowMenu) {
|
|
|
|
return;
|
|
|
|
}
|
2018-09-12 02:32:31 +00:00
|
|
|
this.setState({
|
|
|
|
isShowMenu: false,
|
|
|
|
isNodeItemFrezee: false
|
2018-09-29 10:32:53 +00:00
|
|
|
});
|
2018-09-12 02:32:31 +00:00
|
|
|
}
|
|
|
|
|
2019-01-18 08:41:26 +00:00
|
|
|
onAddFileToggle = () => {
|
|
|
|
this.setState({
|
|
|
|
isMenuIconShow: false,
|
|
|
|
isAddFileDialogShow: !this.state.isAddFileDialogShow
|
|
|
|
});
|
2018-10-16 06:27:21 +00:00
|
|
|
this.onHideContextMenu();
|
|
|
|
}
|
|
|
|
|
2019-01-18 08:41:26 +00:00
|
|
|
onAddFolderToggle = () => {
|
|
|
|
this.setState({
|
|
|
|
isMenuIconShow: false,
|
|
|
|
isAddFolderDialogShow: !this.state.isAddFolderDialogShow
|
|
|
|
});
|
2018-09-12 06:15:27 +00:00
|
|
|
this.onHideContextMenu();
|
|
|
|
}
|
2018-11-22 03:26:00 +00:00
|
|
|
|
2019-01-18 08:41:26 +00:00
|
|
|
onRenameToggle = () => {
|
|
|
|
this.setState({isRenameDialogShow: !this.state.isRenameDialogShow});
|
2018-09-12 06:15:27 +00:00
|
|
|
this.onHideContextMenu();
|
|
|
|
}
|
2018-11-22 03:26:00 +00:00
|
|
|
|
2019-01-18 08:41:26 +00:00
|
|
|
onDeleteToggle = () => {
|
|
|
|
this.setState({isDeleteDialogShow: !this.state.isDeleteDialogShow});
|
2018-09-12 06:15:27 +00:00
|
|
|
this.onHideContextMenu();
|
|
|
|
}
|
|
|
|
|
2018-09-12 02:32:31 +00:00
|
|
|
onAddFolderNode = (dirPath) => {
|
2019-01-18 08:41:26 +00:00
|
|
|
this.setState({isAddFolderDialogShow: !this.state.isAddFolderDialogShow});
|
2018-09-12 02:32:31 +00:00
|
|
|
this.props.onAddFolderNode(dirPath);
|
|
|
|
}
|
2018-11-22 03:26:00 +00:00
|
|
|
|
2018-10-24 06:37:41 +00:00
|
|
|
onAddFileNode = (filePath, isDraft) => {
|
2019-01-18 08:41:26 +00:00
|
|
|
this.setState({isAddFileDialogShow: !this.state.isAddFileDialogShow});
|
2018-10-24 06:37:41 +00:00
|
|
|
this.props.onAddFileNode(filePath, isDraft);
|
2018-09-12 02:32:31 +00:00
|
|
|
}
|
2018-11-22 03:26:00 +00:00
|
|
|
|
2018-09-12 02:32:31 +00:00
|
|
|
onRenameNode = (newName) => {
|
2019-01-18 08:41:26 +00:00
|
|
|
this.setState({isRenameDialogShow: !this.state.isRenameDialogShow});
|
2018-09-12 02:32:31 +00:00
|
|
|
let node = this.state.currentNode;
|
2018-09-29 10:32:53 +00:00
|
|
|
this.props.onRenameNode(node, newName);
|
2018-09-12 02:32:31 +00:00
|
|
|
}
|
2018-11-22 03:26:00 +00:00
|
|
|
|
2018-09-12 02:32:31 +00:00
|
|
|
onDeleteNode = () => {
|
2019-01-18 08:41:26 +00:00
|
|
|
this.setState({isDeleteDialogShow: !this.state.isDeleteDialogShow});
|
2018-09-12 02:32:31 +00:00
|
|
|
let node = this.state.currentNode;
|
|
|
|
this.props.onDeleteNode(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
document.addEventListener('click', this.onHideContextMenu);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillReceiveProps(nextProps) {
|
2018-11-22 03:26:00 +00:00
|
|
|
this.setState({currentNode: nextProps.currentNode});
|
2018-09-12 02:32:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
document.removeEventListener('click', this.onHideContextMenu);
|
|
|
|
}
|
|
|
|
|
2018-09-12 06:15:27 +00:00
|
|
|
addFolderCancel = () => {
|
2019-01-18 08:41:26 +00:00
|
|
|
this.setState({isAddFolderDialogShow: !this.state.isAddFolderDialogShow});
|
2018-09-12 06:15:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
addFileCancel = () => {
|
2019-01-18 08:41:26 +00:00
|
|
|
this.setState({isAddFileDialogShow: !this.state.isAddFileDialogShow});
|
2018-09-12 06:15:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
deleteCancel = () => {
|
2019-01-18 08:41:26 +00:00
|
|
|
this.setState({isDeleteDialogShow: !this.state.isDeleteDialogShow});
|
2018-09-12 06:15:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
renameCancel = () => {
|
2019-01-18 08:41:26 +00:00
|
|
|
this.setState({isRenameDialogShow: !this.state.isRenameDialogShow});
|
2018-09-12 06:15:27 +00:00
|
|
|
}
|
|
|
|
|
2018-09-12 02:32:31 +00:00
|
|
|
render() {
|
|
|
|
return (
|
2018-09-29 10:32:53 +00:00
|
|
|
<div className={`side-panel wiki-side-panel ${this.props.closeSideBar ? '': 'left-zero'}`}>
|
2018-09-12 02:32:31 +00:00
|
|
|
<div className="side-panel-top panel-top">
|
2019-01-18 08:41:26 +00:00
|
|
|
<Logo onCloseSidePanel={this.props.onCloseSide} />
|
2018-09-12 02:32:31 +00:00
|
|
|
</div>
|
|
|
|
<div id="side-nav" className="wiki-side-nav" role="navigation">
|
2019-01-18 08:41:26 +00:00
|
|
|
<h3 className="wiki-pages-heading" onMouseEnter={this.onMouseEnter} onMouseLeave={this.onMouseLeave}>
|
2018-09-29 10:32:53 +00:00
|
|
|
{gettext('Files')}
|
2018-09-12 02:32:31 +00:00
|
|
|
<div className="heading-icon">
|
2019-01-18 08:41:26 +00:00
|
|
|
{this.state.isMenuIconShow && (
|
|
|
|
<Dropdown isOpen={this.state.isHeaderMenuShow} toggle={this.toggleOperationMenu}>
|
|
|
|
<DropdownToggle
|
|
|
|
tag="i"
|
|
|
|
className="fas fa-ellipsis-v"
|
|
|
|
title={gettext('More Operations')}
|
|
|
|
data-toggle="dropdown"
|
|
|
|
aria-expanded={this.state.isHeaderMenuShow}
|
|
|
|
onClick={this.onDropdownToggleClick}
|
|
|
|
/>
|
|
|
|
<DropdownMenu right>
|
|
|
|
<DropdownItem onClick={this.onAddFolderToggle}>{gettext('New Folder')}</DropdownItem>
|
|
|
|
<DropdownItem onClick={this.onAddFileToggle}>{gettext('New File')}</DropdownItem>
|
|
|
|
</DropdownMenu>
|
|
|
|
</Dropdown>
|
|
|
|
)}
|
2018-09-12 02:32:31 +00:00
|
|
|
</div>
|
|
|
|
</h3>
|
|
|
|
<div className="wiki-pages-container">
|
2019-01-18 08:41:26 +00:00
|
|
|
{this.props.treeData && (
|
|
|
|
<TreeView
|
|
|
|
treeData={this.props.treeData}
|
|
|
|
currentPath={this.props.currentPath}
|
|
|
|
isNodeItemFrezee={this.state.isNodeItemFrezee}
|
|
|
|
onShowContextMenu={this.onShowContextMenu}
|
|
|
|
onNodeClick={this.onNodeClick}
|
|
|
|
onDirCollapse={this.props.onDirCollapse}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{this.state.isShowMenu && (
|
|
|
|
<NodeMenu
|
|
|
|
menuPosition={this.state.menuPosition}
|
|
|
|
currentNode={this.state.currentNode}
|
|
|
|
toggleAddFile={this.onAddFileToggle}
|
|
|
|
toggleAddFolder={this.onAddFolderToggle}
|
|
|
|
toggleRename={this.onRenameToggle}
|
|
|
|
toggleDelete={this.onDeleteToggle}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{this.state.isDeleteDialogShow && (
|
|
|
|
<ModalPortal>
|
2018-11-22 03:26:00 +00:00
|
|
|
<Delete
|
2018-09-12 06:15:27 +00:00
|
|
|
currentNode={this.state.currentNode}
|
|
|
|
handleSubmit={this.onDeleteNode}
|
|
|
|
toggleCancel={this.deleteCancel}
|
2018-09-12 02:32:31 +00:00
|
|
|
/>
|
2019-01-18 08:41:26 +00:00
|
|
|
</ModalPortal>
|
|
|
|
)}
|
|
|
|
{this.state.isAddFileDialogShow && (
|
|
|
|
<ModalPortal>
|
2018-10-16 06:27:21 +00:00
|
|
|
<CreateFile
|
|
|
|
fileType={'.md'}
|
|
|
|
parentPath={this.state.currentNode.path}
|
2018-09-12 06:15:27 +00:00
|
|
|
onAddFile={this.onAddFileNode}
|
|
|
|
addFileCancel={this.addFileCancel}
|
|
|
|
/>
|
2019-01-18 08:41:26 +00:00
|
|
|
</ModalPortal>
|
|
|
|
)}
|
|
|
|
{this.state.isAddFolderDialogShow && (
|
|
|
|
<ModalPortal>
|
2018-11-22 03:26:00 +00:00
|
|
|
<CreateFolder
|
2018-10-16 06:27:21 +00:00
|
|
|
parentPath={this.state.currentNode.path}
|
|
|
|
onAddFolder={this.onAddFolderNode}
|
|
|
|
addFolderCancel={this.addFolderCancel}
|
|
|
|
/>
|
2019-01-18 08:41:26 +00:00
|
|
|
</ModalPortal>
|
|
|
|
)}
|
|
|
|
{this.state.isRenameDialogShow && (
|
|
|
|
<ModalPortal>
|
2018-11-22 03:26:00 +00:00
|
|
|
<Rename
|
2018-09-12 06:15:27 +00:00
|
|
|
currentNode={this.state.currentNode}
|
2018-11-22 03:26:00 +00:00
|
|
|
onRename={this.onRenameNode}
|
|
|
|
toggleCancel={this.renameCancel}
|
2018-09-12 06:15:27 +00:00
|
|
|
/>
|
2019-01-18 08:41:26 +00:00
|
|
|
</ModalPortal>
|
|
|
|
)}
|
2018-09-12 02:32:31 +00:00
|
|
|
</div>
|
2018-09-29 10:32:53 +00:00
|
|
|
);
|
2018-09-12 02:32:31 +00:00
|
|
|
}
|
|
|
|
}
|
2018-10-16 10:19:51 +00:00
|
|
|
|
|
|
|
SidePanel.propTypes = propTypes;
|
|
|
|
|
2018-09-12 02:32:31 +00:00
|
|
|
export default SidePanel;
|