您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ProjectInformationRenderer.tsx 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 { ButtonLink } from '../../../../../components/controls/buttons';
  22. import ModalButton from '../../../../../components/controls/ModalButton';
  23. import PrivacyBadgeContainer from '../../../../../components/common/PrivacyBadgeContainer';
  24. import { translate } from '../../../../../helpers/l10n';
  25. import { ComponentQualifier } from '../../../../../types/component';
  26. import { Component, Measure } from '../../../../../types/types';
  27. import DrawerLink from './DrawerLink';
  28. import MetaKey from './meta/MetaKey';
  29. import MetaLinks from './meta/MetaLinks';
  30. import MetaQualityGate from './meta/MetaQualityGate';
  31. import MetaQualityProfiles from './meta/MetaQualityProfiles';
  32. import MetaSize from './meta/MetaSize';
  33. import MetaTags from './meta/MetaTags';
  34. import { ProjectInformationPages } from './ProjectInformationPages';
  35. import RegulatoryReportModal from './projectRegulatoryReport/RegulatoryReportModal';
  36. import withAppStateContext from '../../../app-state/withAppStateContext';
  37. import { AppState } from '../../../../../types/appstate';
  38. import { BranchLike } from '../../../../../types/branch-like';
  39. export interface ProjectInformationRendererProps {
  40. appState: AppState;
  41. canConfigureNotifications: boolean;
  42. canUseBadges: boolean;
  43. component: Component;
  44. branchLike?: BranchLike;
  45. measures?: Measure[];
  46. onComponentChange: (changes: {}) => void;
  47. onPageChange: (page: ProjectInformationPages) => void;
  48. }
  49. export function ProjectInformationRenderer(props: ProjectInformationRendererProps) {
  50. const {
  51. canConfigureNotifications,
  52. canUseBadges,
  53. component,
  54. measures = [],
  55. appState,
  56. branchLike
  57. } = props;
  58. const isApp = component.qualifier === ComponentQualifier.Application;
  59. return (
  60. <>
  61. <div>
  62. <h2 className="big-padded bordered-bottom">
  63. {translate(isApp ? 'application' : 'project', 'info.title')}
  64. </h2>
  65. </div>
  66. <div className="overflow-y-auto">
  67. <div className="big-padded bordered-bottom">
  68. <div className="display-flex-center">
  69. <h3 className="spacer-right">{translate('project.info.description')}</h3>
  70. {component.visibility && (
  71. <PrivacyBadgeContainer
  72. qualifier={component.qualifier}
  73. visibility={component.visibility}
  74. />
  75. )}
  76. </div>
  77. {component.description && (
  78. <p className="it__project-description">{component.description}</p>
  79. )}
  80. <MetaTags component={component} onComponentChange={props.onComponentChange} />
  81. </div>
  82. <div className="big-padded bordered-bottom it__project-loc-value">
  83. <MetaSize component={component} measures={measures} />
  84. </div>
  85. {!isApp &&
  86. (component.qualityGate ||
  87. (component.qualityProfiles && component.qualityProfiles.length > 0)) && (
  88. <>
  89. <div className="big-padded bordered-bottom">
  90. {component.qualityGate && <MetaQualityGate qualityGate={component.qualityGate} />}
  91. {component.qualityProfiles && component.qualityProfiles.length > 0 && (
  92. <MetaQualityProfiles
  93. headerClassName={component.qualityGate ? 'big-spacer-top' : undefined}
  94. profiles={component.qualityProfiles}
  95. />
  96. )}
  97. </div>
  98. </>
  99. )}
  100. {!isApp && <MetaLinks component={component} />}
  101. <div className="big-padded bordered-bottom">
  102. <MetaKey componentKey={component.key} qualifier={component.qualifier} />
  103. </div>
  104. {canUseBadges && (
  105. <DrawerLink
  106. label={translate('overview.badges.get_badge', component.qualifier)}
  107. onPageChange={props.onPageChange}
  108. to={ProjectInformationPages.badges}
  109. />
  110. )}
  111. {canConfigureNotifications && (
  112. <DrawerLink
  113. label={translate('project.info.to_notifications')}
  114. onPageChange={props.onPageChange}
  115. to={ProjectInformationPages.notifications}
  116. />
  117. )}
  118. {component.qualifier === ComponentQualifier.Project &&
  119. appState.regulatoryReportFeatureEnabled && (
  120. <div className="big-padded bordered-bottom">
  121. <ModalButton
  122. modal={({ onClose }) => (
  123. <RegulatoryReportModal
  124. component={component}
  125. branchLike={branchLike}
  126. onClose={onClose}
  127. />
  128. )}>
  129. {({ onClick }) => (
  130. <ButtonLink onClick={onClick}>{translate('regulatory_report.page')}</ButtonLink>
  131. )}
  132. </ModalButton>
  133. </div>
  134. )}
  135. </div>
  136. </>
  137. );
  138. }
  139. export default withAppStateContext(React.memo(ProjectInformationRenderer));