From 4d890a4b7c5f148585e2fc1c2047c751d5ee570e Mon Sep 17 00:00:00 2001 From: shanshuirenjia <978987373@qq.com> Date: Thu, 13 Dec 2018 14:40:09 +0800 Subject: [PATCH] repair router bug --- frontend/src/app.js | 77 +++++++++++-------- .../src/components/cur-dir-path/dir-path.js | 31 ++++++-- frontend/src/components/cur-dir-path/index.js | 4 +- frontend/src/components/dir-view/dir-panel.js | 4 +- frontend/src/components/dir-view/dir-view.js | 4 +- frontend/src/pages/groups/group-view.js | 6 +- 6 files changed, 85 insertions(+), 41 deletions(-) diff --git a/frontend/src/app.js b/frontend/src/app.js index dd3c6c33ff..d51db1af1a 100644 --- a/frontend/src/app.js +++ b/frontend/src/app.js @@ -1,7 +1,7 @@ import React, { Component, Fragment } from 'react'; import ReactDOM from 'react-dom'; -import { Router, Link } from '@reach/router'; -import { gettext, siteRoot } from './utils/constants'; +import { Router } from '@reach/router'; +import { siteRoot } from './utils/constants'; import SidePanel from './components/side-panel'; import MainPanel from './components/main-panel'; import DraftsView from './pages/drafts/drafts-view'; @@ -53,8 +53,9 @@ class App extends Component { draftList:[], isLoadingDraft: true, currentTab: '/', - pathPrefix: null, + pathPrefix: [], }; + this.dirViewPanels = ['my-libs', 'shared-libs', 'org']; // and group } componentDidMount() { @@ -100,41 +101,55 @@ class App extends Component { } tabItemClick = (tabName, groupID) => { - let pathPrefix = this.generatorPrefix(tabName, groupID); + let pathPrefix = []; + if (groupID || this.dirViewPanels.indexOf(tabName) > -1) { + pathPrefix = this.generatorPrefix(tabName, groupID); + } this.setState({ currentTab: tabName, pathPrefix: pathPrefix }); } - generatorPrefix = (currentTab, groupID) => { - if (groupID) { //group - return ( - - {gettext('Groups')} - / - {currentTab} - / - - ); + generatorPrefix = (tabName, groupID) => { + let pathPrefix = []; + if (groupID) { + let navTab1 = { + url: siteRoot + 'groups/', + showName: 'Groups', + name: 'groups', + id: null, + } + let navTab2 = { + url: siteRoot + 'group/' + groupID + '/', + showName: tabName, + name: tabName, + id: groupID, + }; + pathPrefix.push(navTab1); + pathPrefix.push(navTab2); + } else { + let navTab = { + url: siteRoot + tabName + '/', + showName: this.getTabShowName(tabName, groupID), + name: tabName, + id: null, + }; + pathPrefix.push(navTab); } - if (currentTab === 'my-libs') { - return ( - - {gettext('Libraries')} - / - - ); + return pathPrefix; + } + + getTabShowName = (tabName) => { + if (tabName === 'my-libs') { + return 'Libraries'; } - if (currentTab === 'shared-libs') { - return ( - - {gettext('Shared with me')} - / - - ); + if (tabName === 'shared-libs') { + return 'Shared with me'; + } + if (tabName === 'org') { + return 'Shared with all'; } - return null; } render() { @@ -170,9 +185,9 @@ class App extends Component { - + - + diff --git a/frontend/src/components/cur-dir-path/dir-path.js b/frontend/src/components/cur-dir-path/dir-path.js index 05af49242b..55240e3e41 100644 --- a/frontend/src/components/cur-dir-path/dir-path.js +++ b/frontend/src/components/cur-dir-path/dir-path.js @@ -5,9 +5,10 @@ import { siteRoot, gettext } from '../../utils/constants'; const propTypes = { repoName: PropTypes.string.isRequired, - pathPrefix: PropTypes.object, currentPath: PropTypes.string.isRequired, onPathClick: PropTypes.func.isRequired, + onTabNavClick: PropTypes.func, + pathPrefix: PropTypes.array, }; class DirPath extends React.Component { @@ -17,6 +18,10 @@ class DirPath extends React.Component { 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('/'); @@ -47,13 +52,27 @@ class DirPath extends React.Component { let pathElem = this.turnPathToLink(currentPath); return (
- {this.props.pathPrefix ? - this.props.pathPrefix : - - {gettext('Libraries')} + {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.bind(this, 'my-libs')}>{gettext('Libraries')} + / + + ) } + {!this.props.pathPrefix && ( + + this.onTabNavClick.bind(this, 'my-libs')}>{gettext('Libraries')} + / + + )} {currentPath === '/' ? {repoName}: {repoName} diff --git a/frontend/src/components/cur-dir-path/index.js b/frontend/src/components/cur-dir-path/index.js index fbacc1e922..a048622aa1 100644 --- a/frontend/src/components/cur-dir-path/index.js +++ b/frontend/src/components/cur-dir-path/index.js @@ -5,11 +5,12 @@ import DirTool from './dir-tool'; const propTypes = { repoID: PropTypes.string.isRequired, - pathPrefix: PropTypes.object.isRequired, repoName: PropTypes.string.isRequired, permission: PropTypes.bool.isRequired, currentPath: PropTypes.string.isRequired, onPathClick: PropTypes.func.isRequired, + onTabNavClick: PropTypes.func, + pathPrefix: PropTypes.array, }; class CurDirPath extends React.Component { @@ -22,6 +23,7 @@ class CurDirPath extends React.Component { pathPrefix={this.props.pathPrefix} currentPath={this.props.currentPath} onPathClick={this.props.onPathClick} + onTabNavClick={this.props.onTabNavClick} />
diff --git a/frontend/src/components/dir-view/dir-view.js b/frontend/src/components/dir-view/dir-view.js index 62154e28f9..68d351798e 100644 --- a/frontend/src/components/dir-view/dir-view.js +++ b/frontend/src/components/dir-view/dir-view.js @@ -11,7 +11,8 @@ import FileTag from '../../models/file-tag'; import Repo from '../../models/repo'; const propTypes = { - pathPrefix: PropTypes.object.isRequired, + pathPrefix: PropTypes.array.isRequired, + onTabNavClick: PropTypes.func.isRequired, onMenuClick: PropTypes.func.isRequired, }; @@ -456,6 +457,7 @@ class DirView extends React.Component { onFileTagChanged={this.onFileTagChanged} onMenuClick={this.onMenuClick} onPathClick={this.onPathClick} + onTabNavClick={this.props.onTabNavClick} updateDirent={this.updateDirent} switchViewMode={this.switchViewMode} onSearchedClick={this.onSearchedClick} diff --git a/frontend/src/pages/groups/group-view.js b/frontend/src/pages/groups/group-view.js index f152815d07..e5b786f221 100644 --- a/frontend/src/pages/groups/group-view.js +++ b/frontend/src/pages/groups/group-view.js @@ -180,6 +180,10 @@ class GroupView extends React.Component { }); } + onTabNavClick = (tabName) => { + this.props.onTabNavClick(tabName); + } + render() { let { errMessage, emptyTip, currentGroup } = this.state; let isShowSettingIcon = !(currentGroup && currentGroup.parent_group_id !== 0 && currentGroup.admins.indexOf(username) === -1); @@ -203,7 +207,7 @@ class GroupView extends React.Component { {currentGroup && (
- {gettext("Groups")} + this.onTabNavClick('groups')}>{gettext("Groups")} / {currentGroup.name} {currentGroup.parent_group_id !== 0 && (