2023-10-09 21:27:44 +08:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2024-05-21 21:06:50 +08:00
|
|
|
import { Dropdown, DropdownMenu, DropdownToggle, DropdownItem } from 'reactstrap';
|
2024-08-02 13:27:20 +08:00
|
|
|
import { gettext, enableFileTags } from '../../utils/constants';
|
2018-10-09 10:56:59 +08:00
|
|
|
import { Utils } from '../../utils/utils';
|
2024-05-21 21:06:50 +08:00
|
|
|
import TextTranslation from '../../utils/text-translation';
|
2025-03-01 10:12:48 +08:00
|
|
|
import CustomizePopover from '../customize-popover';
|
2023-10-09 21:27:44 +08:00
|
|
|
import ListTagPopover from '../popover/list-tag-popover';
|
2024-06-17 16:52:44 +08:00
|
|
|
import ViewModes from '../../components/view-modes';
|
2024-11-25 10:23:42 +08:00
|
|
|
import SortMenu from '../../components/sort-menu';
|
2024-09-14 16:31:32 +08:00
|
|
|
import MetadataViewToolBar from '../../metadata/components/view-toolbar';
|
2025-02-09 17:59:27 +08:00
|
|
|
import TagsTableSearcher from '../../tag/views/all-tags/tags-table/tags-searcher';
|
2024-07-09 15:09:34 +08:00
|
|
|
import { PRIVATE_FILE_TYPE } from '../../constants';
|
2018-09-18 20:57:17 -05:00
|
|
|
|
2018-09-29 15:47:53 +08:00
|
|
|
const propTypes = {
|
2018-11-28 12:41:49 +08:00
|
|
|
repoID: PropTypes.string.isRequired,
|
2021-09-13 10:37:07 +08:00
|
|
|
userPerm: PropTypes.string,
|
2018-11-28 12:41:49 +08:00
|
|
|
currentPath: PropTypes.string.isRequired,
|
2019-02-27 14:14:28 +08:00
|
|
|
updateUsedRepoTags: PropTypes.func.isRequired,
|
2019-03-25 15:23:37 +08:00
|
|
|
onDeleteRepoTag: PropTypes.func.isRequired,
|
2024-05-21 21:06:50 +08:00
|
|
|
currentMode: PropTypes.string.isRequired,
|
|
|
|
switchViewMode: PropTypes.func.isRequired,
|
|
|
|
isCustomPermission: PropTypes.bool,
|
2024-07-17 11:09:53 +08:00
|
|
|
sortBy: PropTypes.string,
|
|
|
|
sortOrder: PropTypes.string,
|
|
|
|
sortItems: PropTypes.func,
|
2024-08-12 17:15:56 +08:00
|
|
|
viewId: PropTypes.string,
|
2024-12-23 17:47:20 +08:00
|
|
|
onToggleDetail: PropTypes.func,
|
2024-12-24 17:52:18 +08:00
|
|
|
onCloseDetail: PropTypes.func,
|
2018-09-29 15:47:53 +08:00
|
|
|
};
|
2018-09-18 20:57:17 -05:00
|
|
|
|
2018-11-27 14:47:19 +08:00
|
|
|
class DirTool extends React.Component {
|
2018-09-18 20:57:17 -05:00
|
|
|
|
2018-11-02 15:34:34 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
2024-05-21 21:06:50 +08:00
|
|
|
isRepoTagDialogOpen: false,
|
2024-07-17 11:09:53 +08:00
|
|
|
isDropdownMenuOpen: false,
|
2018-11-02 15:34:34 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-05-21 21:06:50 +08:00
|
|
|
toggleDropdownMenu = () => {
|
|
|
|
this.setState({
|
|
|
|
isDropdownMenuOpen: !this.state.isDropdownMenuOpen
|
|
|
|
});
|
2023-12-19 12:13:49 +08:00
|
|
|
};
|
|
|
|
|
2023-10-09 21:27:44 +08:00
|
|
|
hidePopover = (e) => {
|
|
|
|
if (e) {
|
|
|
|
let dom = e.target;
|
|
|
|
while (dom) {
|
|
|
|
if (typeof dom.className === 'string' && dom.className.includes('tag-color-popover')) return;
|
|
|
|
dom = dom.parentNode;
|
|
|
|
}
|
|
|
|
}
|
2024-07-18 11:58:42 +08:00
|
|
|
this.setState({ isRepoTagDialogOpen: false });
|
2023-09-13 08:40:50 +08:00
|
|
|
};
|
2018-11-02 15:34:34 +08:00
|
|
|
|
2023-10-09 21:27:44 +08:00
|
|
|
toggleCancel = () => {
|
2024-07-18 11:58:42 +08:00
|
|
|
this.setState({ isRepoTagDialogOpen: false });
|
2023-09-13 08:40:50 +08:00
|
|
|
};
|
2018-11-19 17:44:59 +08:00
|
|
|
|
2024-07-01 11:25:08 +08:00
|
|
|
getMenu = () => {
|
2024-05-21 21:06:50 +08:00
|
|
|
const list = [];
|
2024-07-09 09:45:50 +08:00
|
|
|
const { userPerm, currentPath } = this.props;
|
|
|
|
if (userPerm !== 'rw' || Utils.isMarkdownFile(currentPath)) {
|
2024-05-21 21:06:50 +08:00
|
|
|
return list;
|
2018-09-29 15:47:53 +08:00
|
|
|
}
|
2024-07-09 09:45:50 +08:00
|
|
|
const { TAGS } = TextTranslation;
|
2024-08-02 13:27:20 +08:00
|
|
|
if (enableFileTags) {
|
|
|
|
list.push(TAGS);
|
|
|
|
}
|
2024-05-21 21:06:50 +08:00
|
|
|
return list;
|
|
|
|
};
|
|
|
|
|
|
|
|
onMenuItemClick = (item) => {
|
2024-07-09 09:45:50 +08:00
|
|
|
const { key } = item;
|
2024-05-22 14:33:03 +08:00
|
|
|
switch (key) {
|
2024-05-21 21:06:50 +08:00
|
|
|
case 'Tags':
|
2024-07-18 11:58:42 +08:00
|
|
|
this.setState({ isRepoTagDialogOpen: !this.state.isRepoTagDialogOpen });
|
2024-05-21 21:06:50 +08:00
|
|
|
break;
|
2023-10-09 21:27:44 +08:00
|
|
|
}
|
2024-05-21 21:06:50 +08:00
|
|
|
};
|
|
|
|
|
2024-05-22 14:33:03 +08:00
|
|
|
onMenuItemKeyDown = (e, item) => {
|
2024-05-21 21:06:50 +08:00
|
|
|
if (e.key == 'Enter' || e.key == 'Space') {
|
2024-05-22 14:33:03 +08:00
|
|
|
this.onMenuItemClick(item);
|
2024-05-21 21:06:50 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-07-17 11:09:53 +08:00
|
|
|
onSelectSortOption = (item) => {
|
|
|
|
const [sortBy, sortOrder] = item.value.split('-');
|
|
|
|
this.props.sortItems(sortBy, sortOrder);
|
|
|
|
};
|
|
|
|
|
2024-05-21 21:06:50 +08:00
|
|
|
render() {
|
2024-07-01 11:25:08 +08:00
|
|
|
const menuItems = this.getMenu();
|
2024-06-17 16:52:44 +08:00
|
|
|
const { isDropdownMenuOpen } = this.state;
|
2024-12-24 17:52:18 +08:00
|
|
|
const { repoID, currentMode, currentPath, sortBy, sortOrder, viewId, isCustomPermission, onToggleDetail, onCloseDetail } = this.props;
|
2024-07-01 11:25:08 +08:00
|
|
|
const propertiesText = TextTranslation.PROPERTIES.value;
|
2024-07-22 09:45:08 +08:00
|
|
|
const isFileExtended = currentPath.startsWith('/' + PRIVATE_FILE_TYPE.FILE_EXTENDED_PROPERTIES + '/');
|
2024-11-22 17:11:55 +08:00
|
|
|
const isTagView = currentPath.startsWith('/' + PRIVATE_FILE_TYPE.TAGS_PROPERTIES + '/');
|
2024-07-10 18:18:57 +08:00
|
|
|
|
|
|
|
if (isFileExtended) {
|
|
|
|
return (
|
2024-08-21 17:14:57 +08:00
|
|
|
<div className="dir-tool">
|
2024-11-15 16:08:46 +08:00
|
|
|
<MetadataViewToolBar
|
|
|
|
viewId={viewId}
|
|
|
|
isCustomPermission={isCustomPermission}
|
2024-12-23 17:47:20 +08:00
|
|
|
onToggleDetail={onToggleDetail}
|
2024-12-24 17:52:18 +08:00
|
|
|
onCloseDetail={onCloseDetail}
|
2024-11-15 16:08:46 +08:00
|
|
|
/>
|
2024-07-10 18:18:57 +08:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-11-22 17:11:55 +08:00
|
|
|
if (isTagView) {
|
|
|
|
return (
|
|
|
|
<div className="dir-tool">
|
2025-02-09 17:59:27 +08:00
|
|
|
<TagsTableSearcher />
|
2024-11-22 17:11:55 +08:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-10-09 21:27:44 +08:00
|
|
|
return (
|
2024-05-21 21:06:50 +08:00
|
|
|
<React.Fragment>
|
2024-07-25 11:02:55 +08:00
|
|
|
<div className="dir-tool d-flex">
|
2024-06-17 16:52:44 +08:00
|
|
|
<ViewModes currentViewMode={currentMode} switchViewMode={this.props.switchViewMode} />
|
2024-11-25 10:23:42 +08:00
|
|
|
<SortMenu sortBy={sortBy} sortOrder={sortOrder} onSelectSortOption={this.onSelectSortOption} />
|
2024-10-18 16:01:00 +08:00
|
|
|
{(!isCustomPermission) &&
|
2024-12-23 17:47:20 +08:00
|
|
|
<div className="cur-view-path-btn" onClick={onToggleDetail}>
|
2024-07-01 11:25:08 +08:00
|
|
|
<span className="sf3-font sf3-font-info" aria-label={propertiesText} title={propertiesText}></span>
|
2024-07-25 11:02:55 +08:00
|
|
|
</div>
|
2024-07-01 11:25:08 +08:00
|
|
|
}
|
2024-05-21 21:06:50 +08:00
|
|
|
{menuItems.length > 0 &&
|
|
|
|
<Dropdown isOpen={isDropdownMenuOpen} toggle={this.toggleDropdownMenu}>
|
|
|
|
<DropdownToggle
|
2024-06-13 15:27:20 +08:00
|
|
|
tag="i"
|
2024-05-21 21:06:50 +08:00
|
|
|
id="cur-folder-more-op-toggle"
|
2024-07-25 11:02:55 +08:00
|
|
|
className='cur-view-path-btn sf3-font-more sf3-font'
|
2024-05-21 21:06:50 +08:00
|
|
|
data-toggle="dropdown"
|
|
|
|
title={gettext('More operations')}
|
|
|
|
aria-label={gettext('More operations')}
|
|
|
|
aria-expanded={isDropdownMenuOpen}
|
|
|
|
>
|
|
|
|
</DropdownToggle>
|
2025-02-14 14:04:25 +08:00
|
|
|
<DropdownMenu>
|
2024-05-21 21:06:50 +08:00
|
|
|
{menuItems.map((menuItem, index) => {
|
|
|
|
if (menuItem === 'Divider') {
|
|
|
|
return <DropdownItem key={index} divider />;
|
|
|
|
} else {
|
|
|
|
return (
|
2024-07-01 11:25:08 +08:00
|
|
|
<DropdownItem
|
|
|
|
key={index}
|
|
|
|
onClick={this.onMenuItemClick.bind(this, menuItem)}
|
|
|
|
onKeyDown={this.onMenuItemKeyDown.bind(this, menuItem)}
|
|
|
|
>{menuItem.value}
|
|
|
|
</DropdownItem>
|
2024-05-21 21:06:50 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
})}
|
|
|
|
</DropdownMenu>
|
|
|
|
</Dropdown>
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
{this.state.isRepoTagDialogOpen &&
|
2025-03-01 10:12:48 +08:00
|
|
|
<CustomizePopover
|
2024-05-21 21:06:50 +08:00
|
|
|
popoverClassName="list-tag-popover"
|
|
|
|
target="cur-folder-more-op-toggle"
|
2025-03-01 10:12:48 +08:00
|
|
|
hidePopover={this.hidePopover}
|
|
|
|
hidePopoverWithEsc={this.hidePopover}
|
2024-05-21 21:06:50 +08:00
|
|
|
boundariesElement={document.body}
|
|
|
|
placement={'bottom-end'}
|
|
|
|
>
|
|
|
|
<ListTagPopover
|
|
|
|
repoID={repoID}
|
|
|
|
onListTagCancel={this.toggleCancel}
|
|
|
|
/>
|
2025-03-01 10:12:48 +08:00
|
|
|
</CustomizePopover>
|
2023-10-09 21:27:44 +08:00
|
|
|
}
|
2024-05-21 21:06:50 +08:00
|
|
|
</React.Fragment>
|
2023-10-09 21:27:44 +08:00
|
|
|
);
|
2018-09-29 15:47:53 +08:00
|
|
|
}
|
2024-05-21 21:06:50 +08:00
|
|
|
|
2018-09-18 20:57:17 -05:00
|
|
|
}
|
|
|
|
|
2018-11-27 14:47:19 +08:00
|
|
|
DirTool.propTypes = propTypes;
|
2018-09-29 15:47:53 +08:00
|
|
|
|
2018-11-27 14:47:19 +08:00
|
|
|
export default DirTool;
|