diff options
author | Stas Vilchik <stas-vilchik@users.noreply.github.com> | 2017-03-09 17:31:40 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-09 17:31:40 +0100 |
commit | 64256992734c3e8184db370f42797e34ddc6339d (patch) | |
tree | 4f88f0a026f2c648f8048e47d142b4e28180f71e /server/sonar-web/src/main | |
parent | 1e191e065bcdf797db13c9237686866d6a63ac04 (diff) | |
download | sonarqube-64256992734c3e8184db370f42797e34ddc6339d.tar.gz sonarqube-64256992734c3e8184db370f42797e34ddc6339d.zip |
SONAR-8452 open the last state of projects page (#1760)
Diffstat (limited to 'server/sonar-web/src/main')
11 files changed, 152 insertions, 40 deletions
diff --git a/server/sonar-web/src/main/js/app/components/Landing.js b/server/sonar-web/src/main/js/app/components/Landing.js index 2204c53b829..7b4ba1721dc 100644 --- a/server/sonar-web/src/main/js/app/components/Landing.js +++ b/server/sonar-web/src/main/js/app/components/Landing.js @@ -31,7 +31,7 @@ class Landing extends React.Component { componentDidMount () { const { currentUser, router } = this.props; if (currentUser.isLoggedIn) { - router.replace('/projects/favorite'); + router.replace('/projects'); } else { router.replace('/about'); } diff --git a/server/sonar-web/src/main/js/app/components/nav/global/GlobalNavBranding.js b/server/sonar-web/src/main/js/app/components/nav/global/GlobalNavBranding.js index bb099b964c1..a1f73443ea2 100644 --- a/server/sonar-web/src/main/js/app/components/nav/global/GlobalNavBranding.js +++ b/server/sonar-web/src/main/js/app/components/nav/global/GlobalNavBranding.js @@ -40,7 +40,7 @@ class GlobalNavBranding extends React.Component { } render () { - const homeController = this.props.currentUser.isLoggedIn ? '/projects/favorite' : '/about'; + const homeController = this.props.currentUser.isLoggedIn ? '/projects' : '/about'; const homeLinkClassName = 'navbar-brand' + (this.props.customLogoUrl ? ' navbar-brand-custom' : ''); return ( <div className="navbar-header"> diff --git a/server/sonar-web/src/main/js/app/components/nav/global/GlobalNavMenu.js b/server/sonar-web/src/main/js/app/components/nav/global/GlobalNavMenu.js index 3c3272a339c..3693e493fcf 100644 --- a/server/sonar-web/src/main/js/app/components/nav/global/GlobalNavMenu.js +++ b/server/sonar-web/src/main/js/app/components/nav/global/GlobalNavMenu.js @@ -38,10 +38,9 @@ export default class GlobalNavMenu extends React.Component { } renderProjects () { - const pathname = this.props.currentUser.isLoggedIn ? '/projects/favorite' : '/projects'; return ( <li> - <Link to={{ pathname }} activeClassName="active"> + <Link to="/projects" activeClassName="active"> {translate('projects.page')} </Link> </li> diff --git a/server/sonar-web/src/main/js/app/components/nav/global/__tests__/__snapshots__/GlobalNavMenu-test.js.snap b/server/sonar-web/src/main/js/app/components/nav/global/__tests__/__snapshots__/GlobalNavMenu-test.js.snap index f212db31949..2f2dc6dd0f3 100644 --- a/server/sonar-web/src/main/js/app/components/nav/global/__tests__/__snapshots__/GlobalNavMenu-test.js.snap +++ b/server/sonar-web/src/main/js/app/components/nav/global/__tests__/__snapshots__/GlobalNavMenu-test.js.snap @@ -6,11 +6,7 @@ exports[`test should work with extensions 1`] = ` activeClassName="active" onlyActiveOnIndex={false} style={Object {}} - to={ - Object { - "pathname": "/projects", - } - }> + to="/projects"> projects.page </Link> </li> 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 d80c910db60..1b71ee0f02d 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 @@ -49,7 +49,10 @@ class OrganizationProjects extends React.Component { <div id="projects-page" className="page page-limited"> <Helmet title={translate('projects.page')} titleTemplate="%s - SonarQube"/> <PageHeaderContainer organization={this.props.organization}/> - <AllProjectsContainer location={this.props.location} organization={this.props.organization}/> + <AllProjectsContainer + isFavorite={false} + location={this.props.location} + organization={this.props.organization}/> </div> ); } 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 f7fbe17c899..b4d8d44a06c 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 @@ -22,6 +22,7 @@ import ProjectsListContainer from './ProjectsListContainer'; import ProjectsListFooterContainer from './ProjectsListFooterContainer'; import PageSidebar from './PageSidebar'; import { parseUrlQuery } from '../store/utils'; +import { saveAll, saveFavorite } from '../utils'; export default class AllProjects extends React.Component { static propTypes = { @@ -35,6 +36,14 @@ export default class AllProjects extends React.Component { }; componentDidMount () { + // do not touch organization-level page + if (!this.props.organization) { + if (this.props.isFavorite) { + saveFavorite(); + } else { + saveAll(); + } + } this.handleQueryChange(); } diff --git a/server/sonar-web/src/main/js/apps/projects/components/AllProjectsContainer.js b/server/sonar-web/src/main/js/apps/projects/components/AllProjectsContainer.js index 1230fca10d3..52398e9b340 100644 --- a/server/sonar-web/src/main/js/apps/projects/components/AllProjectsContainer.js +++ b/server/sonar-web/src/main/js/apps/projects/components/AllProjectsContainer.js @@ -20,14 +20,5 @@ import { connect } from 'react-redux'; import AllProjects from './AllProjects'; import { fetchProjects } from '../store/actions'; -import { getCurrentUser } from '../../../store/rootReducer'; -const mapStateToProps = state => ({ - user: getCurrentUser(state), - isFavorite: false -}); - -export default connect( - mapStateToProps, - { fetchProjects } -)(AllProjects); +export default connect(null, { fetchProjects })(AllProjects); 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 new file mode 100644 index 00000000000..eb487b5eb56 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/projects/components/DefaultPageSelector.js @@ -0,0 +1,59 @@ +/* + * 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 { withRouter } from 'react-router'; +import AllProjectsContainer from './AllProjectsContainer'; +import { getCurrentUser } from '../../../store/rootReducer'; +import { shouldRedirectToFavorite } from '../utils'; + +class DefaultPageSelector extends React.PureComponent { + props: { + currentUser: { isLoggedIn: boolean }, + location: {}, + router: { replace: (path: string) => void } + }; + + componentDidMount () { + if (shouldRedirectToFavorite(this.props.currentUser)) { + this.props.router.replace('/projects/favorite'); + } + } + + render () { + if (shouldRedirectToFavorite(this.props.currentUser)) { + return null; + } else { + return ( + <AllProjectsContainer + isFavorite={false} + location={this.props.location} + user={this.props.currentUser}/> + ); + } + } +} + +const mapStateToProps = state => ({ + currentUser: getCurrentUser(state) +}); + +export default connect(mapStateToProps)(withRouter(DefaultPageSelector)); diff --git a/server/sonar-web/src/main/js/apps/projects/components/FavoriteFilter.js b/server/sonar-web/src/main/js/apps/projects/components/FavoriteFilter.js index 5bc0311bb23..ebf2305ab13 100644 --- a/server/sonar-web/src/main/js/apps/projects/components/FavoriteFilter.js +++ b/server/sonar-web/src/main/js/apps/projects/components/FavoriteFilter.js @@ -20,6 +20,7 @@ import React from 'react'; import { IndexLink, Link } from 'react-router'; import { translate } from '../../../helpers/l10n'; +import { saveAll } from '../utils'; export default class FavoriteFilter extends React.Component { render () { @@ -27,25 +28,34 @@ export default class FavoriteFilter extends React.Component { return null; } - const pathnameForFavorite = this.props.organization ? - `/organizations/${this.props.organization.key}/projects/favorite` : - '/projects/favorite'; + const pathnameForFavorite = this.props.organization + ? `/organizations/${this.props.organization.key}/projects/favorite` + : '/projects/favorite'; - const pathnameForAll = this.props.organization ? - `/organizations/${this.props.organization.key}/projects` : - '/projects'; + const pathnameForAll = this.props.organization + ? `/organizations/${this.props.organization.key}/projects` + : '/projects'; return ( - <div className="projects-sidebar pull-left text-center"> - <div className="button-group"> - <Link to={pathnameForFavorite} className="button" activeClassName="button-active"> - {translate('my_favorites')} - </Link> - <IndexLink to={pathnameForAll} className="button" activeClassName="button-active"> - {translate('all')} - </IndexLink> - </div> + <div className="projects-sidebar pull-left text-center"> + <div className="button-group"> + <Link + id="favorite-projects" + to={pathnameForFavorite} + className="button" + activeClassName="button-active"> + {translate('my_favorites')} + </Link> + <IndexLink + id="all-projects" + to={pathnameForAll} + className="button" + activeClassName="button-active" + onClick={saveAll}> + {translate('all')} + </IndexLink> </div> + </div> ); } } diff --git a/server/sonar-web/src/main/js/apps/projects/routes.js b/server/sonar-web/src/main/js/apps/projects/routes.js index 4da139e7ad0..4ed8f72a50a 100644 --- a/server/sonar-web/src/main/js/apps/projects/routes.js +++ b/server/sonar-web/src/main/js/apps/projects/routes.js @@ -20,12 +20,12 @@ import React from 'react'; import { Route, IndexRoute } from 'react-router'; import App from './components/App'; -import AllProjectsContainer from './components/AllProjectsContainer'; +import DefaultPageSelector from './components/DefaultPageSelector'; import FavoriteProjectsContainer from './components/FavoriteProjectsContainer'; export default ( - <Route component={App}> - <IndexRoute component={AllProjectsContainer}/> - <Route path="favorite" component={FavoriteProjectsContainer}/> - </Route> + <Route component={App}> + <IndexRoute component={DefaultPageSelector}/> + <Route path="favorite" component={FavoriteProjectsContainer}/> + </Route> ); diff --git a/server/sonar-web/src/main/js/apps/projects/utils.js b/server/sonar-web/src/main/js/apps/projects/utils.js new file mode 100644 index 00000000000..598a8cf73c4 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/projects/utils.js @@ -0,0 +1,45 @@ +/* + * 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 +const LOCALSTORAGE_KEY = 'sonarqube.projects.default'; +const LOCALSTORAGE_FAVORITE = 'favorite'; +const LOCALSTORAGE_ALL = 'all'; + +const isFavoriteSet = (): boolean => { + const setting = window.localStorage.getItem(LOCALSTORAGE_KEY); + return setting === LOCALSTORAGE_FAVORITE; +}; + +export const shouldRedirectToFavorite = (currentUser: { isLoggedIn: boolean }) => { + return currentUser.isLoggedIn && isFavoriteSet(); +}; + +const save = (value: string) => { + try { + window.localStorage.setItem(LOCALSTORAGE_KEY, value); + } catch (e) { + // usually that means the storage is full + // just do nothing in this case + } +}; + +export const saveAll = () => save(LOCALSTORAGE_ALL); + +export const saveFavorite = () => save(LOCALSTORAGE_FAVORITE); |