diff options
author | Stas Vilchik <stas.vilchik@sonarsource.com> | 2017-11-23 16:05:14 +0100 |
---|---|---|
committer | Stas Vilchik <stas.vilchik@sonarsource.com> | 2017-12-11 18:00:33 +0100 |
commit | b5825706ab56c92dfae7e12d91af4891e363e03b (patch) | |
tree | 3711cb5e469be80d887c749564667b3517ed8a53 /server/sonar-web/src/main/js/apps/projects/components/DefaultPageSelector.tsx | |
parent | 36685ff3e20875421162206c34aabb31d5b21fdb (diff) | |
download | sonarqube-b5825706ab56c92dfae7e12d91af4891e363e03b.tar.gz sonarqube-b5825706ab56c92dfae7e12d91af4891e363e03b.zip |
SONAR-10080 turn Projects to My Projects
Diffstat (limited to 'server/sonar-web/src/main/js/apps/projects/components/DefaultPageSelector.tsx')
-rw-r--r-- | server/sonar-web/src/main/js/apps/projects/components/DefaultPageSelector.tsx | 44 |
1 files changed, 27 insertions, 17 deletions
diff --git a/server/sonar-web/src/main/js/apps/projects/components/DefaultPageSelector.tsx b/server/sonar-web/src/main/js/apps/projects/components/DefaultPageSelector.tsx index c5d4197f1be..56d148f82b2 100644 --- a/server/sonar-web/src/main/js/apps/projects/components/DefaultPageSelector.tsx +++ b/server/sonar-web/src/main/js/apps/projects/components/DefaultPageSelector.tsx @@ -19,12 +19,15 @@ */ import * as React from 'react'; import * as PropTypes from 'prop-types'; -import AllProjects from './AllProjects'; +import AllProjectsContainer from './AllProjectsContainer'; import { isFavoriteSet, isAllSet } from '../../../helpers/storage'; import { searchProjects } from '../../../api/components'; +import { CurrentUser, isLoggedIn } from '../../../app/types'; interface Props { + currentUser: CurrentUser; location: { pathname: string; query: { [x: string]: string } }; + onSonarCloud: boolean; } interface State { @@ -34,7 +37,6 @@ interface State { export default class DefaultPageSelector extends React.PureComponent<Props, State> { static contextTypes = { - currentUser: PropTypes.object.isRequired, router: PropTypes.object.isRequired }; @@ -44,22 +46,26 @@ export default class DefaultPageSelector extends React.PureComponent<Props, Stat } componentDidMount() { - this.defineIfShouldBeRedirected(); + if (!this.props.onSonarCloud) { + this.defineIfShouldBeRedirected(); + } } componentDidUpdate(prevProps: Props) { - if (prevProps.location !== this.props.location) { - this.defineIfShouldBeRedirected(); - } else if (this.state.shouldBeRedirected === true) { - this.context.router.replace({ ...this.props.location, pathname: '/projects/favorite' }); - } else if (this.state.shouldForceSorting != null) { - this.context.router.replace({ - ...this.props.location, - query: { - ...this.props.location.query, - sort: this.state.shouldForceSorting - } - }); + if (!this.props.onSonarCloud) { + if (prevProps.location !== this.props.location) { + this.defineIfShouldBeRedirected(); + } else if (this.state.shouldBeRedirected === true) { + this.context.router.replace({ ...this.props.location, pathname: '/projects/favorite' }); + } else if (this.state.shouldForceSorting != null) { + this.context.router.replace({ + ...this.props.location, + query: { + ...this.props.location.query, + sort: this.state.shouldForceSorting + } + }); + } } } @@ -67,7 +73,7 @@ export default class DefaultPageSelector extends React.PureComponent<Props, Stat if (Object.keys(this.props.location.query).length > 0) { // show ALL projects when there are some filters this.setState({ shouldBeRedirected: false, shouldForceSorting: undefined }); - } else if (!this.context.currentUser.isLoggedIn) { + } else if (!isLoggedIn(this.props.currentUser)) { // show ALL projects if user is anonymous if (!this.props.location.query || !this.props.location.query.sort) { // force default sorting to last analysis date @@ -92,11 +98,15 @@ export default class DefaultPageSelector extends React.PureComponent<Props, Stat } render() { + if (this.props.onSonarCloud) { + return <AllProjectsContainer isFavorite={true} location={this.props.location} />; + } + const { shouldBeRedirected, shouldForceSorting } = this.state; if (shouldBeRedirected == null || shouldBeRedirected === true || shouldForceSorting != null) { return null; } else { - return <AllProjects isFavorite={false} location={this.props.location} />; + return <AllProjectsContainer isFavorite={false} location={this.props.location} />; } } } |