1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-07-21 02:20:17 +00:00
seahub/frontend/src/components/repo-info-bar.js

118 lines
3.6 KiB
JavaScript
Raw Normal View History

2019-01-09 04:10:33 +00:00
import React from 'react';
import PropTypes from 'prop-types';
import ModalPortal from './modal-portal';
import ListTaggedFilesDialog from './dialog/list-taggedfiles-dialog';
import ListRepoDraftsDialog from './dialog/list-repo-drafts-dialog';
2019-01-09 04:10:33 +00:00
import '../css/repo-info-bar.css';
const propTypes = {
repoID: PropTypes.string.isRequired,
usedRepoTags: PropTypes.array.isRequired,
draftCounts: PropTypes.number,
updateUsedRepoTags: PropTypes.func,
onFileTagChanged: PropTypes.func,
className: PropTypes.string,
shareLinkToken: PropTypes.string,
enableFileDownload: PropTypes.bool
2019-01-09 04:10:33 +00:00
};
class RepoInfoBar extends React.Component {
constructor(props) {
super(props);
this.state = {
currentTag: null,
isListTaggedFileShow: false,
showRepoDrafts: false
2019-01-09 04:10:33 +00:00
};
}
onListTaggedFiles = (currentTag) => {
this.setState({
currentTag: currentTag,
isListTaggedFileShow: !this.state.isListTaggedFileShow
2019-01-09 04:10:33 +00:00
});
};
2019-01-09 04:10:33 +00:00
onCloseDialog = () => {
this.setState({
isListTaggedFileShow: false
});
};
2019-01-09 04:10:33 +00:00
toggleDrafts = () => {
this.setState({
showRepoDrafts: !this.state.showRepoDrafts
});
};
2019-01-09 04:10:33 +00:00
render() {
let { repoID, usedRepoTags, draftCounts, className } = this.props;
// to be compatible with the existing code
if (draftCounts === undefined) {
draftCounts = 0;
}
2019-01-09 04:10:33 +00:00
return (
<div className={`repo-info-bar ${className ? className : ''}`}>
2019-01-09 04:10:33 +00:00
{usedRepoTags.length > 0 && (
<ul className="used-tag-list">
{usedRepoTags.map((usedRepoTag) => {
return (
<li key={usedRepoTag.id} className="used-tag-item">
<span className="used-tag" style={{backgroundColor:usedRepoTag.color}}></span>
2019-01-09 04:10:33 +00:00
<span className="used-tag-name" title={usedRepoTag.name}>{usedRepoTag.name}</span>
<button type="button" className="used-tag-files border-0 bg-transparent" onClick={this.onListTaggedFiles.bind(this, usedRepoTag)}>
2019-01-09 04:10:33 +00:00
{usedRepoTag.fileCount > 1 ? usedRepoTag.fileCount + ' files' : usedRepoTag.fileCount + ' file'}
</button>
2019-01-09 04:10:33 +00:00
</li>
);
})}
</ul>
)}
{/*<div className={usedRepoTags.length > 0 ? 'file-info-list mt-1' : 'file-info-list'}>
{draftCounts > 0 &&
2019-01-25 07:48:30 +00:00
<span className="file-info">
2019-01-29 08:47:20 +00:00
<span className="info-icon sf2-icon-drafts"></span>
<span className="used-tag-name">{gettext('draft')}</span>
<button type="button" className="used-tag-files border-0 bg-transparent" onClick={this.toggleDrafts}>
{draftCounts > 1 ? draftCounts + ' files' : draftCounts + ' file'}
</button>
</span>
}
</div>*/}
2019-01-09 04:10:33 +00:00
{this.state.isListTaggedFileShow && (
<ModalPortal>
<ListTaggedFilesDialog
repoID={repoID}
currentTag={this.state.currentTag}
onClose={this.onCloseDialog}
toggleCancel={this.onListTaggedFiles}
2019-02-14 08:48:46 +00:00
updateUsedRepoTags={this.props.updateUsedRepoTags}
2019-04-21 02:21:48 +00:00
onFileTagChanged={this.props.onFileTagChanged}
shareLinkToken={this.props.shareLinkToken}
enableFileDownload={this.props.enableFileDownload}
/>
2019-01-09 04:10:33 +00:00
</ModalPortal>
)}
{this.state.showRepoDrafts && (
<ModalPortal>
<ListRepoDraftsDialog
toggle={this.toggleDrafts}
repoID={this.props.repoID}
/>
</ModalPortal>
)}
2019-01-09 04:10:33 +00:00
</div>
);
}
}
RepoInfoBar.propTypes = propTypes;
export default RepoInfoBar;