diff options
Diffstat (limited to 'server/sonar-web/src/main/js/app/components')
5 files changed, 57 insertions, 59 deletions
diff --git a/server/sonar-web/src/main/js/app/components/GlobalFooter.tsx b/server/sonar-web/src/main/js/app/components/GlobalFooter.tsx index 12bf494a218..bfc13b67018 100644 --- a/server/sonar-web/src/main/js/app/components/GlobalFooter.tsx +++ b/server/sonar-web/src/main/js/app/components/GlobalFooter.tsx @@ -95,11 +95,6 @@ export default function GlobalFooter({ <Link to="/web_api">{translate('footer.web_api')}</Link> </li> )} - {!hideLoggedInInfo && ( - <li className="page-footer-menu-item"> - <Link to="/about">{translate('footer.about')}</Link> - </li> - )} </ul> </div> ); diff --git a/server/sonar-web/src/main/js/app/components/Landing.tsx b/server/sonar-web/src/main/js/app/components/Landing.tsx index f9bbee068dd..cf30a1dc2a2 100644 --- a/server/sonar-web/src/main/js/app/components/Landing.tsx +++ b/server/sonar-web/src/main/js/app/components/Landing.tsx @@ -17,34 +17,25 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -import { Location } from 'history'; import * as React from 'react'; -import { connect } from 'react-redux'; -import { withRouter, WithRouterProps } from 'react-router'; +import { withCurrentUser } from '../../components/hoc/withCurrentUser'; +import { Router, withRouter } from '../../components/hoc/withRouter'; import { getHomePageUrl } from '../../helpers/urls'; import { isLoggedIn } from '../../helpers/users'; -import { getCurrentUser, Store } from '../../store/rootReducer'; -interface StateProps { - currentUser: T.CurrentUser | undefined; +export interface LandingProps { + currentUser: T.CurrentUser; + router: Router; } -interface OwnProps { - location: Location; -} - -class Landing extends React.PureComponent<StateProps & OwnProps & WithRouterProps> { +export class Landing extends React.PureComponent<LandingProps> { componentDidMount() { const { currentUser } = this.props; - if (currentUser && isLoggedIn(currentUser)) { - if (currentUser.homepage) { - const homepage = getHomePageUrl(currentUser.homepage); - this.props.router.replace(homepage); - } else { - this.props.router.replace('/projects'); - } + if (isLoggedIn(currentUser) && currentUser.homepage) { + const homepage = getHomePageUrl(currentUser.homepage); + this.props.router.replace(homepage); } else { - this.props.router.replace('/about'); + this.props.router.replace('/projects'); } } @@ -53,8 +44,4 @@ class Landing extends React.PureComponent<StateProps & OwnProps & WithRouterProp } } -const mapStateToProps = (state: Store) => ({ - currentUser: getCurrentUser(state) -}); - -export default withRouter(connect(mapStateToProps)(Landing)); +export default withRouter(withCurrentUser(Landing)); diff --git a/server/sonar-web/src/main/js/app/components/__tests__/Landing-test.tsx b/server/sonar-web/src/main/js/app/components/__tests__/Landing-test.tsx new file mode 100644 index 00000000000..afb7e647292 --- /dev/null +++ b/server/sonar-web/src/main/js/app/components/__tests__/Landing-test.tsx @@ -0,0 +1,43 @@ +/* + * SonarQube + * Copyright (C) 2009-2021 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. + */ + +import { shallow } from 'enzyme'; +import * as React from 'react'; +import { mockCurrentUser, mockLoggedInUser, mockRouter } from '../../../helpers/testMocks'; +import { Landing } from '../Landing'; + +it.each([ + [mockCurrentUser(), '/projects'], + [mockLoggedInUser(), '/projects'], + [ + mockLoggedInUser({ homepage: { type: 'ISSUES' } }), + expect.objectContaining({ pathname: '/issues' }) + ] +])('should render correctly', (currentUser: T.CurrentUser, homepageUrl: string) => { + const router = mockRouter(); + shallowRender({ router, currentUser }); + expect(router.replace).toHaveBeenCalledWith(homepageUrl); +}); + +function shallowRender(props: Partial<Landing['props']> = {}) { + return shallow<Landing>( + <Landing currentUser={mockCurrentUser()} router={mockRouter()} {...props} /> + ); +} diff --git a/server/sonar-web/src/main/js/app/components/__tests__/__snapshots__/GlobalFooter-test.tsx.snap b/server/sonar-web/src/main/js/app/components/__tests__/__snapshots__/GlobalFooter-test.tsx.snap index d0526336fd9..61e974fab75 100644 --- a/server/sonar-web/src/main/js/app/components/__tests__/__snapshots__/GlobalFooter-test.tsx.snap +++ b/server/sonar-web/src/main/js/app/components/__tests__/__snapshots__/GlobalFooter-test.tsx.snap @@ -74,17 +74,6 @@ exports[`should display the sq version 1`] = ` footer.web_api </Link> </li> - <li - className="page-footer-menu-item" - > - <Link - onlyActiveOnIndex={false} - style={Object {}} - to="/about" - > - footer.about - </Link> - </li> </ul> </div> `; @@ -215,17 +204,6 @@ exports[`should render the only logged in information 1`] = ` footer.web_api </Link> </li> - <li - className="page-footer-menu-item" - > - <Link - onlyActiveOnIndex={false} - style={Object {}} - to="/about" - > - footer.about - </Link> - </li> </ul> </div> `; diff --git a/server/sonar-web/src/main/js/app/components/nav/global/GlobalNavUser.tsx b/server/sonar-web/src/main/js/app/components/nav/global/GlobalNavUser.tsx index 8d808a68ac4..f1a1d0a989b 100644 --- a/server/sonar-web/src/main/js/app/components/nav/global/GlobalNavUser.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/global/GlobalNavUser.tsx @@ -35,14 +35,9 @@ interface Props { export class GlobalNavUser extends React.PureComponent<Props> { handleLogin = (event: React.SyntheticEvent<HTMLAnchorElement>) => { event.preventDefault(); - const shouldReturnToCurrentPage = window.location.pathname !== `${getBaseUrl()}/about`; - if (shouldReturnToCurrentPage) { - const returnTo = encodeURIComponent(window.location.pathname + window.location.search); - window.location.href = - getBaseUrl() + `/sessions/new?return_to=${returnTo}${window.location.hash}`; - } else { - window.location.href = `${getBaseUrl()}/sessions/new`; - } + const returnTo = encodeURIComponent(window.location.pathname + window.location.search); + window.location.href = + getBaseUrl() + `/sessions/new?return_to=${returnTo}${window.location.hash}`; }; handleLogout = (event: React.SyntheticEvent<HTMLAnchorElement>) => { |