From: Grégoire Aubert Date: Wed, 7 Jun 2017 14:55:24 +0000 (+0200) Subject: SONAR-9245 Prevent the projects page topbar to keep open when switching app in org... X-Git-Tag: 6.5-M1~70 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=07401bd3c1487b3e1f4b7c0105448cc67b4987c7;p=sonarqube.git SONAR-9245 Prevent the projects page topbar to keep open when switching app in org context --- diff --git a/server/sonar-web/src/main/js/apps/organizations/components/OrganizationFavoriteProjects.js b/server/sonar-web/src/main/js/apps/organizations/components/OrganizationFavoriteProjects.js index 9c3edfce2aa..39bcb30a75a 100644 --- a/server/sonar-web/src/main/js/apps/organizations/components/OrganizationFavoriteProjects.js +++ b/server/sonar-web/src/main/js/apps/organizations/components/OrganizationFavoriteProjects.js @@ -19,14 +19,12 @@ */ // @flow import React from 'react'; -import { connect } from 'react-redux'; import FavoriteProjectsContainer from '../../projects/components/FavoriteProjectsContainer'; -import { getOrganizationByKey } from '../../../store/rootReducer'; -import { updateOrganization } from '../actions'; -class OrganizationFavoriteProjects extends React.PureComponent { +export default class OrganizationFavoriteProjects extends React.PureComponent { props: { children?: React.Element<*>, + currentUser: { isLoggedIn: boolean }, location: Object, optionBarOpen: boolean, optionBarToggle: (open: boolean) => void, @@ -53,6 +51,7 @@ class OrganizationFavoriteProjects extends React.PureComponent { return (
({ - organization: getOrganizationByKey(state, ownProps.params.organizationKey) -}); - -const mapDispatchToProps = { updateOrganization }; - -export default connect(mapStateToProps, mapDispatchToProps)(OrganizationFavoriteProjects); diff --git a/server/sonar-web/src/main/js/apps/organizations/components/OrganizationPage.js b/server/sonar-web/src/main/js/apps/organizations/components/OrganizationPage.js index 55f9cd00902..d08cfabf5d4 100644 --- a/server/sonar-web/src/main/js/apps/organizations/components/OrganizationPage.js +++ b/server/sonar-web/src/main/js/apps/organizations/components/OrganizationPage.js @@ -40,14 +40,13 @@ type Props = { }; type State = { - loading: boolean, - optionBarOpen: boolean + loading: boolean }; class OrganizationPage extends React.PureComponent { mounted: boolean; props: Props; - state: State = { loading: true, optionBarOpen: false }; + state: State = { loading: true }; componentDidMount() { this.mounted = true; @@ -75,8 +74,6 @@ class OrganizationPage extends React.PureComponent { }); }; - handleOptionBarToggle = (open: boolean) => this.setState({ optionBarOpen: open }); - render() { const { organization } = this.props; @@ -92,11 +89,7 @@ class OrganizationPage extends React.PureComponent {
- {this.props.children && - React.cloneElement(this.props.children, { - optionBarOpen: this.state.optionBarOpen, - optionBarToggle: this.handleOptionBarToggle - })} + {this.props.children}
); } diff --git a/server/sonar-web/src/main/js/apps/organizations/components/OrganizationProjects.js b/server/sonar-web/src/main/js/apps/organizations/components/OrganizationProjects.js index f3286b2ab82..39d5c76ce76 100644 --- a/server/sonar-web/src/main/js/apps/organizations/components/OrganizationProjects.js +++ b/server/sonar-web/src/main/js/apps/organizations/components/OrganizationProjects.js @@ -19,14 +19,12 @@ */ // @flow import React from 'react'; -import { connect } from 'react-redux'; import AllProjectsContainer from '../../projects/components/AllProjectsContainer'; -import { getOrganizationByKey } from '../../../store/rootReducer'; -import { updateOrganization } from '../actions'; -class OrganizationProjects extends React.PureComponent { +export default class OrganizationProjects extends React.PureComponent { props: { children?: React.Element<*>, + currentUser: { isLoggedIn: boolean }, location: Object, optionBarOpen: boolean, optionBarToggle: (open: boolean) => void, @@ -53,6 +51,7 @@ class OrganizationProjects extends React.PureComponent { return (
({ - organization: getOrganizationByKey(state, ownProps.params.organizationKey) -}); - -const mapDispatchToProps = { updateOrganization }; - -export default connect(mapStateToProps, mapDispatchToProps)(OrganizationProjects); diff --git a/server/sonar-web/src/main/js/apps/organizations/components/OrganizationProjectsContainer.js b/server/sonar-web/src/main/js/apps/organizations/components/OrganizationProjectsContainer.js new file mode 100644 index 00000000000..faa2bf8df04 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/organizations/components/OrganizationProjectsContainer.js @@ -0,0 +1,52 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +//@flow +import React from 'react'; +import { connect } from 'react-redux'; +import { getCurrentUser, getOrganizationByKey } from '../../../store/rootReducer'; +import { updateOrganization } from '../actions'; + +type State = { + optionBarOpen: boolean +}; + +class OrganizationProjectsContainer extends React.PureComponent { + state: State = { optionBarOpen: false }; + + handleOptionBarToggle = (open: boolean) => this.setState({ optionBarOpen: open }); + + render() { + return React.cloneElement(this.props.children, { + currentUser: this.props.currentUser, + optionBarOpen: this.state.optionBarOpen, + optionBarToggle: this.handleOptionBarToggle, + organization: this.props.organization + }); + } +} + +const mapStateToProps = (state, ownProps) => ({ + organization: getOrganizationByKey(state, ownProps.params.organizationKey), + currentUser: getCurrentUser(state) +}); + +const mapDispatchToProps = { updateOrganization }; + +export default connect(mapStateToProps, mapDispatchToProps)(OrganizationProjectsContainer); diff --git a/server/sonar-web/src/main/js/apps/organizations/components/__tests__/__snapshots__/OrganizationPage-test.js.snap b/server/sonar-web/src/main/js/apps/organizations/components/__tests__/__snapshots__/OrganizationPage-test.js.snap index 91b20a05ca1..d9579e1bf4a 100644 --- a/server/sonar-web/src/main/js/apps/organizations/components/__tests__/__snapshots__/OrganizationPage-test.js.snap +++ b/server/sonar-web/src/main/js/apps/organizations/components/__tests__/__snapshots__/OrganizationPage-test.js.snap @@ -28,10 +28,7 @@ exports[`smoke test 2`] = ` } } /> -
+
hello
diff --git a/server/sonar-web/src/main/js/apps/organizations/routes.js b/server/sonar-web/src/main/js/apps/organizations/routes.js index c01ca215da0..f5880608456 100644 --- a/server/sonar-web/src/main/js/apps/organizations/routes.js +++ b/server/sonar-web/src/main/js/apps/organizations/routes.js @@ -20,6 +20,7 @@ import OrganizationPage from './components/OrganizationPage'; import OrganizationPageExtension from '../../app/components/extensions/OrganizationPageExtension'; import OrganizationProjects from './components/OrganizationProjects'; +import OrganizationProjectsContainer from './components/OrganizationProjectsContainer'; import OrganizationFavoriteProjects from './components/OrganizationFavoriteProjects'; import OrganizationRules from './components/OrganizationRules'; import OrganizationAdmin from './components/OrganizationAdmin'; @@ -47,11 +48,18 @@ const routes = [ }, { path: 'projects', - component: OrganizationProjects - }, - { - path: 'projects/favorite', - component: OrganizationFavoriteProjects + component: OrganizationProjectsContainer, + childRoutes: [ + { + indexRoute: { + component: OrganizationProjects + } + }, + { + path: 'favorite', + component: OrganizationFavoriteProjects + } + ] }, { path: 'members', diff --git a/server/sonar-web/src/main/js/apps/projects/components/AllProjects.js b/server/sonar-web/src/main/js/apps/projects/components/AllProjects.js index dd440f83927..9720d56560b 100644 --- a/server/sonar-web/src/main/js/apps/projects/components/AllProjects.js +++ b/server/sonar-web/src/main/js/apps/projects/components/AllProjects.js @@ -39,7 +39,7 @@ type Props = { optionBarToggle: (open: boolean) => void, organization?: { key: string }, router: { push: ({ pathname: string, query?: {} }) => void }, - user?: { isLoggedIn: boolean } + currentUser?: { isLoggedIn: boolean } }; type State = { @@ -133,7 +133,7 @@ export default class AllProjects extends React.PureComponent { onToggleOptionBar={this.props.optionBarToggle} open={optionBarOpen} selectedSort={selectedSort} - user={this.props.user} + currentUser={this.props.currentUser} view={view} visualization={visualization} /> diff --git a/server/sonar-web/src/main/js/apps/projects/components/DefaultPageSelector.js b/server/sonar-web/src/main/js/apps/projects/components/DefaultPageSelector.js index 0a163363c46..988891c41d3 100644 --- a/server/sonar-web/src/main/js/apps/projects/components/DefaultPageSelector.js +++ b/server/sonar-web/src/main/js/apps/projects/components/DefaultPageSelector.js @@ -109,7 +109,7 @@ class DefaultPageSelector extends React.PureComponent { location={this.props.location} optionBarOpen={this.props.optionBarOpen} optionBarToggle={this.props.optionBarToggle} - user={this.props.currentUser} + currentUser={this.props.currentUser} /> ); } diff --git a/server/sonar-web/src/main/js/apps/projects/components/FavoriteProjectsContainer.js b/server/sonar-web/src/main/js/apps/projects/components/FavoriteProjectsContainer.js index ffad9d0b8d5..bf2a030408b 100644 --- a/server/sonar-web/src/main/js/apps/projects/components/FavoriteProjectsContainer.js +++ b/server/sonar-web/src/main/js/apps/projects/components/FavoriteProjectsContainer.js @@ -20,12 +20,12 @@ import { connect } from 'react-redux'; import { withRouter } from 'react-router'; import AllProjects from './AllProjects'; -import { fetchProjects } from '../store/actions'; import { getCurrentUser } from '../../../store/rootReducer'; +import { fetchProjects } from '../store/actions'; const mapStateToProps = state => ({ - user: getCurrentUser(state), - isFavorite: true + isFavorite: true, + currentUser: getCurrentUser(state) }); export default connect(mapStateToProps, { fetchProjects })(withRouter(AllProjects)); diff --git a/server/sonar-web/src/main/js/apps/projects/components/ProjectsOptionBar.js b/server/sonar-web/src/main/js/apps/projects/components/ProjectsOptionBar.js index b076abcb98d..98537d80eba 100644 --- a/server/sonar-web/src/main/js/apps/projects/components/ProjectsOptionBar.js +++ b/server/sonar-web/src/main/js/apps/projects/components/ProjectsOptionBar.js @@ -33,7 +33,7 @@ type Props = { projects: Array<*>, projectsAppState: { loading: boolean, total?: number }, selectedSort: string, - user?: { isLoggedIn: boolean }, + currentUser?: { isLoggedIn: boolean }, view: string, visualization?: string }; @@ -48,12 +48,12 @@ export default class ProjectsOptionBar extends React.PureComponent { }; renderSortingSelect() { - const { projectsAppState, projects, user, view } = this.props; + const { projectsAppState, projects, currentUser, view } = this.props; const limitReached = projects != null && projectsAppState.total != null && projects.length < projectsAppState.total; - const defaultOption = user && user.isLoggedIn ? 'name' : 'analysis_date'; + const defaultOption = currentUser && currentUser.isLoggedIn ? 'name' : 'analysis_date'; if (view === 'visualizations' && !limitReached) { return ( diff --git a/server/sonar-web/src/main/js/apps/projects/components/__tests__/ProjectOptionBar-test.js b/server/sonar-web/src/main/js/apps/projects/components/__tests__/ProjectOptionBar-test.js index 14d16176c63..c496b37c7d7 100644 --- a/server/sonar-web/src/main/js/apps/projects/components/__tests__/ProjectOptionBar-test.js +++ b/server/sonar-web/src/main/js/apps/projects/components/__tests__/ProjectOptionBar-test.js @@ -35,7 +35,7 @@ it('should render option bar open', () => { visualization="risk" projects={[1, 2, 3]} projectsAppState={{ total: 3 }} - user={{ isLoggedIn: true }} + currentUser={{ isLoggedIn: true }} /> ) ).toMatchSnapshot(); @@ -61,7 +61,7 @@ it('should render switch the default sorting option for anonymous users', () => open={true} view="overall" visualization="risk" - user={{ isLoggedIn: true }} + currentUser={{ isLoggedIn: true }} /> ).find('ProjectsSortingSelect') ).toMatchSnapshot(); @@ -71,7 +71,7 @@ it('should render switch the default sorting option for anonymous users', () => open={true} view="leak" visualization="risk" - user={{ isLoggedIn: false }} + currentUser={{ isLoggedIn: false }} /> ).find('ProjectsSortingSelect') ).toMatchSnapshot();