import React, { Fragment } from 'react'; import PropTypes from 'prop-types'; import { Link } from '@reach/router'; import { UncontrolledTooltip } from 'reactstrap'; import { siteRoot, gettext } from '../../utils/constants'; import InternalLinkDialog from '../dialog/internal-link-dialog'; import { Utils } from '../../utils/utils'; const propTypes = { repoName: PropTypes.string.isRequired, currentPath: PropTypes.string.isRequired, onPathClick: PropTypes.func.isRequired, onTabNavClick: PropTypes.func, pathPrefix: PropTypes.array, repoID: PropTypes.string.isRequired, isViewFile: PropTypes.bool, fileTags: PropTypes.array.isRequired, }; class DirPath extends React.Component { onPathClick = (e) => { let path = Utils.getEventData(e, 'path'); this.props.onPathClick(path); } onTabNavClick = (tabName, id) => { this.props.onTabNavClick(tabName, id); } 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, fileTags } = this.props; let pathElem = this.turnPathToLink(currentPath); let tagTitle = ''; if (fileTags.length > 0) { fileTags.forEach(item => { tagTitle += item.name + ' '; }); } return (
{this.props.pathPrefix && this.props.pathPrefix.map((item, index) => { return ( this.onTabNavClick(item.name, item.id)}>{gettext(item.showName)} / ); })} {this.props.pathPrefix && this.props.pathPrefix.length === 0 && ( this.onTabNavClick('my-libs')}>{gettext('Libraries')} / )} {!this.props.pathPrefix && ( this.onTabNavClick('my-libs')}>{gettext('Libraries')} / )} {(currentPath === '/' || currentPath === '') ? {repoName}: {repoName} } {pathElem} {this.props.isViewFile && } {(this.props.isViewFile && fileTags.length !== 0) && {fileTags.map((fileTag, index) => { return (); })} {tagTitle} }
); } } DirPath.propTypes = propTypes; export default DirPath;