2023-10-09 21:27:44 +08:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { v4 as uuidv4 } from 'uuid';
|
2018-11-28 12:41:49 +08:00
|
|
|
import { gettext, siteRoot } from '../../utils/constants';
|
2018-10-09 10:56:59 +08:00
|
|
|
import { Utils } from '../../utils/utils';
|
2023-10-09 21:27:44 +08:00
|
|
|
import SeahubPopover from '../common/seahub-popover';
|
|
|
|
import ListTagPopover from '../popover/list-tag-popover';
|
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,
|
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 = {
|
|
|
|
isListRepoTagShow: false,
|
|
|
|
};
|
2023-10-09 21:27:44 +08:00
|
|
|
this.tagsIconID = `tags-icon-${uuidv4()}`;
|
2018-11-02 15:34:34 +08:00
|
|
|
}
|
|
|
|
|
2023-12-19 12:13:49 +08:00
|
|
|
onMouseDown = (e) => {
|
|
|
|
e.stopPropagation();
|
|
|
|
};
|
|
|
|
|
|
|
|
toggleRepoTag = (e) => {
|
|
|
|
e.stopPropagation();
|
|
|
|
this.setState({ isListRepoTagShow: !this.state.isListRepoTagShow });
|
2023-09-13 08:40:50 +08:00
|
|
|
};
|
2018-12-21 12:33:31 +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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.setState({ isListRepoTagShow: 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 = () => {
|
|
|
|
this.setState({ isListRepoTagShow: false });
|
2023-09-13 08:40:50 +08:00
|
|
|
};
|
2018-11-19 17:44:59 +08:00
|
|
|
|
2018-09-29 15:47:53 +08:00
|
|
|
isMarkdownFile(filePath) {
|
2023-10-09 21:27:44 +08:00
|
|
|
return Utils.getFileName(filePath).includes('.md');
|
2018-09-29 15:47:53 +08:00
|
|
|
}
|
2018-11-22 11:26:00 +08:00
|
|
|
|
2018-09-29 15:47:53 +08:00
|
|
|
render() {
|
2022-02-26 11:22:59 +08:00
|
|
|
let { repoID, userPerm, currentPath } = this.props;
|
2023-10-09 21:27:44 +08:00
|
|
|
if (userPerm !== 'rw') {
|
|
|
|
return '';
|
2018-09-29 15:47:53 +08:00
|
|
|
}
|
2023-10-09 21:27:44 +08:00
|
|
|
if (this.isMarkdownFile(currentPath)) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
let toolbarDom = null;
|
|
|
|
if (Utils.getFileName(currentPath)) { // name not '' is not root path
|
|
|
|
let trashUrl = siteRoot + 'repo/' + repoID + '/trash/?path=' + encodeURIComponent(currentPath);
|
|
|
|
toolbarDom = (
|
|
|
|
<ul className="path-toolbar">
|
|
|
|
<li className="toolbar-item">
|
2023-12-19 12:13:49 +08:00
|
|
|
<a
|
|
|
|
className="op-link sf2-icon-tag"
|
|
|
|
href="#"
|
|
|
|
id={this.tagsIconID}
|
|
|
|
role="button"
|
|
|
|
onClick={this.toggleRepoTag}
|
|
|
|
onMouseDown={this.onMouseDown}
|
|
|
|
title={gettext('Tags')}
|
|
|
|
aria-label={gettext('Tags')}
|
|
|
|
></a>
|
2023-10-09 21:27:44 +08:00
|
|
|
</li>
|
|
|
|
<li className="toolbar-item">
|
|
|
|
<a className="op-link sf2-icon-recycle" href={trashUrl} title={gettext('Trash')} aria-label={gettext('Trash')}></a>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
);
|
|
|
|
} else { // currentPath === '/' is root path
|
|
|
|
let trashUrl = siteRoot + 'repo/' + repoID + '/trash/';
|
|
|
|
let historyUrl = siteRoot + 'repo/history/' + repoID + '/';
|
|
|
|
toolbarDom = (
|
|
|
|
<ul className="path-toolbar">
|
|
|
|
<li className="toolbar-item">
|
2023-12-19 12:13:49 +08:00
|
|
|
<a
|
|
|
|
className="op-link sf2-icon-tag"
|
|
|
|
href="#"
|
|
|
|
id={this.tagsIconID}
|
|
|
|
role="button"
|
|
|
|
onClick={this.toggleRepoTag}
|
|
|
|
onMouseDown={this.onMouseDown}
|
|
|
|
title={gettext('Tags')}
|
|
|
|
aria-label={gettext('Tags')}
|
|
|
|
></a>
|
2023-10-09 21:27:44 +08:00
|
|
|
</li>
|
|
|
|
<li className="toolbar-item">
|
|
|
|
<a className="op-link sf2-icon-recycle" href={trashUrl} title={gettext('Trash')} aria-label={gettext('Trash')}></a>
|
|
|
|
</li>
|
|
|
|
<li className="toolbar-item">
|
|
|
|
<a className="op-link sf2-icon-history" href={historyUrl} title={gettext('History')} aria-label={gettext('History')}></a>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{toolbarDom}
|
|
|
|
{this.state.isListRepoTagShow &&
|
|
|
|
<SeahubPopover
|
|
|
|
popoverClassName="list-tag-popover"
|
|
|
|
target={this.tagsIconID}
|
|
|
|
hideSeahubPopover={this.hidePopover}
|
|
|
|
hideSeahubPopoverWithEsc={this.hidePopover}
|
|
|
|
canHideSeahubPopover={true}
|
|
|
|
boundariesElement={document.body}
|
|
|
|
placement={'bottom-end'}
|
|
|
|
>
|
|
|
|
<ListTagPopover
|
|
|
|
repoID={repoID}
|
|
|
|
onListTagCancel={this.toggleCancel}
|
|
|
|
/>
|
|
|
|
</SeahubPopover>
|
|
|
|
}
|
|
|
|
</>
|
|
|
|
);
|
2018-09-29 15:47:53 +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;
|