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.

MetricBox.tsx 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2021 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 { Link } from 'react-router';
  22. import ActivityLink from '../../../components/common/ActivityLink';
  23. import MeasuresLink from '../../../components/common/MeasuresLink';
  24. import HelpTooltip from '../../../components/controls/HelpTooltip';
  25. import Measure from '../../../components/measure/Measure';
  26. import Level from '../../../components/ui/Level';
  27. import { translate } from '../../../helpers/l10n';
  28. import { getComponentDrilldownUrl } from '../../../helpers/urls';
  29. import { GraphType } from '../../../types/project-activity';
  30. import { METRICS_PER_TYPE } from '../utils';
  31. import Effort from './Effort';
  32. import MainRating from './MainRating';
  33. import RatingFreshness from './RatingFreshness';
  34. export interface MetricBoxProps {
  35. component: string;
  36. measures: T.Dict<string | undefined>;
  37. metricKey: string;
  38. }
  39. export default function MetricBox({ component, measures, metricKey }: MetricBoxProps) {
  40. const keys = METRICS_PER_TYPE[metricKey];
  41. const rating = measures[keys.rating];
  42. const lastReliabilityChange = measures[keys.last_change];
  43. const rawEffort = measures[keys.effort];
  44. const effort = rawEffort ? JSON.parse(rawEffort) : undefined;
  45. return (
  46. <div className="portfolio-box">
  47. <h2 className="portfolio-box-title">
  48. {translate(keys.label)}
  49. <HelpTooltip
  50. className="little-spacer-left"
  51. overlay={translate('portfolio.metric_domain', metricKey, 'help')}
  52. />
  53. </h2>
  54. {rating ? (
  55. <MainRating component={component} metric={keys.rating} value={rating} />
  56. ) : (
  57. <div className="portfolio-box-rating">
  58. <span className="rating no-rating">—</span>
  59. </div>
  60. )}
  61. {rating && (
  62. <>
  63. <h3>{translate('portfolio.metric_trend')}</h3>
  64. <RatingFreshness lastChange={lastReliabilityChange} rating={rating} />
  65. </>
  66. )}
  67. {metricKey === 'releasability'
  68. ? Number(effort) > 0 && (
  69. <>
  70. <h3>{translate('portfolio.lowest_rated_project_branches')}</h3>
  71. <div className="portfolio-effort">
  72. <Link
  73. to={getComponentDrilldownUrl({
  74. componentKey: component,
  75. metric: 'alert_status'
  76. })}>
  77. <span>
  78. <Measure
  79. className="little-spacer-right"
  80. metricKey="projects"
  81. metricType="SHORT_INT"
  82. value={effort}
  83. />
  84. {Number(effort) === 1
  85. ? translate('portfolio.project_branch')
  86. : translate('portfolio.project_branches')}
  87. </span>
  88. </Link>
  89. <Level
  90. aria-label={
  91. Number(effort) === 1
  92. ? translate('portfolio.has_qg_status')
  93. : translate('portfolio.have_qg_status')
  94. }
  95. className="little-spacer-left"
  96. level="ERROR"
  97. small={true}
  98. />
  99. </div>
  100. </>
  101. )
  102. : effort && (
  103. <>
  104. <h3>{translate('portfolio.lowest_rated_project_branches')}</h3>
  105. <Effort component={component} effort={effort} metricKey={keys.rating} />
  106. </>
  107. )}
  108. <div className="portfolio-box-links">
  109. <div>
  110. <MeasuresLink component={component} metric={keys.measuresMetric} />
  111. </div>
  112. <div>
  113. <ActivityLink
  114. component={component}
  115. metric={keys.activity || keys.rating}
  116. graph={GraphType.custom}
  117. />
  118. </div>
  119. </div>
  120. </div>
  121. );
  122. }