import React, { Fragment } from 'react'; import { gettext, repoID, slug, permission, siteRoot } from '../../utils/constants'; import { Utils } from '../../utils/utils'; import PropTypes from 'prop-types'; import ListTagDialog from '../dialog/list-tag-dialog'; import CreateTagDialog from '../dialog/create-tag-dialog'; import UpdateTagDialog from '../dialog/update-tag-dialog'; const propTypes = { currentPath: PropTypes.string.isRequired }; class DirTool extends React.Component { constructor(props) { super(props); this.state = { currentTag: null, isListRepoTagShow: false, isUpdateRepoTagShow: false, isCreateRepoTagShow: false, }; } onListRepoTagToggle = () => { this.setState({isListRepoTagShow: !this.state.isListRepoTagShow}); } onCreateRepoTagToggle = () => { this.setState({ isCreateRepoTagShow: !this.state.isCreateRepoTagShow, isListRepoTagShow: !this.state.isListRepoTagShow, }); } onUpdateRepoTagToggle = (currentTag) => { this.setState({ currentTag: currentTag, isListRepoTagShow: !this.state.isListRepoTagShow, isUpdateRepoTagShow: !this.state.isUpdateRepoTagShow, }); } isMarkdownFile(filePath) { let name = Utils.getFileName(filePath); return name.indexOf('.md') > -1 ? true : false; } render() { let { currentPath } = this.props; let isFile = this.isMarkdownFile(currentPath); let name = Utils.getFileName(currentPath); let trashUrl = siteRoot + 'repo/recycle/' + repoID + '/?referer=' + encodeURIComponent(location.href); let historyUrl = siteRoot + 'repo/history/' + repoID + '/?referer=' + encodeURIComponent(location.href); if ( (name === slug || name === '') && !isFile && permission) { return ( { this.state.isListRepoTagShow && } { this.state.isCreateRepoTagShow && } { this.state.isUpdateRepoTagShow && } ); } else if (!isFile && permission) { return ( ); } else if (permission) { historyUrl = siteRoot + 'repo/file_revisions/' + repoID + '/?p=' + Utils.encodePath(currentPath) + '&referer=' + encodeURIComponent(location.href); return ( ); } return ''; } } DirTool.propTypes = propTypes; export default DirTool;