2019-03-15 02:10:24 +00:00
|
|
|
import React, { Fragment } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2024-03-25 09:22:01 +00:00
|
|
|
import { DropdownToggle, Dropdown, DropdownMenu, DropdownItem } from 'reactstrap';
|
|
|
|
import { gettext, siteRoot } from '../../utils/constants';
|
2019-07-16 02:01:09 +00:00
|
|
|
import { Utils } from '../../utils/utils';
|
2019-03-15 02:10:24 +00:00
|
|
|
import ModalPotal from '../modal-portal';
|
|
|
|
import ShareDialog from '../dialog/share-dialog';
|
|
|
|
import EditFileTagDialog from '../dialog/edit-filetag-dialog';
|
|
|
|
|
|
|
|
const propTypes = {
|
|
|
|
path: PropTypes.string.isRequired,
|
|
|
|
repoID: PropTypes.string.isRequired,
|
2024-02-02 12:52:58 +00:00
|
|
|
repoTags: PropTypes.array.isRequired,
|
2019-03-15 02:10:24 +00:00
|
|
|
userPerm: PropTypes.string.isRequired,
|
|
|
|
repoEncrypted: PropTypes.bool.isRequired,
|
|
|
|
enableDirPrivateShare: PropTypes.bool.isRequired,
|
|
|
|
isGroupOwnedRepo: PropTypes.bool.isRequired,
|
2019-04-19 07:50:27 +00:00
|
|
|
filePermission: PropTypes.string,
|
2019-03-15 02:10:24 +00:00
|
|
|
fileTags: PropTypes.array.isRequired,
|
|
|
|
onFileTagChanged: PropTypes.func.isRequired,
|
2019-04-25 10:28:52 +00:00
|
|
|
showShareBtn: PropTypes.bool.isRequired,
|
2023-12-26 06:35:44 +00:00
|
|
|
dirent: PropTypes.object,
|
2019-03-15 02:10:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class ViewFileToolbar extends React.Component {
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
2019-04-22 02:29:41 +00:00
|
|
|
isMoreMenuShow: false,
|
2019-03-15 02:10:24 +00:00
|
|
|
isShareDialogShow: false,
|
|
|
|
isEditTagDialogShow: false,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
onEditClick = (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
let { path, repoID } = this.props;
|
|
|
|
let url = siteRoot + 'lib/' + repoID + '/file' + Utils.encodePath(path) + '?mode=edit';
|
|
|
|
window.open(url);
|
2023-09-13 00:40:50 +00:00
|
|
|
};
|
2019-03-15 02:10:24 +00:00
|
|
|
|
2019-04-22 02:29:41 +00:00
|
|
|
toggleMore = () => {
|
|
|
|
this.setState({isMoreMenuShow: !this.state.isMoreMenuShow});
|
2023-09-13 00:40:50 +00:00
|
|
|
};
|
2019-03-15 02:10:24 +00:00
|
|
|
|
|
|
|
onShareToggle = () => {
|
|
|
|
this.setState({isShareDialogShow: !this.state.isShareDialogShow});
|
2023-09-13 00:40:50 +00:00
|
|
|
};
|
2019-03-15 02:10:24 +00:00
|
|
|
|
|
|
|
onEditFileTagToggle = () => {
|
|
|
|
this.setState({isEditTagDialogShow: !this.state.isEditTagDialogShow});
|
2023-09-13 00:40:50 +00:00
|
|
|
};
|
2019-03-15 02:10:24 +00:00
|
|
|
|
2019-07-10 07:53:47 +00:00
|
|
|
onHistoryClick = () => {
|
|
|
|
let historyUrl = siteRoot + 'repo/file_revisions/' + this.props.repoID + '/?p=' + Utils.encodePath(this.props.path);
|
|
|
|
location.href = historyUrl;
|
2023-09-13 00:40:50 +00:00
|
|
|
};
|
2019-07-10 07:53:47 +00:00
|
|
|
|
2019-03-15 02:10:24 +00:00
|
|
|
render() {
|
2019-04-19 07:50:27 +00:00
|
|
|
let { filePermission } = this.props;
|
2019-03-15 02:10:24 +00:00
|
|
|
return (
|
|
|
|
<Fragment>
|
|
|
|
<div className="dir-operation">
|
2024-03-25 09:22:01 +00:00
|
|
|
{(filePermission === 'rw' || filePermission === 'cloud-edit') && (
|
2019-03-15 02:10:24 +00:00
|
|
|
<Fragment>
|
|
|
|
<button className="btn btn-secondary operation-item" title={gettext('Edit File')} onClick={this.onEditClick}>{gettext('Edit')}</button>
|
|
|
|
</Fragment>
|
|
|
|
)}
|
2019-04-19 07:50:27 +00:00
|
|
|
{filePermission === 'rw' && (
|
2019-04-22 02:29:41 +00:00
|
|
|
<Dropdown isOpen={this.state.isMoreMenuShow} toggle={this.toggleMore}>
|
|
|
|
<DropdownToggle className='btn btn-secondary operation-item'>
|
|
|
|
{gettext('More')}
|
|
|
|
</DropdownToggle>
|
|
|
|
<DropdownMenu>
|
2020-11-02 05:56:35 +00:00
|
|
|
{this.props.showShareBtn &&
|
2019-04-25 07:09:28 +00:00
|
|
|
<DropdownItem onClick={this.onShareToggle}>{gettext('Share')}</DropdownItem>
|
|
|
|
}
|
2019-04-22 02:29:41 +00:00
|
|
|
<DropdownItem onClick={this.onEditFileTagToggle}>{gettext('Tags')}</DropdownItem>
|
2019-07-10 07:53:47 +00:00
|
|
|
<DropdownItem onClick={this.onHistoryClick}>{gettext('History')}</DropdownItem>
|
2019-04-22 02:29:41 +00:00
|
|
|
</DropdownMenu>
|
|
|
|
</Dropdown>
|
2019-03-15 02:10:24 +00:00
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
{this.state.isShareDialogShow && (
|
|
|
|
<ModalPotal>
|
2020-11-02 05:56:35 +00:00
|
|
|
<ShareDialog
|
2019-03-15 02:10:24 +00:00
|
|
|
itemType={'file'}
|
|
|
|
itemName={Utils.getFileName(this.props.path)}
|
|
|
|
itemPath={this.props.path}
|
|
|
|
repoID={this.props.repoID}
|
|
|
|
repoEncrypted={this.props.repoEncrypted}
|
|
|
|
enableDirPrivateShare={this.props.enableDirPrivateShare}
|
|
|
|
userPerm={this.props.userPerm}
|
|
|
|
isGroupOwnedRepo={this.props.isGroupOwnedRepo}
|
|
|
|
toggleDialog={this.onShareToggle}
|
|
|
|
/>
|
|
|
|
</ModalPotal>
|
|
|
|
)}
|
|
|
|
{this.state.isEditTagDialogShow && (
|
|
|
|
<ModalPotal>
|
|
|
|
<EditFileTagDialog
|
|
|
|
filePath={this.props.path}
|
|
|
|
repoID={this.props.repoID}
|
2024-02-02 12:52:58 +00:00
|
|
|
repoTags={this.props.repoTags}
|
2019-03-15 02:10:24 +00:00
|
|
|
fileTagList={this.props.fileTags}
|
|
|
|
toggleCancel={this.onEditFileTagToggle}
|
|
|
|
onFileTagChanged={this.props.onFileTagChanged}
|
|
|
|
/>
|
|
|
|
</ModalPotal>
|
|
|
|
)}
|
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ViewFileToolbar.propTypes = propTypes;
|
|
|
|
|
2020-07-21 03:16:33 +00:00
|
|
|
export default ViewFileToolbar;
|