1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-07-15 16:04:01 +00:00
seahub/frontend/src/components/repo-info-bar.js

144 lines
4.8 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-19 08:20:40 +00:00
import ReadmeDialog from './dialog/readme-dialog';
import { siteRoot, gettext } from '../utils/constants';
2019-01-09 04:10:33 +00:00
import { Utils } from '../utils/utils';
import '../css/repo-info-bar.css';
const propTypes = {
repoID: PropTypes.string.isRequired,
currentPath: PropTypes.string.isRequired,
usedRepoTags: PropTypes.array.isRequired,
readmeMarkdown: PropTypes.object,
draftCounts: PropTypes.number,
2019-02-14 08:48:46 +00:00
updateUsedRepoTags: PropTypes.func.isRequired,
2019-04-21 02:21:48 +00:00
onFileTagChanged: PropTypes.func.isRequired,
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-19 08:20:40 +00:00
showReadmeDialog: false,
2019-01-09 04:10:33 +00:00
};
}
onListTaggedFiles = (currentTag) => {
this.setState({
currentTag: currentTag,
isListTaggedFileShow: !this.state.isListTaggedFileShow,
});
}
onCloseDialog = () => {
this.setState({
isListTaggedFileShow: false
});
}
toggleDrafts = () => {
this.setState({
showRepoDrafts: !this.state.showRepoDrafts
});
}
2019-01-19 08:20:40 +00:00
toggleReadme = () => {
this.setState({
showReadmeDialog: !this.state.showReadmeDialog
});
}
2019-01-09 04:10:33 +00:00
render() {
let {repoID, currentPath, usedRepoTags, readmeMarkdown} = this.props;
2019-01-21 05:46:52 +00:00
let href = readmeMarkdown !== null ? siteRoot + 'lib/' + repoID + '/file' + Utils.joinPath(currentPath, readmeMarkdown.name) + '?mode=edit' : '';
2019-01-19 09:45:28 +00:00
let filePath = readmeMarkdown !== null ? currentPath + readmeMarkdown.name : '';
2019-01-09 04:10:33 +00:00
return (
<div className="repo-info-bar">
{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>
<span className="used-tag-files" onClick={this.onListTaggedFiles.bind(this, usedRepoTag)}>
{usedRepoTag.fileCount > 1 ? usedRepoTag.fileCount + ' files' : usedRepoTag.fileCount + ' file'}
</span>
</li>
);
})}
</ul>
)}
2019-01-25 07:48:30 +00:00
<div className={(usedRepoTags.length > 0 && readmeMarkdown) ? 'file-info-list mt-1' : 'file-info-list'}>
{(readmeMarkdown !== null && parseInt(readmeMarkdown.size) > 1) &&
<span className="file-info" onClick={this.toggleReadme}>
2019-01-29 08:47:20 +00:00
<span className="info-icon sf2-icon-readme"></span>
2019-01-25 07:48:30 +00:00
<span className="used-tag-name">{readmeMarkdown.name}</span>
2019-01-19 08:20:40 +00:00
</span>
}
2019-01-25 07:48:30 +00:00
{(readmeMarkdown !== null && parseInt(readmeMarkdown.size) < 2) &&
<span className="file-info">
2019-01-29 08:47:20 +00:00
<span className="info-icon sf2-icon-readme"></span>
2019-01-25 07:48:30 +00:00
<a className="used-tag-name" href={href} target='_blank'>{readmeMarkdown.name}</a>
</span>
2019-01-19 08:20:40 +00:00
}
{this.props.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>
<span className="used-tag-files" onClick={this.toggleDrafts}>
{this.props.draftCounts > 1 ? this.props.draftCounts + ' files' : this.props.draftCounts + ' file'}
</span>
</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}
/>
2019-01-09 04:10:33 +00:00
</ModalPortal>
)}
{this.state.showRepoDrafts && (
<ModalPortal>
<ListRepoDraftsDialog
toggle={this.toggleDrafts}
repoID={this.props.repoID}
/>
</ModalPortal>
)}
2019-01-19 08:20:40 +00:00
{this.state.showReadmeDialog && (
<ModalPortal>
<ReadmeDialog
toggleCancel={this.toggleReadme}
repoID={repoID}
filePath={filePath}
href={href}
2019-01-19 09:45:28 +00:00
fileName={readmeMarkdown.name}
2019-01-19 08:20:40 +00:00
/>
</ModalPortal>
)}
2019-01-09 04:10:33 +00:00
</div>
);
}
}
RepoInfoBar.propTypes = propTypes;
export default RepoInfoBar;