import React from 'react'; import PropTypes from 'prop-types'; import { gettext } from '../../utils/constants'; import CurDirPath from '../../components/cur-dir-path'; import Detail from '../../components/dirent-detail'; import DirColumnView from '../../components/dir-view-mode/dir-column-view'; import ToolbarForSelectedDirents from '../../components/toolbar/selected-dirents-toolbar'; import { MetadataStatusProvider } from '../../metadata/hooks'; import '../../css/lib-content-view.css'; const propTypes = { isSidePanelFolded: PropTypes.bool, switchViewMode: PropTypes.func.isRequired, isCustomPermission: PropTypes.bool, pathPrefix: PropTypes.array.isRequired, isTreePanelShown: PropTypes.bool.isRequired, toggleTreePanel: PropTypes.func.isRequired, currentMode: PropTypes.string.isRequired, path: PropTypes.string.isRequired, pathExist: PropTypes.bool.isRequired, // repoinfo repoEncrypted: PropTypes.bool.isRequired, currentRepoInfo: PropTypes.object.isRequired, repoID: PropTypes.string.isRequired, enableDirPrivateShare: PropTypes.bool.isRequired, isGroupOwnedRepo: PropTypes.bool.isRequired, userPerm: PropTypes.string, isRepoOwner: PropTypes.bool.isRequired, // path func onTabNavClick: PropTypes.func.isRequired, onMainNavBarClick: PropTypes.func.isRequired, // file isViewFile: PropTypes.bool.isRequired, isFileLoadedErr: PropTypes.bool.isRequired, hash: PropTypes.string, fileTags: PropTypes.array.isRequired, isFileLoading: PropTypes.bool.isRequired, filePermission: PropTypes.string, content: PropTypes.string, metadataViewId: PropTypes.string, lastModified: PropTypes.string, latestContributor: PropTypes.string, onLinkClick: PropTypes.func.isRequired, // tree isTreeDataLoading: PropTypes.bool.isRequired, treeData: PropTypes.object.isRequired, currentNode: PropTypes.object, onNodeClick: PropTypes.func.isRequired, onNodeCollapse: PropTypes.func.isRequired, onNodeExpanded: PropTypes.func.isRequired, onRenameNode: PropTypes.func.isRequired, onDeleteNode: PropTypes.func.isRequired, onAddFileNode: PropTypes.func.isRequired, onAddFolderNode: PropTypes.func.isRequired, // repo content repoTags: PropTypes.array.isRequired, usedRepoTags: PropTypes.array.isRequired, updateUsedRepoTags: PropTypes.func.isRequired, // list isDirentListLoading: PropTypes.bool.isRequired, direntList: PropTypes.array.isRequired, sortBy: PropTypes.string.isRequired, sortOrder: PropTypes.string.isRequired, sortItems: PropTypes.func.isRequired, updateDirent: PropTypes.func.isRequired, onItemClick: PropTypes.func.isRequired, onItemSelected: PropTypes.func.isRequired, onItemDelete: PropTypes.func.isRequired, onItemRename: PropTypes.func.isRequired, onItemMove: PropTypes.func.isRequired, onItemCopy: PropTypes.func.isRequired, onAddFolder: PropTypes.func.isRequired, onAddFile: PropTypes.func.isRequired, onItemConvert: PropTypes.func.isRequired, onFileTagChanged: PropTypes.func.isRequired, isDirentSelected: PropTypes.bool.isRequired, isAllDirentSelected: PropTypes.bool.isRequired, onAllDirentSelected: PropTypes.func.isRequired, isDirentDetailShow: PropTypes.bool.isRequired, selectedDirent: PropTypes.object, selectedDirentList: PropTypes.array.isRequired, onSelectedDirentListUpdate: PropTypes.func.isRequired, onItemsMove: PropTypes.func.isRequired, onItemsCopy: PropTypes.func.isRequired, onItemsDelete: PropTypes.func.isRequired, closeDirentDetail: PropTypes.func.isRequired, showDirentDetail: PropTypes.func.isRequired, onDeleteRepoTag: PropTypes.func.isRequired, updateDetail: PropTypes.bool.isRequired, onListContainerScroll: PropTypes.func.isRequired, onDirentClick: PropTypes.func.isRequired, direntDetailPanelTab: PropTypes.string, loadDirentList: PropTypes.func, fullDirentList: PropTypes.array, unSelectDirent: PropTypes.func, onFilesTagChanged: PropTypes.func.isRequired, showShareBtn: PropTypes.bool.isRequired, onUploadFile: PropTypes.func.isRequired, onUploadFolder: PropTypes.func.isRequired, onToolbarFileTagChanged: PropTypes.func.isRequired }; class LibContentContainer extends React.Component { constructor(props) { super(props); this.state = { currentDirent: null, }; this.errMessage = (
{gettext('Folder does not exist.')}
); } UNSAFE_componentWillReceiveProps(nextProps) { if (nextProps.path !== this.props.path || nextProps.updateDetail !== this.props.updateDetail) { this.setState({ currentDirent: null }); } } onPathClick = (path) => { this.props.onMainNavBarClick(path); }; onItemClick = (dirent) => { this.props.onItemClick(dirent); }; onDirentClick = (dirent, event) => { this.setState({ currentDirent: dirent }); this.props.onDirentClick(dirent, event); }; onItemSelected = (dirent) => { this.setState({ currentDirent: dirent }); this.props.onItemSelected(dirent); }; onItemDelete = (dirent) => { this.checkCurrentDirent(dirent); this.props.onItemDelete(dirent); }; onItemMove = (destRepo, dirent, selectedPath, currentPath) => { this.checkCurrentDirent(dirent); this.props.onItemMove(destRepo, dirent, selectedPath, currentPath); }; checkCurrentDirent = (deletedDirent) => { let { currentDirent } = this.state; if (currentDirent && deletedDirent.name === currentDirent.name) { this.setState({ currentDirent: null }); } }; onItemsScroll = (e) => { let target = e.target; if (target.scrollTop === 0) { return; } if (target.scrollTop + target.clientHeight + 1 >= target.scrollHeight) { this.props.onListContainerScroll(); } }; render() { let { path, repoID, usedRepoTags } = this.props; let isRepoInfoBarShow = false; if (path === '/') { if (usedRepoTags.length !== 0) { isRepoInfoBarShow = true; } } let curViewPathStyle = { 'borderBottom': 'none' }; if (this.props.isDirentSelected) { curViewPathStyle.transform = 'translateY(-50px)'; } return (
{this.props.currentRepoInfo.status === 'read-only' &&
{gettext('This library has been set to read-only by admin and cannot be updated.')}
}
{!this.props.pathExist && this.errMessage} {this.props.pathExist && ( )} {this.props.isDirentDetailShow && ( )}
); } } LibContentContainer.propTypes = propTypes; export default LibContentContainer;