1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-29 08:37:55 +00:00
Files
seahub/frontend/src/pages/my-libs/mylib-repo-menu.js

268 lines
8.3 KiB
JavaScript
Raw Normal View History

import React from 'react';
import PropTypes from 'prop-types';
import { Dropdown, DropdownMenu, DropdownToggle, DropdownItem } from 'reactstrap';
import { gettext, isPro, folderPermEnabled, enableRepoSnapshotLabel, enableResetEncryptedRepoPassword, isEmailConfigured, enableMultipleOfficeSuite } from '../../utils/constants';
2019-06-04 16:18:32 +08:00
import { Utils } from '../../utils/utils';
import MobileItemMenu from '../../components/mobile-item-menu';
const propTypes = {
isPC: PropTypes.bool,
repo: PropTypes.object.isRequired,
isStarred: PropTypes.bool,
onFreezedItem: PropTypes.func,
onUnfreezedItem: PropTypes.func,
onMenuItemClick: PropTypes.func.isRequired,
};
class MylibRepoMenu extends React.Component {
constructor(props) {
super(props);
this.state = {
isItemMenuShow: false,
isAdvancedMenuShown: false
};
}
onMenuItemClick = (e) => {
const operation = Utils.getEventData(e, 'toggle');
this.props.onMenuItemClick(operation);
};
onMenuItemKeyDown = (e) => {
if (e.key == 'Enter' || e.key == 'Space') {
this.onMenuItemClick(e);
}
};
onDropdownToggleClick = (e) => {
this.toggleOperationMenu(e);
};
onDropdownToggleKeyDown = (e) => {
if (e.key == 'Enter' || e.key == 'Space') {
this.onDropdownToggleClick(e);
}
};
toggleOperationMenu = (e) => {
const { isLibView } = this.props;
if (isLibView) {
this.setState({ isItemMenuShow: !this.state.isItemMenuShow });
return;
}
let dataset = e.target ? e.target.dataset : null;
if (dataset && dataset.toggle && dataset.toggle === 'Rename') {
2024-07-18 11:58:42 +08:00
this.setState({ isItemMenuShow: !this.state.isItemMenuShow });
return;
}
this.setState(
2024-07-18 11:58:42 +08:00
{ isItemMenuShow: !this.state.isItemMenuShow },
() => {
if (this.state.isItemMenuShow) {
this.props.onFreezedItem();
} else {
this.props.onUnfreezedItem();
}
}
);
};
toggleAdvancedMenuShown = (e) => {
this.setState({ isAdvancedMenuShown: true });
};
toggleAdvancedMenu = (e) => {
e.stopPropagation();
this.setState({ isAdvancedMenuShown: !this.state.isAdvancedMenuShown }, () => {
this.toggleOperationMenu(e);
});
};
onDropDownMouseMove = (e) => {
if (this.state.isAdvancedMenuShown && e.target && e.target.className === 'dropdown-item') {
this.setState({
isAdvancedMenuShown: false
});
}
};
generatorOperations = () => {
let repo = this.props.repo;
let showResetPasswordMenuItem = isPro && repo.encrypted && enableResetEncryptedRepoPassword && isEmailConfigured;
let operations = ['Rename', 'Transfer'];
2020-03-09 21:13:16 +08:00
if (folderPermEnabled) {
operations.push('Folder Permission');
}
operations.push('Share Admin', 'Divider');
if (repo.encrypted) {
operations.push('Change Password');
}
if (showResetPasswordMenuItem) {
2019-05-15 14:56:46 +08:00
operations.push('Reset Password');
}
operations.push('Divider', 'Advanced');
// Remove adjacent excess 'Divider'
for (let i = 0; i < operations.length; i++) {
if (operations[i] === 'Divider' && operations[i + 1] === 'Divider') {
operations.splice(i, 1);
i--;
}
}
return operations;
};
getAdvancedOperations = () => {
const operations = [];
operations.push('API Token');
if (this.props.isPC && enableRepoSnapshotLabel) {
operations.push('Label Current State');
}
if (enableMultipleOfficeSuite && isPro) {
operations.push('Office Suite');
}
return operations;
};
translateOperations = (item) => {
let translateResult = '';
2024-07-18 11:58:42 +08:00
switch (item) {
case 'Star':
translateResult = gettext('Star');
break;
case 'Unstar':
translateResult = gettext('Unstar');
break;
case 'Share':
translateResult = gettext('Share');
break;
case 'Delete':
translateResult = gettext('Delete');
break;
case 'Rename':
translateResult = gettext('Rename');
break;
case 'Transfer':
translateResult = gettext('Transfer');
break;
case 'Change Password':
translateResult = gettext('Change Password');
break;
case 'Reset Password':
translateResult = gettext('Reset Password');
break;
case 'Folder Permission':
translateResult = gettext('Folder Permission');
break;
case 'Label Current State':
translateResult = gettext('Label Current State');
break;
case 'API Token':
translateResult = 'API Token'; // translation is not needed here
break;
case 'Share Admin':
translateResult = gettext('Share Admin');
break;
case 'Advanced':
translateResult = gettext('Advanced');
break;
case 'Office Suite':
translateResult = gettext('Office Suite');
break;
default:
break;
}
return translateResult;
};
render() {
let operations = this.generatorOperations();
const advancedOperations = this.getAdvancedOperations();
const { children, isLibView } = this.props;
// pc menu
if (this.props.isPC) {
return (
<Dropdown
isOpen={this.state.isItemMenuShow}
toggle={this.toggleOperationMenu}
direction={isLibView ? 'end' : 'down'}
className={isLibView ? 'd-block' : ''}
>
<DropdownToggle
Icon bg (#7871) * ['Files', 'my libs', 'shared with me', 'shared with all', 'group', 'department' pages] added background to the library items' operation icons when hovering on them * ['share' dialog] 'Share Link'(link list, link-authenticated-emails, link-authenticated-users): added background to the items' operation icons when hovering on them * ['share' dialog] 'Share to user': added background for the sharing items and the operation icons when hover on them * [select editor] improved it; added background to the 'edit' icon when hover on it * ['share' dialog] 'Share to group': added background for the sharing items and the operation icons when hover on them; fixed it for mobile * ['share' dialog] 'Custom sharing permissions': added background for the permission items and the operation icons when hover on them * ['share' dialog] 'Invite Guest': added background for the items and the operation icons when hover on them * ['share' dialog] 'Share to other server': added background for the items and the operation icons when hover on them * [repo 'Folder Permission' dialog] 'User Permission': added background for the items and the operation icons when hover on them * [repo 'Folder Permission' dialog] 'Group Permission': added background for the items and the operation icons when hover on them * [repo 'Share Admin' dialog] 'Share Link': added background for the sharing items and the operation icons when hover on them; improved it * [repo 'Share Admin' dialog] 'Upload Link': added background for the sharing items and the operation icons when hover on them; improved it * [repo 'Share Admin' dialog] 'User Shares': added background for the sharing items and the operation icons when hover on them; improved the permission editor * [repo 'Share Admin' dialog] 'Group Shares': added background for the sharing items and the operation icons when hover on them; improved the permission editor * [repo 'API Token' dialog] added background for the items and the operation icons when hover on them * [group/department 'Manage group members' dialog] added background for the operation icons when hover on them * ['select members from departments' dialog] added background for the operation icons when hover on them * [library list pages] removed the background when hover on the 'star/unstar' icons of the library items * ['back' icons] added background for the 'go back' icons when hover on them * ['my deleted repos' dialog] added background for the operation icons when hover on them * ['Favorites' page] added background for the items and the operation icons when hover on them * ['Wikis' page] added background for the operation icons when hover on them * ['Invite Guest' page] added background for the items and the operation icons when hover on them * ['Share Admin'] 'Libraries' page: added background for the items and the operation icons when hover on them * ['Share Admin'] 'Folders' page: added background for the items and the operation icons when hover on them * ['Share Admin'] 'Share Links' page: added background for the items and the operation icons when hover on them * ['Share Admin'] 'Upload Links' page: added background for the operation icons when hover on them * [repo 'Modification History' dialog] added background for the operation icons when hover on them * [repo 'Snapshot' page] added background for the items and the operation icons when hover on them * [folder 'share link' page] added background for the items and the operation icons when hover on them * [file 'History Versions' page] changed the 'more' icon and added background for the the operation icons when hover on them * [personal 'settings' page] 'Linked Devices': added background for the items and the operation icons when hover on them * ['library view' page] 'move/copy' dialog: added background for the 'clear search keyword' icon when hover on it * ['library view' page] added background for the operation icons when hover on them * ['system admin'] 'Devices' pages: added background for the items and the operation icons when hover on them * [system admin] repos/users/groups/inst/... pages: added background for the operation icons when hover on them * [system admin] 'Libraries - Trash' page: added background for the items and the operation icons when hover on them * [system admin] 'Users' pages: added background for the operation icons when hover on them * [system admin] 'Departments' pages: added background for the operation icons when hover on them * [system admin] 'Organizations' & 'Search Organizations' pages: added background for the operation icons when hover on them * [system admin] 'Institutions' pages: added background for items & the operation icons when hover on them * [system admin] 'terms and conditions' pages: added background for items & the operation icons when hover on them * [system admin] 'Links - Share Links' pages: added background for items & the operation icons when hover on them * [system admin] 'Links - Upload Links' pages: added background for items & the operation icons when hover on them * org page use new op-icon * use common edit icon --------- Co-authored-by: Michael An <1822852997@qq.com>
2025-05-31 12:01:08 +08:00
tag={isLibView ? 'div' : 'i'}
className={isLibView ? 'dir-others-item' : 'op-icon sf3-font-more sf3-font'}
role="button"
tabIndex="0"
title={isLibView ? gettext('More') : gettext('More operations')}
2024-01-03 18:08:24 +08:00
aria-label={gettext('More operations')}
onClick={this.onDropdownToggleClick}
onKeyDown={this.onDropdownToggleKeyDown}
data-toggle="dropdown"
>
Icon bg (#7871) * ['Files', 'my libs', 'shared with me', 'shared with all', 'group', 'department' pages] added background to the library items' operation icons when hovering on them * ['share' dialog] 'Share Link'(link list, link-authenticated-emails, link-authenticated-users): added background to the items' operation icons when hovering on them * ['share' dialog] 'Share to user': added background for the sharing items and the operation icons when hover on them * [select editor] improved it; added background to the 'edit' icon when hover on it * ['share' dialog] 'Share to group': added background for the sharing items and the operation icons when hover on them; fixed it for mobile * ['share' dialog] 'Custom sharing permissions': added background for the permission items and the operation icons when hover on them * ['share' dialog] 'Invite Guest': added background for the items and the operation icons when hover on them * ['share' dialog] 'Share to other server': added background for the items and the operation icons when hover on them * [repo 'Folder Permission' dialog] 'User Permission': added background for the items and the operation icons when hover on them * [repo 'Folder Permission' dialog] 'Group Permission': added background for the items and the operation icons when hover on them * [repo 'Share Admin' dialog] 'Share Link': added background for the sharing items and the operation icons when hover on them; improved it * [repo 'Share Admin' dialog] 'Upload Link': added background for the sharing items and the operation icons when hover on them; improved it * [repo 'Share Admin' dialog] 'User Shares': added background for the sharing items and the operation icons when hover on them; improved the permission editor * [repo 'Share Admin' dialog] 'Group Shares': added background for the sharing items and the operation icons when hover on them; improved the permission editor * [repo 'API Token' dialog] added background for the items and the operation icons when hover on them * [group/department 'Manage group members' dialog] added background for the operation icons when hover on them * ['select members from departments' dialog] added background for the operation icons when hover on them * [library list pages] removed the background when hover on the 'star/unstar' icons of the library items * ['back' icons] added background for the 'go back' icons when hover on them * ['my deleted repos' dialog] added background for the operation icons when hover on them * ['Favorites' page] added background for the items and the operation icons when hover on them * ['Wikis' page] added background for the operation icons when hover on them * ['Invite Guest' page] added background for the items and the operation icons when hover on them * ['Share Admin'] 'Libraries' page: added background for the items and the operation icons when hover on them * ['Share Admin'] 'Folders' page: added background for the items and the operation icons when hover on them * ['Share Admin'] 'Share Links' page: added background for the items and the operation icons when hover on them * ['Share Admin'] 'Upload Links' page: added background for the operation icons when hover on them * [repo 'Modification History' dialog] added background for the operation icons when hover on them * [repo 'Snapshot' page] added background for the items and the operation icons when hover on them * [folder 'share link' page] added background for the items and the operation icons when hover on them * [file 'History Versions' page] changed the 'more' icon and added background for the the operation icons when hover on them * [personal 'settings' page] 'Linked Devices': added background for the items and the operation icons when hover on them * ['library view' page] 'move/copy' dialog: added background for the 'clear search keyword' icon when hover on it * ['library view' page] added background for the operation icons when hover on them * ['system admin'] 'Devices' pages: added background for the items and the operation icons when hover on them * [system admin] repos/users/groups/inst/... pages: added background for the operation icons when hover on them * [system admin] 'Libraries - Trash' page: added background for the items and the operation icons when hover on them * [system admin] 'Users' pages: added background for the operation icons when hover on them * [system admin] 'Departments' pages: added background for the operation icons when hover on them * [system admin] 'Organizations' & 'Search Organizations' pages: added background for the operation icons when hover on them * [system admin] 'Institutions' pages: added background for items & the operation icons when hover on them * [system admin] 'terms and conditions' pages: added background for items & the operation icons when hover on them * [system admin] 'Links - Share Links' pages: added background for items & the operation icons when hover on them * [system admin] 'Links - Upload Links' pages: added background for items & the operation icons when hover on them * org page use new op-icon * use common edit icon --------- Co-authored-by: Michael An <1822852997@qq.com>
2025-05-31 12:01:08 +08:00
{children}
</DropdownToggle>
<DropdownMenu onMouseMove={this.onDropDownMouseMove} container={isLibView ? 'body' : ''}>
2024-07-18 11:58:42 +08:00
{operations.map((item, index) => {
2020-03-09 21:13:16 +08:00
if (item == 'Divider') {
return <DropdownItem key={index} divider />;
} else if (item == 'Advanced') {
return (
<Dropdown
key={index}
direction="right"
className="w-100"
isOpen={this.state.isAdvancedMenuShown}
toggle={this.toggleAdvancedMenu}
onMouseMove={(e) => {e.stopPropagation();}}
>
<DropdownToggle
tag="span"
className="dropdown-item font-weight-normal rounded-0 d-flex justify-content-between align-items-center pr-2"
onMouseEnter={this.toggleAdvancedMenuShown}
>
{this.translateOperations(item)}
<i className="sf3-font-down sf3-font rotate-270"></i>
</DropdownToggle>
<DropdownMenu>
2024-07-18 11:58:42 +08:00
{advancedOperations.map((item, index) => {
return (<DropdownItem key={index} data-toggle={item} onClick={this.onMenuItemClick} onKeyDown={this.onMenuItemKeyDown}>{this.translateOperations(item)}</DropdownItem>);
})}
</DropdownMenu>
</Dropdown>
);
2020-03-09 21:13:16 +08:00
} else {
return (<DropdownItem key={index} data-toggle={item} onClick={this.onMenuItemClick} onKeyDown={this.onMenuItemKeyDown}>{this.translateOperations(item)}</DropdownItem>);
2020-03-09 21:13:16 +08:00
}
})}
</DropdownMenu>
</Dropdown>
2019-05-15 14:56:46 +08:00
);
}
// mobile menu
operations.pop(); // removed the last item 'Advanced'
operations.unshift('Delete');
operations.unshift('Share');
this.props.isStarred ? operations.unshift('Unstar') : operations.unshift('Star');
return (
<MobileItemMenu isOpen={this.state.isItemMenuShow} toggle={this.toggleOperationMenu}>
{operations.filter(item => item != 'Divider').map((item, index) => {
return (<DropdownItem key={index} className="mobile-menu-item" data-toggle={item} onClick={this.onMenuItemClick}>{this.translateOperations(item)}</DropdownItem>);
})}
</MobileItemMenu>
);
}
}
MylibRepoMenu.propTypes = propTypes;
export default MylibRepoMenu;