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.

MetaContainer.tsx 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 { connect } from 'react-redux';
  22. import { lazyLoad } from 'sonar-ui-common/components/lazyLoad';
  23. import { translate } from 'sonar-ui-common/helpers/l10n';
  24. import MetaKey from './MetaKey';
  25. import MetaOrganizationKey from './MetaOrganizationKey';
  26. import MetaLinks from './MetaLinks';
  27. import MetaQualityGate from './MetaQualityGate';
  28. import MetaQualityProfiles from './MetaQualityProfiles';
  29. import MetaSize from './MetaSize';
  30. import MetaTags from './MetaTags';
  31. import AnalysesList from '../events/AnalysesList';
  32. import { hasPrivateAccess } from '../../../helpers/organizations';
  33. import {
  34. getCurrentUser,
  35. getMyOrganizations,
  36. getOrganizationByKey,
  37. Store,
  38. getAppState
  39. } from '../../../store/rootReducer';
  40. import PrivacyBadgeContainer from '../../../components/common/PrivacyBadgeContainer';
  41. const BadgesModal = lazyLoad(() => import('../badges/BadgesModal'), 'BadgesModal');
  42. interface StateToProps {
  43. appState: T.AppState;
  44. currentUser: T.CurrentUser;
  45. organization?: T.Organization;
  46. userOrganizations: T.Organization[];
  47. }
  48. interface OwnProps {
  49. branchLike?: T.BranchLike;
  50. component: T.Component;
  51. history?: {
  52. [metric: string]: Array<{ date: Date; value?: string }>;
  53. };
  54. measures?: T.MeasureEnhanced[];
  55. metrics?: T.Dict<T.Metric>;
  56. onComponentChange: (changes: {}) => void;
  57. }
  58. type Props = OwnProps & StateToProps;
  59. export class Meta extends React.PureComponent<Props> {
  60. renderQualityInfos() {
  61. const { organizationsEnabled } = this.props.appState;
  62. const { component, currentUser, organization, userOrganizations } = this.props;
  63. const { qualifier, qualityProfiles, qualityGate } = component;
  64. const isProject = qualifier === 'TRK';
  65. if (
  66. !isProject ||
  67. (organizationsEnabled && !hasPrivateAccess(currentUser, organization, userOrganizations))
  68. ) {
  69. return null;
  70. }
  71. return (
  72. <div className="overview-meta-card" id="overview-meta-quality-gate">
  73. {qualityGate && (
  74. <MetaQualityGate
  75. organization={organizationsEnabled ? component.organization : undefined}
  76. qualityGate={qualityGate}
  77. />
  78. )}
  79. {qualityProfiles && qualityProfiles.length > 0 && (
  80. <MetaQualityProfiles
  81. headerClassName={qualityGate ? 'big-spacer-top' : undefined}
  82. organization={organizationsEnabled ? component.organization : undefined}
  83. profiles={qualityProfiles}
  84. />
  85. )}
  86. </div>
  87. );
  88. }
  89. render() {
  90. const { organizationsEnabled } = this.props.appState;
  91. const { branchLike, component, measures, metrics, organization } = this.props;
  92. const { qualifier, description, visibility } = component;
  93. const isProject = qualifier === 'TRK';
  94. const isApp = qualifier === 'APP';
  95. const isPrivate = visibility === 'private';
  96. return (
  97. <div className="overview-meta">
  98. <div className="overview-meta-card">
  99. <h4 className="overview-meta-header">
  100. {translate('overview.about_this_project', qualifier)}
  101. {component.visibility && (
  102. <PrivacyBadgeContainer
  103. className="spacer-left pull-right"
  104. organization={organization}
  105. qualifier={component.qualifier}
  106. tooltipProps={{ projectKey: component.key }}
  107. visibility={component.visibility}
  108. />
  109. )}
  110. </h4>
  111. {description !== undefined && <p className="overview-meta-description">{description}</p>}
  112. {isProject && (
  113. <MetaTags component={component} onComponentChange={this.props.onComponentChange} />
  114. )}
  115. {measures && (
  116. <MetaSize branchLike={branchLike} component={component} measures={measures} />
  117. )}
  118. </div>
  119. {metrics && (
  120. <AnalysesList
  121. branchLike={branchLike}
  122. component={component}
  123. history={this.props.history}
  124. metrics={metrics}
  125. qualifier={component.qualifier}
  126. />
  127. )}
  128. {this.renderQualityInfos()}
  129. {isProject && <MetaLinks component={component} />}
  130. <div className="overview-meta-card">
  131. <MetaKey componentKey={component.key} qualifier={component.qualifier} />
  132. {organizationsEnabled && <MetaOrganizationKey organization={component.organization} />}
  133. </div>
  134. {!isPrivate && (isProject || isApp) && metrics && (
  135. <BadgesModal
  136. branchLike={branchLike}
  137. metrics={metrics}
  138. project={component.key}
  139. qualifier={component.qualifier}
  140. />
  141. )}
  142. </div>
  143. );
  144. }
  145. }
  146. const mapStateToProps = (state: Store, { component }: OwnProps) => ({
  147. appState: getAppState(state),
  148. currentUser: getCurrentUser(state),
  149. organization: getOrganizationByKey(state, component.organization),
  150. userOrganizations: getMyOrganizations(state)
  151. });
  152. export default connect(mapStateToProps)(Meta);