You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

App.tsx 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2019 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. import * as React from 'react';
  21. import { Helmet } from 'react-helmet';
  22. import { getBaseUrl, getPathUrlAsString } from 'sonar-ui-common/helpers/urls';
  23. import { lazyLoad } from 'sonar-ui-common/components/lazyLoad';
  24. import OverviewApp from './OverviewApp';
  25. import Suggestions from '../../../app/components/embed-docs-modal/Suggestions';
  26. import { withRouter, Router } from '../../../components/hoc/withRouter';
  27. import { getProjectUrl } from '../../../helpers/urls';
  28. import { isSonarCloud } from '../../../helpers/system';
  29. import { isShortLivingBranch, isPullRequest } from '../../../helpers/branches';
  30. const EmptyOverview = lazyLoad(() => import('./EmptyOverview'));
  31. const ReviewApp = lazyLoad(() => import('../pullRequests/ReviewApp'));
  32. interface Props {
  33. branchLike?: T.BranchLike;
  34. branchLikes: T.BranchLike[];
  35. component: T.Component;
  36. isInProgress?: boolean;
  37. isPending?: boolean;
  38. onComponentChange: (changes: Partial<T.Component>) => void;
  39. router: Pick<Router, 'replace'>;
  40. }
  41. export class App extends React.PureComponent<Props> {
  42. componentDidMount() {
  43. const { component } = this.props;
  44. if (this.isPortfolio()) {
  45. this.props.router.replace({
  46. pathname: '/portfolio',
  47. query: { id: component.key }
  48. });
  49. }
  50. }
  51. isPortfolio = () => {
  52. return ['VW', 'SVW'].includes(this.props.component.qualifier);
  53. };
  54. render() {
  55. const { branchLike, branchLikes, component } = this.props;
  56. if (this.isPortfolio()) {
  57. return null;
  58. }
  59. return (
  60. <>
  61. {isSonarCloud() && (
  62. <Helmet>
  63. <link
  64. href={getBaseUrl() + getPathUrlAsString(getProjectUrl(component.key))}
  65. rel="canonical"
  66. />
  67. </Helmet>
  68. )}
  69. {isShortLivingBranch(branchLike) || isPullRequest(branchLike) ? (
  70. <>
  71. <Suggestions suggestions="pull_requests" />
  72. <ReviewApp branchLike={branchLike} component={component} />
  73. </>
  74. ) : (
  75. <>
  76. <Suggestions suggestions="overview" />
  77. {!component.analysisDate ? (
  78. <EmptyOverview
  79. branchLike={branchLike}
  80. branchLikes={branchLikes}
  81. component={component}
  82. hasAnalyses={this.props.isPending || this.props.isInProgress}
  83. onComponentChange={this.props.onComponentChange}
  84. />
  85. ) : (
  86. <OverviewApp
  87. branchLike={branchLike}
  88. component={component}
  89. onComponentChange={this.props.onComponentChange}
  90. />
  91. )}
  92. </>
  93. )}
  94. </>
  95. );
  96. }
  97. }
  98. export default withRouter(App);