diff --git a/frontend/src/components/cur-dir-path/dir-path.js b/frontend/src/components/cur-dir-path/dir-path.js new file mode 100644 index 0000000000..2194e3966c --- /dev/null +++ b/frontend/src/components/cur-dir-path/dir-path.js @@ -0,0 +1,62 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import { siteRoot, gettext } from '../../utils/constants'; + +const propTypes = { + repoName: PropTypes.string.isRequired, + currentPath: PropTypes.string.isRequired, + onPathClick: PropTypes.func.isRequired, +}; + +class DirPath extends React.Component { + + onPathClick = (e) => { + let path = e.target.dataset.path; + this.props.onPathClick(path); + } + + turnPathToLink = (path) => { + path = path[path.length - 1] === '/' ? path.slice(0, path.length - 1) : path; + let pathList = path.split('/'); + let nodePath = ''; + let pathElem = pathList.map((item, index) => { + if (item === '') { + return; + } + if (index === (pathList.length - 1)) { + return ( + /{item} + ); + } else { + nodePath += '/' + item; + return ( + + / + {item} + + ); + } + }); + return pathElem; + } + + render() { + let { currentPath, repoName } = this.props; + let pathElem = this.turnPathToLink(currentPath); + return ( +
+ ); + } +} + +DirPath.propTypes = propTypes; + +export default DirPath; diff --git a/frontend/src/components/toolbar/path-toolbar.js b/frontend/src/components/cur-dir-path/dir-tool.js similarity index 90% rename from frontend/src/components/toolbar/path-toolbar.js rename to frontend/src/components/cur-dir-path/dir-tool.js index f754e0dc1e..f3e9deb8b9 100644 --- a/frontend/src/components/toolbar/path-toolbar.js +++ b/frontend/src/components/cur-dir-path/dir-tool.js @@ -7,10 +7,10 @@ import CreateTagDialog from '../dialog/create-tag-dialog'; import UpdateTagDialog from '../dialog/update-tag-dialog'; const propTypes = { - path: PropTypes.string.isRequired + currentPath: PropTypes.string.isRequired }; -class PathToolbar extends React.Component { +class DirTool extends React.Component { constructor(props) { super(props); @@ -47,8 +47,9 @@ class PathToolbar extends React.Component { } render() { - let isFile = this.isMarkdownFile(this.props.path); - let name = Utils.getFileName(this.props.path); + 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) { @@ -89,7 +90,7 @@ class PathToolbar extends React.Component { ); } else if (permission) { - historyUrl = siteRoot + 'repo/file_revisions/' + repoID + '/?p=' + Utils.encodePath(this.props.path) + '&referer=' + encodeURIComponent(location.href); + historyUrl = siteRoot + 'repo/file_revisions/' + repoID + '/?p=' + Utils.encodePath(currentPath) + '&referer=' + encodeURIComponent(location.href); return (