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.0KB

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