1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-05 00:43:53 +00:00
Files
seahub/frontend/src/components/cur-dir-path/dir-tool.js

138 lines
4.0 KiB
JavaScript
Raw Normal View History

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';
import { Utils } from '../../utils/utils';
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,
userPerm: PropTypes.string,
2018-11-28 12:41:49 +08:00
currentPath: PropTypes.string.isRequired,
updateUsedRepoTags: PropTypes.func.isRequired,
onDeleteRepoTag: PropTypes.func.isRequired,
2018-09-29 15:47:53 +08:00
};
2018-09-18 20:57:17 -05: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,
};
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 });
};
2018-12-21 12:33:31 +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 });
};
2018-11-02 15:34:34 +08:00
toggleCancel = () => {
this.setState({ isListRepoTagShow: false });
};
2018-11-19 17:44:59 +08:00
2018-09-29 15:47:53 +08:00
isMarkdownFile(filePath) {
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;
if (userPerm !== 'rw') {
return '';
2018-09-29 15:47:53 +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>
</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>
</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
}
DirTool.propTypes = propTypes;
2018-09-29 15:47:53 +08:00
export default DirTool;