diff --git a/frontend/src/components/cur-dir-path/dir-path.js b/frontend/src/components/cur-dir-path/dir-path.js index 00c03f9cbe..36ce2b9178 100644 --- a/frontend/src/components/cur-dir-path/dir-path.js +++ b/frontend/src/components/cur-dir-path/dir-path.js @@ -6,17 +6,31 @@ import { siteRoot, gettext } from '../../utils/constants'; import { Utils } from '../../utils/utils'; import { InternalLinkOperation } from '../operations'; import DirOperationToolBar from '../../components/toolbar/dir-operation-toolbar'; +import ViewFileToolbar from '../../components/toolbar/view-file-toolbar'; const propTypes = { + repoID: PropTypes.string.isRequired, repoName: PropTypes.string.isRequired, currentPath: PropTypes.string.isRequired, onPathClick: PropTypes.func.isRequired, onTabNavClick: PropTypes.func, pathPrefix: PropTypes.array, - repoID: PropTypes.string.isRequired, isViewFile: PropTypes.bool, fileTags: PropTypes.array.isRequired, - toggleTreePanel: PropTypes.func.isRequired + toggleTreePanel: PropTypes.func.isRequired, + repoEncrypted: PropTypes.bool.isRequired, + enableDirPrivateShare: PropTypes.bool.isRequired, + userPerm: PropTypes.string.isRequired, + isGroupOwnedRepo: PropTypes.bool.isRequired, + showShareBtn: PropTypes.bool.isRequired, + onAddFile: PropTypes.func.isRequired, + onAddFolder: PropTypes.func.isRequired, + onUploadFile: PropTypes.func.isRequired, + onUploadFolder: PropTypes.func.isRequired, + direntList: PropTypes.array.isRequired, + repoTags: PropTypes.array.isRequired, + filePermission: PropTypes.string, + onFileTagChanged: PropTypes.func.isRequired, }; class DirPath extends React.Component { @@ -51,23 +65,41 @@ class DirPath extends React.Component { return ( / - - {item} - + {this.props.isViewFile ? + + {item} + + : + + {item} + + } ); } else { diff --git a/frontend/src/components/cur-dir-path/index.js b/frontend/src/components/cur-dir-path/index.js index b5359238a6..ca7de8a76f 100644 --- a/frontend/src/components/cur-dir-path/index.js +++ b/frontend/src/components/cur-dir-path/index.js @@ -25,6 +25,18 @@ const propTypes = { currentMode: PropTypes.string.isRequired, switchViewMode: PropTypes.func.isRequired, isCustomPermission: PropTypes.bool, + repoEncrypted: PropTypes.bool.isRequired, + isGroupOwnedRepo: PropTypes.bool.isRequired, + enableDirPrivateShare: PropTypes.bool.isRequired, + showShareBtn: PropTypes.bool.isRequired, + onAddFile: PropTypes.func.isRequired, + onAddFolder: PropTypes.func.isRequired, + onUploadFile: PropTypes.func.isRequired, + onUploadFolder: PropTypes.func.isRequired, + fullDirentList: PropTypes.array.isRequired, + filePermission: PropTypes.string, + repoTags: PropTypes.array.isRequired, + onFileTagChanged: PropTypes.func.isRequired, }; class CurDirPath extends React.Component { @@ -66,6 +78,9 @@ class CurDirPath extends React.Component { onUploadFile={this.props.onUploadFile} onUploadFolder={this.props.onUploadFolder} direntList={this.props.fullDirentList} + filePermission={this.props.filePermission} + onFileTagChanged={this.props.onFileTagChanged} + repoTags={this.props.repoTags} /> {isDesktop && { e.stopPropagation(); this.setState({ - isSubMenuShown: !this.state.isSubMenuShown}, () => { + isSubMenuShown: !this.state.isSubMenuShown + }, () => { this.toggleDesktopOpMenu(); }); }; @@ -186,7 +187,11 @@ class DirOperationToolbar extends React.Component { ] }); } else { - opList.push({'text': gettext('Upload'), 'onClick': this.onUploadFile}); + opList.push({ + 'icon': 'upload-files', + 'text': gettext('Upload'), + 'onClick': this.onUploadFile + }); } } @@ -206,7 +211,7 @@ class DirOperationToolbar extends React.Component { opList.push({ 'icon': 'new', 'text': gettext('New'), - subOpList: newSubOpList + 'subOpList': newSubOpList }); } @@ -266,10 +271,12 @@ class DirOperationToolbar extends React.Component { ); } else { - return ( - - {item.text} - ); + return ( + + + {item.text} + + ); } })} diff --git a/frontend/src/components/toolbar/view-file-toolbar.js b/frontend/src/components/toolbar/view-file-toolbar.js index 91b2172399..ed86a9ab3e 100644 --- a/frontend/src/components/toolbar/view-file-toolbar.js +++ b/frontend/src/components/toolbar/view-file-toolbar.js @@ -20,6 +20,7 @@ const propTypes = { onFileTagChanged: PropTypes.func.isRequired, showShareBtn: PropTypes.bool.isRequired, dirent: PropTypes.object, + children: PropTypes.object }; class ViewFileToolbar extends React.Component { @@ -27,12 +28,52 @@ class ViewFileToolbar extends React.Component { constructor(props) { super(props); this.state = { + isDropdownMenuOpen: false, isMoreMenuShow: false, isShareDialogShow: false, isEditTagDialogShow: false, }; } + toggleDropdownMenu = () => { + this.setState({isDropdownMenuOpen: !this.state.isDropdownMenuOpen}); + }; + + onDropdownToggleKeyDown = (e) => { + if (e.key == 'Enter' || e.key == 'Space') { + this.toggleDropdownMenu(); + } + }; + + onDropDownMouseMove = (e) => { + if (this.state.isSubMenuShown && e.target && e.target.className === 'dropdown-item') { + this.setState({ + isSubMenuShown: false + }); + } + }; + + toggleSubMenu = (e) => { + e.stopPropagation(); + this.setState({ + isSubMenuShown: !this.state.isSubMenuShown}, () => { + this.toggleDropdownMenu(); + }); + }; + + toggleSubMenuShown = (item) => { + this.setState({ + isSubMenuShown: true, + currentItem: item.text + }); + }; + + onMenuItemKeyDown = (item, e) => { + if (e.key == 'Enter' || e.key == 'Space') { + item.onClick(); + } + }; + onEditClick = (e) => { e.preventDefault(); let { path, repoID } = this.props; @@ -58,30 +99,110 @@ class ViewFileToolbar extends React.Component { }; render() { - let { filePermission } = this.props; + const { filePermission, showShareBtn } = this.props; + let opList = []; + + if (filePermission === 'rw' || filePermission === 'cloud-edit') { + opList.push({ + 'icon': 'rename', + 'text': gettext('Edit'), + 'onClick': this.onEditClick + }); + } + if (filePermission === 'rw') { + /* + let newSubOpList = []; + if (showShareBtn) { + newSubOpList.push({ + 'text': gettext('Share'), + 'onClick': this.onShareToggle + }); + } + newSubOpList.push( + {'text': gettext('Tags'), 'onClick': this.onEditFileTagToggle}, + {'text': gettext('History'), 'onClick': this.onHistoryClick} + ); + + opList.push({ + 'icon': 'more-vertical', + 'text': gettext('More'), + 'subOpList': newSubOpList + }); + */ + if (showShareBtn) { + opList.push({ + 'icon': 'share', + 'text': gettext('Share'), + 'onClick': this.onShareToggle + }); + } + + opList.push( + {'icon': 'tag', 'text': gettext('Tags'), 'onClick': this.onEditFileTagToggle}, + {'icon': 'history', 'text': gettext('History'), 'onClick': this.onHistoryClick} + ); + } + return ( -
- {(filePermission === 'rw' || filePermission === 'cloud-edit') && ( - - - - )} - {filePermission === 'rw' && ( - - - {gettext('More')} - - - {this.props.showShareBtn && - {gettext('Share')} - } - {gettext('Tags')} - {gettext('History')} - - - )} -
+ {opList.length > 0 && + + + {this.props.children} + + + + {opList.map((item, index)=> { + if (item == 'Divider') { + return ; + } else if (item.subOpList) { + return ( + {e.stopPropagation();}} + > + + + {item.text} + + + {item.subOpList.map((item, index)=> { + if (item == 'Divider') { + return ; + } else { + return ({item.text}); + } + })} + + + ); + } else { + return ( + + + {item.text} + + ); + } + })} + + + } {this.state.isShareDialogShow && ( } diff --git a/frontend/src/pages/lib-content-view/lib-content-toolbar.js b/frontend/src/pages/lib-content-view/lib-content-toolbar.js index b217f3ca51..b846a5631d 100644 --- a/frontend/src/pages/lib-content-view/lib-content-toolbar.js +++ b/frontend/src/pages/lib-content-view/lib-content-toolbar.js @@ -2,85 +2,18 @@ import React, { Fragment } from 'react'; import PropTypes from 'prop-types'; import { gettext } from '../../utils/constants'; import CommonToolbar from '../../components/toolbar/common-toolbar'; -import ViewFileToolbar from '../../components/toolbar/view-file-toolbar'; const propTypes = { - isViewFile: PropTypes.bool.isRequired, - filePermission: PropTypes.string, - fileTags: PropTypes.array.isRequired, - onFileTagChanged: PropTypes.func.isRequired, // for file-view-toolbar - // side-panel onSideNavMenuClick: PropTypes.func.isRequired, - // mutiple-dir - isDirentSelected: PropTypes.bool.isRequired, repoID: PropTypes.string.isRequired, - repoTags: PropTypes.array.isRequired, - path: PropTypes.string.isRequired, - selectedDirentList: PropTypes.array.isRequired, - onItemsMove: PropTypes.func.isRequired, - onItemsCopy: PropTypes.func.isRequired, - onItemsDelete: PropTypes.func.isRequired, - // dir - direntList: PropTypes.array.isRequired, repoName: PropTypes.string.isRequired, - repoEncrypted: PropTypes.bool.isRequired, - isGroupOwnedRepo: PropTypes.bool.isRequired, - userPerm: PropTypes.string.isRequired, - showShareBtn: PropTypes.bool.isRequired, - enableDirPrivateShare: PropTypes.bool.isRequired, - onAddFile: PropTypes.func.isRequired, - onAddFolder: PropTypes.func.isRequired, - onUploadFile: PropTypes.func.isRequired, - onUploadFolder: PropTypes.func.isRequired, - // view-mode - currentMode: PropTypes.string.isRequired, - switchViewMode: PropTypes.func.isRequired, - // search onSearchedClick: PropTypes.func.isRequired, - isRepoOwner: PropTypes.bool.isRequired, - // selected menu - onFilesTagChanged: PropTypes.func.isRequired, // for mutiple select toolbar - updateDirent: PropTypes.func.isRequired, - unSelectDirent: PropTypes.func, currentRepoInfo: PropTypes.object, - onItemRename: PropTypes.func, - showDirentDetail: PropTypes.func, }; class LibContentToolbar extends React.Component { render() { - - if (this.props.isViewFile) { - return ( - -
- - -
- -
- ); - } - return (