import React, { Fragment } from 'react'; import PropTypes from 'prop-types'; import { gettext } from '../../utils/constants'; import CurDirPath from '../../components/cur-dir-path'; import DirentDetail from '../../components/dirent-detail/dirent-details'; import DirListView from '../../components/dir-view-mode/dir-list-view'; import DirGridView from '../../components/dir-view-mode/dir-grid-view'; import DirColumnView from '../../components/dir-view-mode/dir-column-view'; const propTypes = { pathPrefix: PropTypes.array.isRequired, currentMode: PropTypes.string.isRequired, path: PropTypes.string.isRequired, pathExist: PropTypes.bool.isRequired, // repoinfo currentRepoInfo: PropTypes.object.isRequired, repoID: PropTypes.string.isRequired, repoPermission: PropTypes.bool.isRequired, enableDirPrivateShare: PropTypes.bool.isRequired, userPrem: PropTypes.bool, isGroupOwnedRepo: 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, isDraft: PropTypes.bool.isRequired, hasDraft: PropTypes.bool.isRequired, fileTags: PropTypes.array.isRequired, goDraftPage: PropTypes.func.isRequired, isFileLoading: PropTypes.bool.isRequired, filePermission: PropTypes.bool.isRequired, content: 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 draftCounts: PropTypes.number, usedRepoTags: PropTypes.array.isRequired, readmeMarkdown: PropTypes.object, 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, onFileTagChanged: PropTypes.func.isRequired, isDirentSelected: PropTypes.bool.isRequired, isAllDirentSelected: PropTypes.bool.isRequired, onAllDirentSelected: PropTypes.func.isRequired, }; class LibContentContainer extends React.Component { constructor(props) { super(props); this.state = { currentDirent: null, isDirentDetailShow: false, }; this.errMessage = (
{gettext('Folder does not exist.')}
); } onPathClick = (path) => { this.setState({isDirentDetailShow: false}); this.props.onMainNavBarClick(path); } onItemClick = (dirent) => { this.setState({isDirentDetailShow: false}); this.props.onItemClick(dirent); } // on '' onDirentClick = (dirent) => { if (this.state.isDirentDetailShow) { this.onItemDetails(dirent); } } onItemDetails = (dirent) => { this.setState({ currentDirent: dirent, isDirentDetailShow: true, }); } onItemDetailsClose = () => { this.setState({isDirentDetailShow: false}); } componentWillReceiveProps (nextProps) { if (nextProps.isDirentDetailShow !== this.state.isDirentDetailShow) { this.setState({ isDirentDetailShow: nextProps.isDirentDetailShow, currentDirent: nextProps.selectedDirent, }); } } render() { let { path, repoID, usedRepoTags, readmeMarkdown, draftCounts } = this.props; let isRepoInfoBarShow = false; if (path === '/') { if (usedRepoTags.length !== 0 || readmeMarkdown !== null || draftCounts !== 0) { isRepoInfoBarShow = true; } } return (
{!this.props.pathExist && this.errMessage} {this.props.pathExist && ( {this.props.currentMode === 'list' && ( )} {this.props.currentMode === 'grid' && ( )} {this.props.currentMode === 'column' && ( )} )}
{this.state.isDirentDetailShow && (
)}
); } } LibContentContainer.propTypes = propTypes; export default LibContentContainer;