From: 7PH Date: Mon, 29 Jan 2024 14:35:46 +0000 (+0100) Subject: SONAR-21455 Rename software quailty measure usages to uppercase & Drop mocks X-Git-Tag: 10.4.0.87286~53 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=93cb409571cbcaca8332ce697b71db0bc85a9fdd;p=sonarqube.git SONAR-21455 Rename software quailty measure usages to uppercase & Drop mocks --- diff --git a/server/sonar-web/src/main/js/api/measures.ts b/server/sonar-web/src/main/js/api/measures.ts index faa195c339b..d1a15e79808 100644 --- a/server/sonar-web/src/main/js/api/measures.ts +++ b/server/sonar-web/src/main/js/api/measures.ts @@ -25,7 +25,6 @@ import { MeasuresAndMetaWithPeriod, MeasuresForProjects, } from '../types/measures'; -import { MetricKey, MetricType } from '../types/metrics'; import { Measure } from '../types/types'; const COMPONENT_URL = '/api/measures/component'; @@ -62,131 +61,25 @@ export function getMeasuresWithPeriod( }).catch(throwGlobalError); } -export async function getMeasuresWithPeriodAndMetrics( +export function getMeasuresWithPeriodAndMetrics( component: string, metrics: string[], branchParameters?: BranchParameters, ): Promise { - // TODO: Remove this mock (SONAR-21488) - const mockedMetrics = metrics.filter( - (metric) => - ![ - MetricKey.maintainability_issues, - MetricKey.reliability_issues, - MetricKey.security_issues, - ].includes(metric as MetricKey), - ); - const result = await getJSON(COMPONENT_URL, { + return getJSON(COMPONENT_URL, { additionalFields: 'period,metrics', component, - metricKeys: mockedMetrics.join(','), + metricKeys: metrics.join(','), ...branchParameters, }).catch(throwGlobalError); - if (metrics.includes(MetricKey.maintainability_issues)) { - result.metrics.push({ - key: MetricKey.maintainability_issues, - name: 'Maintainability Issues', - description: 'Maintainability Issues', - domain: 'Maintainability', - type: MetricType.Data, - higherValuesAreBetter: false, - qualitative: true, - hidden: false, - bestValue: '0', - }); - result.component.measures?.push({ - metric: MetricKey.maintainability_issues, - value: JSON.stringify({ - total: 3, - high: 1, - medium: 1, - low: 1, - }), - }); - } - if (metrics.includes(MetricKey.reliability_issues)) { - result.metrics.push({ - key: MetricKey.reliability_issues, - name: 'Reliability Issues', - description: 'Reliability Issues', - domain: 'Reliability', - type: MetricType.Data, - higherValuesAreBetter: false, - qualitative: true, - hidden: false, - bestValue: '0', - }); - result.component.measures?.push({ - metric: MetricKey.reliability_issues, - value: JSON.stringify({ - total: 2, - high: 0, - medium: 1, - low: 1, - }), - }); - } - if (metrics.includes(MetricKey.security_issues)) { - result.metrics.push({ - key: MetricKey.security_issues, - name: 'Security Issues', - description: 'Security Issues', - domain: 'Security', - type: MetricType.Data, - higherValuesAreBetter: false, - qualitative: true, - hidden: false, - bestValue: '0', - }); - result.component.measures?.push({ - metric: MetricKey.security_issues, - value: JSON.stringify({ - total: 1, - high: 0, - medium: 0, - low: 1, - }), - }); - } - return result; } -export async function getMeasuresForProjects( +export function getMeasuresForProjects( projectKeys: string[], metricKeys: string[], ): Promise { - // TODO: Remove this mock (SONAR-21488) - const mockedMetrics = metricKeys.filter( - (metric) => - ![ - MetricKey.maintainability_issues, - MetricKey.reliability_issues, - MetricKey.security_issues, - ].includes(metric as MetricKey), - ); - - const result = await getJSON('/api/measures/search', { + return getJSON('/api/measures/search', { projectKeys: projectKeys.join(), - metricKeys: mockedMetrics.join(), + metricKeys: metricKeys.join(), }).then((r) => r.measures); - - [ - MetricKey.maintainability_issues, - MetricKey.reliability_issues, - MetricKey.security_issues, - ].forEach((metric) => { - if (metricKeys.includes(metric)) { - projectKeys.forEach((projectKey) => { - result.push({ - component: projectKey, - metric, - value: JSON.stringify({ - total: 2, - }), - }); - }); - } - }); - - return result; } diff --git a/server/sonar-web/src/main/js/api/mocks/data/measures.ts b/server/sonar-web/src/main/js/api/mocks/data/measures.ts index 964937323bd..6c571bb0703 100644 --- a/server/sonar-web/src/main/js/api/mocks/data/measures.ts +++ b/server/sonar-web/src/main/js/api/mocks/data/measures.ts @@ -20,6 +20,7 @@ import { keyBy } from 'lodash'; import { isDiffMetric } from '../../../helpers/measures'; import { mockMeasure } from '../../../helpers/testMocks'; +import { SoftwareImpactSeverity } from '../../../types/clean-code-taxonomy'; import { IssueDeprecatedStatus, IssueType, RawIssue } from '../../../types/issues'; import { MetricKey, MetricType } from '../../../types/metrics'; import { Measure } from '../../../types/types'; @@ -61,9 +62,9 @@ function mockComponentMeasure(tree: ComponentTree, issueList: IssueData[], metri metric: metricKey, value: JSON.stringify({ total: 1, - high: 0, - medium: 1, - low: 0, + [SoftwareImpactSeverity.High]: 0, + [SoftwareImpactSeverity.Medium]: 1, + [SoftwareImpactSeverity.Low]: 0, }), }); @@ -72,9 +73,9 @@ function mockComponentMeasure(tree: ComponentTree, issueList: IssueData[], metri metric: metricKey, value: JSON.stringify({ total: 3, - high: 0, - medium: 2, - low: 1, + [SoftwareImpactSeverity.High]: 0, + [SoftwareImpactSeverity.Medium]: 2, + [SoftwareImpactSeverity.Low]: 1, }), }); @@ -83,9 +84,9 @@ function mockComponentMeasure(tree: ComponentTree, issueList: IssueData[], metri metric: metricKey, value: JSON.stringify({ total: 2, - high: 0, - medium: 0, - low: 1, + [SoftwareImpactSeverity.High]: 0, + [SoftwareImpactSeverity.Medium]: 0, + [SoftwareImpactSeverity.Low]: 1, }), }); } diff --git a/server/sonar-web/src/main/js/apps/overview/branches/SoftwareImpactMeasureCard.tsx b/server/sonar-web/src/main/js/apps/overview/branches/SoftwareImpactMeasureCard.tsx index a3341ce2f5e..e6df00f3ac9 100644 --- a/server/sonar-web/src/main/js/apps/overview/branches/SoftwareImpactMeasureCard.tsx +++ b/server/sonar-web/src/main/js/apps/overview/branches/SoftwareImpactMeasureCard.tsx @@ -39,7 +39,7 @@ import { } from '../../../types/clean-code-taxonomy'; import { MetricKey, MetricType } from '../../../types/metrics'; import { Component, MeasureEnhanced } from '../../../types/types'; -import { getSoftwareImpactSeverityValue, softwareQualityToMeasure } from '../utils'; +import { softwareQualityToMeasure } from '../utils'; import SoftwareImpactMeasureBreakdownCard from './SoftwareImpactMeasureBreakdownCard'; import SoftwareImpactMeasureRating from './SoftwareImpactMeasureRating'; @@ -58,7 +58,7 @@ export function SoftwareImpactMeasureCard(props: Readonly m.metric.key === metricKey); - const measure = JSON.parse(measureRaw?.value ?? 'null') as SoftwareImpactMeasureData | null; + const measure = JSON.parse(measureRaw?.value ?? 'null') as SoftwareImpactMeasureData; // Find rating measure const ratingMeasure = measures.find((m) => m.metric.key === ratingMetricKey); @@ -72,12 +72,11 @@ export function SoftwareImpactMeasureCard(props: Readonly issuesCount > 0)?.[0]; + highlightedSeverity = [ + SoftwareImpactSeverity.High, + SoftwareImpactSeverity.Medium, + SoftwareImpactSeverity.Low, + ].find((severity) => measure[severity] > 0); } return ( @@ -134,7 +133,7 @@ export function SoftwareImpactMeasureCard(props: Readonly diff --git a/server/sonar-web/src/main/js/apps/overview/branches/__tests__/BranchOverview-it.tsx b/server/sonar-web/src/main/js/apps/overview/branches/__tests__/BranchOverview-it.tsx index 0b016f39d88..a761cf832c1 100644 --- a/server/sonar-web/src/main/js/apps/overview/branches/__tests__/BranchOverview-it.tsx +++ b/server/sonar-web/src/main/js/apps/overview/branches/__tests__/BranchOverview-it.tsx @@ -38,7 +38,7 @@ import { mockQualityGateProjectStatus } from '../../../../helpers/mocks/quality- import { mockLoggedInUser, mockMeasure, mockPaging } from '../../../../helpers/testMocks'; import { renderComponent } from '../../../../helpers/testReactTestingUtils'; import { byRole, byText } from '../../../../helpers/testSelector'; -import { SoftwareQuality } from '../../../../types/clean-code-taxonomy'; +import { SoftwareImpactSeverity, SoftwareQuality } from '../../../../types/clean-code-taxonomy'; import { ComponentQualifier } from '../../../../types/component'; import { MetricKey } from '../../../../types/metrics'; import { ProjectAnalysisEventCategory } from '../../../../types/project-activity'; @@ -266,9 +266,9 @@ describe('project overview', () => { 'B', { total: 1, - high: 0, - medium: 1, - low: 0, + [SoftwareImpactSeverity.High]: 0, + [SoftwareImpactSeverity.Medium]: 1, + [SoftwareImpactSeverity.Low]: 0, }, [false, true, false], ); @@ -277,9 +277,9 @@ describe('project overview', () => { 'A', { total: 3, - high: 0, - medium: 2, - low: 1, + [SoftwareImpactSeverity.High]: 0, + [SoftwareImpactSeverity.Medium]: 2, + [SoftwareImpactSeverity.Low]: 1, }, [false, false, false], ); @@ -288,9 +288,9 @@ describe('project overview', () => { 'E', { total: 2, - high: 0, - medium: 0, - low: 1, + [SoftwareImpactSeverity.High]: 0, + [SoftwareImpactSeverity.Medium]: 0, + [SoftwareImpactSeverity.Low]: 1, }, [false, false, true], ); @@ -312,9 +312,9 @@ describe('project overview', () => { 'B', { total: 1, - high: 0, - medium: 1, - low: 0, + [SoftwareImpactSeverity.High]: 0, + [SoftwareImpactSeverity.Medium]: 1, + [SoftwareImpactSeverity.Low]: 0, }, [false, true, false], ); @@ -323,9 +323,9 @@ describe('project overview', () => { 'A', { total: 3, - high: 0, - medium: 2, - low: 1, + [SoftwareImpactSeverity.High]: 0, + [SoftwareImpactSeverity.Medium]: 2, + [SoftwareImpactSeverity.Low]: 1, }, [false, false, false], ); diff --git a/server/sonar-web/src/main/js/apps/overview/branches/test-utils.ts b/server/sonar-web/src/main/js/apps/overview/branches/test-utils.ts index d9e676b2169..319831442db 100644 --- a/server/sonar-web/src/main/js/apps/overview/branches/test-utils.ts +++ b/server/sonar-web/src/main/js/apps/overview/branches/test-utils.ts @@ -51,17 +51,23 @@ export const getPageObjects = () => { ).toBeInTheDocument(); expect( byRole('link', { - name: `overview.measures.software_impact.severity.see_x_open_issues.${data.high}.software_quality.${softwareQuality}.overview.measures.software_impact.severity.HIGH.tooltip`, + name: `overview.measures.software_impact.severity.see_x_open_issues.${ + data[SoftwareImpactSeverity.High] + }.software_quality.${softwareQuality}.overview.measures.software_impact.severity.HIGH.tooltip`, }).get(), ).toBeInTheDocument(); expect( byRole('link', { - name: `overview.measures.software_impact.severity.see_x_open_issues.${data.medium}.software_quality.${softwareQuality}.overview.measures.software_impact.severity.MEDIUM.tooltip`, + name: `overview.measures.software_impact.severity.see_x_open_issues.${ + data[SoftwareImpactSeverity.Medium] + }.software_quality.${softwareQuality}.overview.measures.software_impact.severity.MEDIUM.tooltip`, }).get(), ).toBeInTheDocument(); expect( byRole('link', { - name: `overview.measures.software_impact.severity.see_x_open_issues.${data.low}.software_quality.${softwareQuality}.overview.measures.software_impact.severity.LOW.tooltip`, + name: `overview.measures.software_impact.severity.see_x_open_issues.${ + data[SoftwareImpactSeverity.Low] + }.software_quality.${softwareQuality}.overview.measures.software_impact.severity.LOW.tooltip`, }).get(), ).toBeInTheDocument(); } diff --git a/server/sonar-web/src/main/js/apps/overview/utils.tsx b/server/sonar-web/src/main/js/apps/overview/utils.tsx index 4510c2641df..b6a894181f7 100644 --- a/server/sonar-web/src/main/js/apps/overview/utils.tsx +++ b/server/sonar-web/src/main/js/apps/overview/utils.tsx @@ -24,11 +24,7 @@ import { ISSUETYPE_METRIC_KEYS_MAP } from '../../helpers/issues'; import { translate } from '../../helpers/l10n'; import { formatMeasure } from '../../helpers/measures'; import { parseAsString } from '../../helpers/query'; -import { - SoftwareImpactMeasureData, - SoftwareImpactSeverity, - SoftwareQuality, -} from '../../types/clean-code-taxonomy'; +import { SoftwareQuality } from '../../types/clean-code-taxonomy'; import { IssueType } from '../../types/issues'; import { MetricKey } from '../../types/metrics'; import { AnalysisMeasuresVariations, MeasureHistory } from '../../types/project-activity'; @@ -194,15 +190,6 @@ export function softwareQualityToMeasure(softwareQuality: SoftwareQuality): Metr return (softwareQuality.toLowerCase() + '_issues') as MetricKey; } -// Extract the number of issues for a given severity in the software impact measure -export function getSoftwareImpactSeverityValue( - severity: SoftwareImpactSeverity, - softwareImpactMeasure?: SoftwareImpactMeasureData, -) { - const key = severity.toLowerCase() as keyof SoftwareImpactMeasureData; - return softwareImpactMeasure ? softwareImpactMeasure[key]?.toString() : ''; -} - export function getIssueRatingName(type: IssueType) { return translate('metric_domain', ISSUETYPE_METRIC_KEYS_MAP[type].ratingName); } diff --git a/server/sonar-web/src/main/js/types/clean-code-taxonomy.ts b/server/sonar-web/src/main/js/types/clean-code-taxonomy.ts index ea51bfbe928..120a753bc91 100644 --- a/server/sonar-web/src/main/js/types/clean-code-taxonomy.ts +++ b/server/sonar-web/src/main/js/types/clean-code-taxonomy.ts @@ -60,7 +60,7 @@ export interface SoftwareImpact { export interface SoftwareImpactMeasureData { total: number; - high: number; - medium: number; - low: number; + [SoftwareImpactSeverity.High]: number; + [SoftwareImpactSeverity.Medium]: number; + [SoftwareImpactSeverity.Low]: number; }