]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-21479 Branch activity graph adopts Clean Code taxonomy
authorstanislavh <stanislav.honcharov@sonarsource.com>
Wed, 24 Jan 2024 16:35:36 +0000 (17:35 +0100)
committersonartech <sonartech@sonarsource.com>
Mon, 29 Jan 2024 20:03:17 +0000 (20:03 +0000)
server/sonar-web/src/main/js/apps/overview/utils.tsx
server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/ProjectActivityApp-it.tsx
server/sonar-web/src/main/js/components/activity-graph/GraphsTooltips.tsx
server/sonar-web/src/main/js/components/activity-graph/GraphsTooltipsContentIssues.tsx [deleted file]
server/sonar-web/src/main/js/components/activity-graph/__tests__/ActivityGraph-it.tsx
server/sonar-web/src/main/js/components/activity-graph/__tests__/DataTableModal-it.tsx
server/sonar-web/src/main/js/components/activity-graph/__tests__/GraphsTooltips-it.tsx
server/sonar-web/src/main/js/components/activity-graph/__tests__/utils-test.ts
server/sonar-web/src/main/js/components/activity-graph/utils.ts

index f0e14d2caeb0f91fa2c99d0e46150d6803646278..af64bfc79490cc6c49ad29e27038091f9a541b7c 100644 (file)
@@ -114,9 +114,7 @@ export const PR_METRICS: string[] = [
 ];
 
 export const HISTORY_METRICS_LIST: string[] = [
-  MetricKey.bugs,
-  MetricKey.vulnerabilities,
-  MetricKey.sqale_index,
+  MetricKey.violations,
   MetricKey.duplicated_lines_density,
   MetricKey.ncloc,
   MetricKey.coverage,
index d9f2cc63587ba87760f6afe4b8656189c621216e..1141b833d0b0b3e2c9c767fb21b5251981eae6d7 100644 (file)
@@ -79,6 +79,7 @@ beforeEach(() => {
 
   timeMachineHandler.setMeasureHistory(
     [
+      MetricKey.violations,
       MetricKey.bugs,
       MetricKey.reliability_rating,
       MetricKey.code_smells,
@@ -467,11 +468,11 @@ describe('graph interactions', () => {
     renderProjectActivityAppContainer();
     await ui.appLoaded();
 
-    expect(ui.bugsPopupCell.query()).not.toBeInTheDocument();
+    expect(ui.issuesPopupCell.query()).not.toBeInTheDocument();
 
     await ui.showDetails('1.1.0.1');
 
-    expect(ui.bugsPopupCell.get()).toBeInTheDocument();
+    expect(ui.issuesPopupCell.get()).toBeInTheDocument();
   });
 
   it('should correctly handle customizing the graph', async () => {
@@ -551,7 +552,7 @@ function getPageObject() {
     // Misc.
     loading: byText('loading'),
     baseline: byText('project_activity.new_code_period_start'),
-    bugsPopupCell: byRole('cell', { name: MetricKey.bugs }),
+    issuesPopupCell: byRole('cell', { name: `metric.${MetricKey.violations}.name` }),
     monthSelector: byTestId('month-select'),
     yearSelector: byTestId('year-select'),
   };
index 3ba12fc28df4d419923825fb566719115189cfd8..85bd5122726ab8cdca812eceb0b492f7ab157791 100644 (file)
@@ -27,8 +27,6 @@ import GraphsTooltipsContent from './GraphsTooltipsContent';
 import GraphsTooltipsContentCoverage from './GraphsTooltipsContentCoverage';
 import GraphsTooltipsContentDuplication from './GraphsTooltipsContentDuplication';
 import GraphsTooltipsContentEvents from './GraphsTooltipsContentEvents';
-import GraphsTooltipsContentIssues from './GraphsTooltipsContentIssues';
-import { DEFAULT_GRAPH } from './utils';
 
 interface PropsWithoutTheme {
   events: AnalysisEvent[];
@@ -50,7 +48,7 @@ const TOOLTIP_LEFT_FLIP_THRESHOLD = 50;
 
 export class GraphsTooltipsClass extends React.PureComponent<Props> {
   renderContent() {
-    const { tooltipIdx, series, graph, measuresHistory } = this.props;
+    const { tooltipIdx, series } = this.props;
 
     return series.map((serie, idx) => {
       const point = serie.data[tooltipIdx];
@@ -59,20 +57,6 @@ export class GraphsTooltipsClass extends React.PureComponent<Props> {
         return null;
       }
 
-      if (graph === DEFAULT_GRAPH) {
-        return (
-          <GraphsTooltipsContentIssues
-            index={idx}
-            key={serie.name}
-            measuresHistory={measuresHistory}
-            name={serie.name}
-            tooltipIdx={tooltipIdx}
-            translatedName={serie.translatedName}
-            value={this.props.formatValue(point.y)}
-          />
-        );
-      }
-
       return (
         <GraphsTooltipsContent
           index={idx}
diff --git a/server/sonar-web/src/main/js/components/activity-graph/GraphsTooltipsContentIssues.tsx b/server/sonar-web/src/main/js/components/activity-graph/GraphsTooltipsContentIssues.tsx
deleted file mode 100644 (file)
index 285466e..0000000
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2024 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-import { MetricsEnum, MetricsRatingBadge } from 'design-system';
-import * as React from 'react';
-import { ChartLegendIcon } from '../../components/icons/ChartLegendIcon';
-import { MetricKey } from '../../types/metrics';
-import { MeasureHistory } from '../../types/project-activity';
-import { Dict } from '../../types/types';
-
-export interface GraphsTooltipsContentIssuesProps {
-  index: number;
-  measuresHistory: MeasureHistory[];
-  name: string;
-  tooltipIdx: number;
-  translatedName: string;
-  value: string;
-}
-
-const METRIC_RATING: Dict<string> = {
-  [MetricKey.bugs]: MetricKey.reliability_rating,
-  [MetricKey.vulnerabilities]: MetricKey.security_rating,
-  [MetricKey.code_smells]: MetricKey.sqale_rating,
-};
-
-export default function GraphsTooltipsContentIssues(props: GraphsTooltipsContentIssuesProps) {
-  const { index, measuresHistory, name, tooltipIdx, translatedName, value } = props;
-  const rating = measuresHistory.find((measure) => measure.metric === METRIC_RATING[name]);
-
-  if (!rating?.history[tooltipIdx]) {
-    return null;
-  }
-
-  const ratingValue = rating.history[tooltipIdx].value;
-
-  const ratingEnumValue =
-    (ratingValue &&
-      {
-        '1.0': MetricsEnum.A,
-        '2.0': MetricsEnum.B,
-        '3.0': MetricsEnum.C,
-        '4.0': MetricsEnum.D,
-        '5.0': MetricsEnum.E,
-      }[ratingValue]) ||
-    undefined;
-
-  return (
-    <tr className="sw-h-8" key={name}>
-      <td className="sw-w-5">
-        <ChartLegendIcon className="sw-mr-0" index={index} />
-      </td>
-      <td>
-        <span className="sw-body-sm-highlight sw-ml-2">{value}</span>
-      </td>
-      <td>
-        <span className="sw-body-sm">{translatedName}</span>
-      </td>
-      {ratingValue && (
-        <td>
-          <MetricsRatingBadge label={ratingValue} rating={ratingEnumValue} size="xs" />
-        </td>
-      )}
-    </tr>
-  );
-}
index 3a22bf0d594d7a014a5915d90dc181b03d90201e..c2c0943c804625942f1eb170b4bc1026c7d62d19 100644 (file)
@@ -50,8 +50,8 @@ describe('rendering', () => {
     renderActivityGraph();
 
     // Static legend items, which aren't interactive.
-    expect(ui.legendRemoveMetricBtn(MetricKey.bugs).query()).not.toBeInTheDocument();
-    expect(ui.getLegendItem(MetricKey.bugs)).toBeInTheDocument();
+    expect(ui.legendRemoveMetricBtn(MetricKey.violations).query()).not.toBeInTheDocument();
+    expect(ui.getLegendItem(MetricKey.violations)).toBeInTheDocument();
 
     // Switch to custom graph.
     await ui.changeGraphType(GraphType.custom);
@@ -81,7 +81,7 @@ describe('data table modal', () => {
 
     await ui.openDataTable();
     expect(ui.dataTable.get()).toBeInTheDocument();
-    expect(ui.dataTableColHeaders.getAll()).toHaveLength(5);
+    expect(ui.dataTableColHeaders.getAll()).toHaveLength(3);
     expect(ui.dataTableRows.getAll()).toHaveLength(HISTORY_COUNT + 1);
 
     // Change graph type and dates, check table updates correctly.
@@ -103,7 +103,7 @@ describe('data table modal', () => {
 
     await ui.openDataTable();
     expect(ui.dataTable.get()).toBeInTheDocument();
-    expect(ui.dataTableColHeaders.getAll()).toHaveLength(5);
+    expect(ui.dataTableColHeaders.getAll()).toHaveLength(3);
     expect(ui.dataTableRows.getAll()).toHaveLength(2);
   });
 });
@@ -247,6 +247,7 @@ function renderActivityGraph(
     const measuresHistory: MeasureHistory[] = [];
     const metrics: Metric[] = [];
     [
+      MetricKey.violations,
       MetricKey.bugs,
       MetricKey.code_smells,
       MetricKey.confirmed_issues,
index 973dfb866ea2223c294075cefc2e96562f33d5cf..fc8e03c87a37bfc786d70140f0853c6b37e6cd15 100644 (file)
@@ -106,7 +106,7 @@ function renderDataTableModal(props: Partial<DataTableModalProps> = {}) {
 function mockSeries(n = 10) {
   const measuresHistory: MeasureHistory[] = [];
   const metrics: Metric[] = [];
-  [MetricKey.bugs, MetricKey.code_smells, MetricKey.vulnerabilities].forEach((metric) => {
+  [MetricKey.violations].forEach((metric) => {
     const history = times(n, (i) => {
       const date = parseDate('2016-01-01T00:00:00+0200');
       date.setDate(date.getDate() + 365 * i);
index 6c13e320a5aad75d049f652f0d3f63686c9e2219..e490c142813d9a99f8fa23cfb6fc7548fc0e6a2a 100644 (file)
@@ -34,14 +34,7 @@ import { GraphsTooltips, Props } from '../GraphsTooltips';
 import { generateSeries, getDisplayedHistoryMetrics } from '../utils';
 
 it.each([
-  [
-    GraphType.issues,
-    [
-      [MetricKey.bugs, 1, 3],
-      [MetricKey.code_smells, 0, 1],
-      [MetricKey.vulnerabilities, 2, 5],
-    ],
-  ],
+  [GraphType.issues, [[MetricKey.violations, 1]]],
   [
     GraphType.coverage,
     [
@@ -79,12 +72,8 @@ function renderGraphsTooltips(props: Partial<Props> = {}) {
 
   (
     [
+      [MetricKey.violations, '1'],
       [MetricKey.bugs, '1'],
-      [MetricKey.reliability_rating, '3'],
-      [MetricKey.code_smells, '0'],
-      [MetricKey.sqale_rating, '1'],
-      [MetricKey.vulnerabilities, '2'],
-      [MetricKey.security_rating, '5'],
       [MetricKey.lines_to_cover, '10'],
       [MetricKey.uncovered_lines, '8'],
       [MetricKey.coverage, '75'],
index 6d6ad63eff101f84ff1be109c29c08593c0e03fe..1117a9bd16245d2c8972b1ca28f0c4827085635f 100644 (file)
@@ -93,9 +93,7 @@ describe('getDisplayedHistoryMetrics', () => {
   const customMetrics = ['foo', 'bar'];
   it('should return only displayed metrics on the graph', () => {
     expect(utils.getDisplayedHistoryMetrics(utils.DEFAULT_GRAPH, [])).toEqual([
-      MetricKey.bugs,
-      MetricKey.code_smells,
-      MetricKey.vulnerabilities,
+      MetricKey.violations,
     ]);
     expect(utils.getDisplayedHistoryMetrics(GraphType.coverage, customMetrics)).toEqual([
       MetricKey.lines_to_cover,
@@ -113,9 +111,7 @@ describe('getHistoryMetrics', () => {
   const customMetrics = ['foo', 'bar'];
   it('should return all metrics', () => {
     expect(utils.getHistoryMetrics(utils.DEFAULT_GRAPH, [])).toEqual([
-      MetricKey.bugs,
-      MetricKey.code_smells,
-      MetricKey.vulnerabilities,
+      MetricKey.violations,
       MetricKey.reliability_rating,
       MetricKey.security_rating,
       MetricKey.sqale_rating,
index da67b0e48117ce58c88f772da794d929111c97e4..74de8cc41165d72e1ffbb2265824ec1cb4881bac 100644 (file)
@@ -28,7 +28,7 @@ import { Dict, Metric } from '../../types/types';
 export const DEFAULT_GRAPH = GraphType.issues;
 
 const GRAPHS_METRICS_DISPLAYED: Dict<string[]> = {
-  [GraphType.issues]: [MetricKey.bugs, MetricKey.code_smells, MetricKey.vulnerabilities],
+  [GraphType.issues]: [MetricKey.violations],
   [GraphType.coverage]: [MetricKey.lines_to_cover, MetricKey.uncovered_lines],
   [GraphType.duplications]: [MetricKey.ncloc, MetricKey.duplicated_lines],
 };