MeasuresAndMetaWithPeriod,
MeasuresForProjects,
} from '../types/measures';
-import { MetricKey, MetricType } from '../types/metrics';
import { Measure } from '../types/types';
const COMPONENT_URL = '/api/measures/component';
}).catch(throwGlobalError);
}
-export async function getMeasuresWithPeriodAndMetrics(
+export function getMeasuresWithPeriodAndMetrics(
component: string,
metrics: string[],
branchParameters?: BranchParameters,
): Promise<MeasuresAndMetaWithPeriod & MeasuresAndMetaWithMetrics> {
- // 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<MeasuresForProjects[]> {
- // 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;
}
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';
metric: metricKey,
value: JSON.stringify({
total: 1,
- high: 0,
- medium: 1,
- low: 0,
+ [SoftwareImpactSeverity.High]: 0,
+ [SoftwareImpactSeverity.Medium]: 1,
+ [SoftwareImpactSeverity.Low]: 0,
}),
});
metric: metricKey,
value: JSON.stringify({
total: 3,
- high: 0,
- medium: 2,
- low: 1,
+ [SoftwareImpactSeverity.High]: 0,
+ [SoftwareImpactSeverity.Medium]: 2,
+ [SoftwareImpactSeverity.Low]: 1,
}),
});
metric: metricKey,
value: JSON.stringify({
total: 2,
- high: 0,
- medium: 0,
- low: 1,
+ [SoftwareImpactSeverity.High]: 0,
+ [SoftwareImpactSeverity.Medium]: 0,
+ [SoftwareImpactSeverity.Low]: 1,
}),
});
}
} 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';
// Find measure for this software quality
const metricKey = softwareQualityToMeasure(softwareQuality);
const measureRaw = measures.find((m) => 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);
// We highlight the highest severity breakdown card with non-zero count if the rating is not A
let highlightedSeverity: SoftwareImpactSeverity | undefined;
if (measure && (!ratingLabel || ratingLabel !== 'A')) {
- const issuesBySeverity: [SoftwareImpactSeverity, number][] = [
- [SoftwareImpactSeverity.High, measure.high],
- [SoftwareImpactSeverity.Medium, measure.medium],
- [SoftwareImpactSeverity.Low, measure.low],
- ];
- highlightedSeverity = issuesBySeverity.find(([_, issuesCount]) => issuesCount > 0)?.[0];
+ highlightedSeverity = [
+ SoftwareImpactSeverity.High,
+ SoftwareImpactSeverity.Medium,
+ SoftwareImpactSeverity.Low,
+ ].find((severity) => measure[severity] > 0);
}
return (
key={severity}
component={component}
softwareQuality={softwareQuality}
- value={measure ? getSoftwareImpactSeverityValue(severity, measure) : undefined}
+ value={measure?.[severity]?.toString()}
severity={severity}
active={highlightedSeverity === severity}
/>
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';
'B',
{
total: 1,
- high: 0,
- medium: 1,
- low: 0,
+ [SoftwareImpactSeverity.High]: 0,
+ [SoftwareImpactSeverity.Medium]: 1,
+ [SoftwareImpactSeverity.Low]: 0,
},
[false, true, false],
);
'A',
{
total: 3,
- high: 0,
- medium: 2,
- low: 1,
+ [SoftwareImpactSeverity.High]: 0,
+ [SoftwareImpactSeverity.Medium]: 2,
+ [SoftwareImpactSeverity.Low]: 1,
},
[false, false, false],
);
'E',
{
total: 2,
- high: 0,
- medium: 0,
- low: 1,
+ [SoftwareImpactSeverity.High]: 0,
+ [SoftwareImpactSeverity.Medium]: 0,
+ [SoftwareImpactSeverity.Low]: 1,
},
[false, false, true],
);
'B',
{
total: 1,
- high: 0,
- medium: 1,
- low: 0,
+ [SoftwareImpactSeverity.High]: 0,
+ [SoftwareImpactSeverity.Medium]: 1,
+ [SoftwareImpactSeverity.Low]: 0,
},
[false, true, false],
);
'A',
{
total: 3,
- high: 0,
- medium: 2,
- low: 1,
+ [SoftwareImpactSeverity.High]: 0,
+ [SoftwareImpactSeverity.Medium]: 2,
+ [SoftwareImpactSeverity.Low]: 1,
},
[false, false, false],
);
).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();
}
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';
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);
}
export interface SoftwareImpactMeasureData {
total: number;
- high: number;
- medium: number;
- low: number;
+ [SoftwareImpactSeverity.High]: number;
+ [SoftwareImpactSeverity.Medium]: number;
+ [SoftwareImpactSeverity.Low]: number;
}