import React, { Fragment } from 'react'; import PropTypes from 'prop-types'; import { Link } from '@gatsbyjs/reach-router'; import { siteRoot, gettext } from '../../utils/constants'; import { Utils } from '../../utils/utils'; const propTypes = { repoName: PropTypes.string.isRequired, currentPath: PropTypes.string.isRequired, onPathClick: PropTypes.func.isRequired, onTabNavClick: PropTypes.func.isRequired, repoID: PropTypes.string.isRequired, }; class DirPath extends React.Component { onPathClick = (e) => { let path = Utils.getEventData(e, '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 null; } 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 (
this.props.onTabNavClick('shared-with-ocm')}>{gettext('All')} / {(currentPath === '/' || currentPath === '') ? {repoName}: {repoName} } {pathElem}
); } } DirPath.propTypes = propTypes; export default DirPath;