aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/apps/projects/components
diff options
context:
space:
mode:
authorStas Vilchik <stas-vilchik@users.noreply.github.com>2017-03-09 17:31:40 +0100
committerGitHub <noreply@github.com>2017-03-09 17:31:40 +0100
commit64256992734c3e8184db370f42797e34ddc6339d (patch)
tree4f88f0a026f2c648f8048e47d142b4e28180f71e /server/sonar-web/src/main/js/apps/projects/components
parent1e191e065bcdf797db13c9237686866d6a63ac04 (diff)
downloadsonarqube-64256992734c3e8184db370f42797e34ddc6339d.tar.gz
sonarqube-64256992734c3e8184db370f42797e34ddc6339d.zip
SONAR-8452 open the last state of projects page (#1760)
Diffstat (limited to 'server/sonar-web/src/main/js/apps/projects/components')
-rw-r--r--server/sonar-web/src/main/js/apps/projects/components/AllProjects.js9
-rw-r--r--server/sonar-web/src/main/js/apps/projects/components/AllProjectsContainer.js11
-rw-r--r--server/sonar-web/src/main/js/apps/projects/components/DefaultPageSelector.js59
-rw-r--r--server/sonar-web/src/main/js/apps/projects/components/FavoriteFilter.js40
4 files changed, 94 insertions, 25 deletions
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>
);
}
}