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.

WorstProjects.tsx 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 { max } from 'lodash';
  23. import { SubComponent } from '../types';
  24. import Measure from '../../../components/measure/Measure';
  25. import QualifierIcon from '../../../components/icons-components/QualifierIcon';
  26. import { translate, translateWithParameters } from '../../../helpers/l10n';
  27. import { formatMeasure } from '../../../helpers/measures';
  28. import { getProjectUrl } from '../../../helpers/urls';
  29. interface Props {
  30. component: string;
  31. subComponents: SubComponent[];
  32. total: number;
  33. }
  34. export default function WorstProjects({ component, subComponents, total }: Props) {
  35. const count = subComponents.length;
  36. if (!count) {
  37. return null;
  38. }
  39. const maxLoc = max(
  40. subComponents.map(component => Number(component.measures['ncloc'] || 0))
  41. ) as number;
  42. const projectsPageUrl = { pathname: '/code', query: { id: component } };
  43. return (
  44. <div className="panel panel-white portfolio-sub-components" id="portfolio-sub-components">
  45. <table className="data zebra">
  46. <thead>
  47. <tr>
  48. <th>&nbsp;</th>
  49. <th className="text-center portfolio-sub-components-cell">
  50. {translate('metric_domain.Releasability')}
  51. </th>
  52. <th className="text-center portfolio-sub-components-cell">
  53. {translate('metric_domain.Reliability')}
  54. </th>
  55. <th className="text-center portfolio-sub-components-cell">
  56. {translate('portfolio.metric_domain.vulnerabilities')}
  57. </th>
  58. <th className="text-center portfolio-sub-components-cell">
  59. {translate('portfolio.metric_domain.security_hotspots')}
  60. </th>
  61. <th className="text-center portfolio-sub-components-cell">
  62. {translate('metric_domain.Maintainability')}
  63. </th>
  64. <th className="text-center portfolio-sub-components-cell">
  65. {translate('metric.ncloc.name')}
  66. </th>
  67. </tr>
  68. </thead>
  69. <tbody>
  70. {subComponents.map(component => (
  71. <tr key={component.key}>
  72. <td>
  73. <Link
  74. className="link-with-icon"
  75. to={getProjectUrl(component.refKey || component.key)}>
  76. <QualifierIcon qualifier={component.qualifier} /> {component.name}
  77. </Link>
  78. </td>
  79. {component.qualifier === 'TRK'
  80. ? renderCell(component.measures, 'alert_status', 'LEVEL')
  81. : renderCell(component.measures, 'releasability_rating', 'RATING')}
  82. {renderCell(component.measures, 'reliability_rating', 'RATING')}
  83. {renderCell(component.measures, 'security_rating', 'RATING')}
  84. {renderCell(component.measures, 'security_review_rating', 'RATING')}
  85. {renderCell(component.measures, 'sqale_rating', 'RATING')}
  86. {renderNcloc(component.measures, maxLoc)}
  87. </tr>
  88. ))}
  89. </tbody>
  90. </table>
  91. {total > count && (
  92. <footer className="spacer-top note text-center">
  93. {translateWithParameters(
  94. 'x_of_y_shown',
  95. formatMeasure(count, 'INT'),
  96. formatMeasure(total, 'INT')
  97. )}
  98. <Link className="spacer-left" to={projectsPageUrl}>
  99. {translate('show_more')}
  100. </Link>
  101. </footer>
  102. )}
  103. </div>
  104. );
  105. }
  106. function renderCell(measures: T.Dict<string | undefined>, metric: string, type: string) {
  107. return (
  108. <td className="text-center">
  109. <Measure metricKey={metric} metricType={type} value={measures[metric]} />
  110. </td>
  111. );
  112. }
  113. function renderNcloc(measures: T.Dict<string | undefined>, maxLoc: number) {
  114. const ncloc = Number(measures['ncloc'] || 0);
  115. const barWidth = maxLoc > 0 ? Math.max(1, Math.round((ncloc / maxLoc) * 50)) : 0;
  116. return (
  117. <td className="text-right">
  118. <span className="note">
  119. <Measure metricKey="ncloc" metricType="SHORT_INT" value={measures['ncloc']} />
  120. </span>
  121. {maxLoc > 0 && (
  122. <svg className="spacer-left" height="16" width="50">
  123. <rect className="bar-chart-bar" height="10" width={barWidth} x="0" y="3" />
  124. </svg>
  125. )}
  126. </td>
  127. );
  128. }