import React from 'react'; import { gettext, repoID, slug, permission, siteRoot } from '../constants'; import { encodePath } from '../utils'; import PropTypes from 'prop-types'; const propTypes = { filePath: PropTypes.string.isRequired }; class PathToolbar extends React.Component { isMarkdownFile(filePath) { let lastIndex = filePath.lastIndexOf('/'); let name = filePath.slice(lastIndex + 1); return name.indexOf('.md') > -1 ? true : false; } render() { let isFile = this.isMarkdownFile(this.props.filePath); let index = this.props.filePath.lastIndexOf('/'); let name = this.props.filePath.slice(index + 1); 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 (
); } else if ( !isFile && permission) { return ( ); } else if (permission) { historyUrl = siteRoot + 'repo/file_revisions/' + repoID + '/?p=' + encodePath(this.props.filePath) + '&referer=' + encodeURIComponent(location.href); return ( ) } return ''; } } PathToolbar.propTypes = propTypes; export default PathToolbar;