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.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2022 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 withAppStateContext from '../../../app/components/app-state/withAppStateContext';
  22. import Suggestions from '../../../app/components/embed-docs-modal/Suggestions';
  23. import { Router, withRouter } from '../../../components/hoc/withRouter';
  24. import { lazyLoadComponent } from '../../../components/lazyLoadComponent';
  25. import { isPullRequest } from '../../../helpers/branch-like';
  26. import { ProjectAlmBindingResponse } from '../../../types/alm-settings';
  27. import { AppState } from '../../../types/appstate';
  28. import { BranchLike } from '../../../types/branch-like';
  29. import { isPortfolioLike } from '../../../types/component';
  30. import { Component } from '../../../types/types';
  31. import BranchOverview from '../branches/BranchOverview';
  32. const EmptyOverview = lazyLoadComponent(() => import('./EmptyOverview'));
  33. const PullRequestOverview = lazyLoadComponent(() => import('../pullRequests/PullRequestOverview'));
  34. interface Props {
  35. appState: AppState;
  36. branchLike?: BranchLike;
  37. branchLikes: BranchLike[];
  38. component: Component;
  39. isInProgress?: boolean;
  40. isPending?: boolean;
  41. projectBinding?: ProjectAlmBindingResponse;
  42. router: Pick<Router, 'replace'>;
  43. }
  44. export class App extends React.PureComponent<Props> {
  45. isPortfolio = () => {
  46. return isPortfolioLike(this.props.component.qualifier);
  47. };
  48. render() {
  49. const {
  50. appState: { branchesEnabled },
  51. branchLike,
  52. branchLikes,
  53. component,
  54. projectBinding
  55. } = this.props;
  56. if (this.isPortfolio()) {
  57. return null;
  58. }
  59. return isPullRequest(branchLike) ? (
  60. <>
  61. <Suggestions suggestions="pull_requests" />
  62. <PullRequestOverview branchLike={branchLike} component={component} />
  63. </>
  64. ) : (
  65. <>
  66. <Suggestions suggestions="overview" />
  67. {!component.analysisDate && (
  68. <EmptyOverview
  69. branchLike={branchLike}
  70. branchLikes={branchLikes}
  71. component={component}
  72. hasAnalyses={this.props.isPending || this.props.isInProgress}
  73. projectBinding={projectBinding}
  74. />
  75. )}
  76. {component.analysisDate && (
  77. <BranchOverview
  78. branch={branchLike}
  79. branchesEnabled={branchesEnabled}
  80. component={component}
  81. projectBinding={projectBinding}
  82. />
  83. )}
  84. </>
  85. );
  86. }
  87. }
  88. export default withRouter(withAppStateContext(App));