import React, { Fragment } from 'react'; import PropTypes from 'prop-types'; import { UncontrolledTooltip } from 'reactstrap'; import { Link } from '@gatsbyjs/reach-router'; import DirOperationToolBar from '../../components/toolbar/dir-operation-toolbar'; import MetadataViewName from '../../metadata/components/metadata-view-name'; import TagViewName from '../../tag/components/tag-view-name'; import { siteRoot, gettext } from '../../utils/constants'; import { Utils } from '../../utils/utils'; import { PRIVATE_FILE_TYPE } from '../../constants'; import { debounce } from '../../metadata/utils/common'; import { EVENT_BUS_TYPE } from '../../metadata/constants'; const propTypes = { currentRepoInfo: PropTypes.object.isRequired, repoID: PropTypes.string.isRequired, repoName: PropTypes.string.isRequired, currentPath: PropTypes.string.isRequired, onPathClick: PropTypes.func.isRequired, onTabNavClick: PropTypes.func, pathPrefix: PropTypes.array, fileTags: PropTypes.array.isRequired, toggleTreePanel: PropTypes.func.isRequired, repoEncrypted: PropTypes.bool.isRequired, enableDirPrivateShare: PropTypes.bool.isRequired, userPerm: PropTypes.string.isRequired, isGroupOwnedRepo: PropTypes.bool.isRequired, showShareBtn: PropTypes.bool.isRequired, onAddFile: PropTypes.func.isRequired, onAddFolder: PropTypes.func.isRequired, onUploadFile: PropTypes.func.isRequired, onUploadFolder: PropTypes.func.isRequired, direntList: PropTypes.array.isRequired, repoTags: PropTypes.array.isRequired, filePermission: PropTypes.string, onFileTagChanged: PropTypes.func.isRequired, onItemMove: PropTypes.func.isRequired, loadDirentList: PropTypes.func.isRequired, }; class DirPath extends React.Component { constructor(props) { super(props); this.state = { dropTargetPath: '', }; } onPathClick = (e) => { let path = Utils.getEventData(e, 'path'); this.props.onPathClick(path); }; onTabNavClick = (e, tabName, id) => { if (window.uploader && window.uploader.isUploadProgressDialogShow && window.uploader.totalProgress !== 100) { if (!window.confirm(gettext('A file is being uploaded. Are you sure you want to leave this page?'))) { e.preventDefault(); return false; } window.uploader.isUploadProgressDialogShow = false; } this.props.onTabNavClick(tabName, id); }; onDragEnter = (e) => { e.preventDefault(); if (Utils.isIEBrowser()) { return false; } this.setState({ dropTargetPath: e.target.dataset.path, }); }; onDragLeave = (e) => { e.preventDefault(); if (Utils.isIEBrowser()) { return false; } this.setState({ dropTargetPath: '', }); }; onDragOver = (e) => { if (Utils.isIEBrowser()) { return false; } e.preventDefault(); e.dataTransfer.dropEffect = 'move'; }; onDrop = (e) => { if (Utils.isIEBrowser()) { return false; } if (e.dataTransfer.files.length) { return; } let selectedPath = Utils.getEventData(e, 'path'); let dragStartItemsData = e.dataTransfer.getData('application/drag-item-info'); dragStartItemsData = JSON.parse(dragStartItemsData); if (Array.isArray(dragStartItemsData)) { this.props.onItemsMove(this.props.currentRepoInfo, selectedPath); } else { let { nodeDirent, nodeParentPath } = dragStartItemsData; this.props.onItemMove(this.props.currentRepoInfo, nodeDirent, selectedPath, nodeParentPath); } this.setState({ dropTargetPath: '', }); }; handelRefresh = debounce(() => { window.sfMetadataContext.eventBus.dispatch(EVENT_BUS_TYPE.RELOAD_DATA); }, 200); turnPathToLink = (path) => { path = path[path.length - 1] === '/' ? path.slice(0, path.length - 1) : path; let pathList = path.split('/'); let nodePath = ''; if (pathList.length === 2 && !pathList[0] && [PRIVATE_FILE_TYPE.FILE_EXTENDED_PROPERTIES, PRIVATE_FILE_TYPE.TAGS_PROPERTIES].includes(pathList[1])) { return null; } let pathElem = pathList.map((item, index) => { if (item === '') { return null; } if (index === pathList.length - 2 && item === PRIVATE_FILE_TYPE.FILE_EXTENDED_PROPERTIES) { return ( / {gettext('Views')} ); } if (index === pathList.length - 2 && item === PRIVATE_FILE_TYPE.TAGS_PROPERTIES) { return ( / {gettext('Tags')} ); } if (index === pathList.length - 1 && pathList[pathList.length - 2] === PRIVATE_FILE_TYPE.FILE_EXTENDED_PROPERTIES) { return ( /
{gettext('Refresh the view')}
); } if (index === pathList.length - 1 && pathList[pathList.length - 2] === PRIVATE_FILE_TYPE.TAGS_PROPERTIES) { return ( / ); } if (index === (pathList.length - 1)) { return ( / {item} ); } else { nodePath += '/' + item; return ( / {item} ); } }); return pathElem; }; isViewMetadata = () => { const { currentPath } = this.props; const path = currentPath[currentPath.length - 1] === '/' ? currentPath.slice(0, currentPath.length - 1) : currentPath; const pathList = path.split('/'); return pathList[pathList.length - 2] === PRIVATE_FILE_TYPE.FILE_EXTENDED_PROPERTIES; }; render() { let { currentPath, repoName } = this.props; let pathElem = this.turnPathToLink(currentPath); return (
{this.props.pathPrefix && this.props.pathPrefix.map((item, index) => { return ( this.onTabNavClick(e, item.name, item.id)}>{gettext(item.showName)} / ); })} {this.props.pathPrefix && this.props.pathPrefix.length === 0 && ( this.onTabNavClick(e, 'libraries')}>{gettext('Files')} / )} {!this.props.pathPrefix && ( this.onTabNavClick(e, 'libraries')}>{gettext('Files')} / )} {(currentPath === '/' || currentPath === '') ? {repoName} : {repoName} } {pathElem}
); } } DirPath.propTypes = propTypes; export default DirPath;