From 34dffa98cc400f52b59826670c765a77e07316e9 Mon Sep 17 00:00:00 2001 From: 7PH Date: Mon, 6 Nov 2023 11:33:38 +0100 Subject: [PATCH] SONAR-20872 Rename and use accepted_metric in place of won't fix metric in measures page --- .../src/main/js/apps/component-measures/utils.ts | 5 +++-- .../src/main/js/apps/projectActivity/utils.ts | 7 ++++++- server/sonar-web/src/main/js/helpers/measures.ts | 4 ++++ server/sonar-web/src/main/js/helpers/mocks/metrics.ts | 10 +++++----- server/sonar-web/src/main/js/types/metrics.ts | 1 + 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/server/sonar-web/src/main/js/apps/component-measures/utils.ts b/server/sonar-web/src/main/js/apps/component-measures/utils.ts index e146258c985..ca845e698b2 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/utils.ts +++ b/server/sonar-web/src/main/js/apps/component-measures/utils.ts @@ -21,7 +21,7 @@ import { groupBy, memoize, sortBy, toPairs } from 'lodash'; import { enhanceMeasure } from '../../components/measure/utils'; import { isBranch, isPullRequest } from '../../helpers/branch-like'; import { getLocalizedMetricName } from '../../helpers/l10n'; -import { getDisplayMetrics, isDiffMetric } from '../../helpers/measures'; +import { MEASURES_REDIRECTION, getDisplayMetrics, isDiffMetric } from '../../helpers/measures'; import { cleanQuery, parseAsOptionalBoolean, @@ -231,7 +231,8 @@ export interface Query { } export const parseQuery = memoize((urlQuery: RawQuery): Query => { - const metric = (parseAsString(urlQuery['metric']) || DEFAULT_METRIC) as MetricKey; + const parsedMetric = parseAsString(urlQuery['metric']) || DEFAULT_METRIC; + const metric = MEASURES_REDIRECTION[parsedMetric] ?? parsedMetric; return { metric, selected: parseAsString(urlQuery['selected']), diff --git a/server/sonar-web/src/main/js/apps/projectActivity/utils.ts b/server/sonar-web/src/main/js/apps/projectActivity/utils.ts index 0e705c97498..593bed6b881 100644 --- a/server/sonar-web/src/main/js/apps/projectActivity/utils.ts +++ b/server/sonar-web/src/main/js/apps/projectActivity/utils.ts @@ -21,6 +21,7 @@ import { startOfDay } from 'date-fns'; import { isEqual } from 'lodash'; import { DEFAULT_GRAPH } from '../../components/activity-graph/utils'; import { parseDate } from '../../helpers/dates'; +import { MEASURES_REDIRECTION } from '../../helpers/measures'; import { cleanQuery, parseAsArray, @@ -30,6 +31,7 @@ import { serializeString, serializeStringArray, } from '../../helpers/query'; +import { MetricKey } from '../../types/metrics'; import { GraphType, ParsedAnalysis } from '../../types/project-activity'; import { Dict, RawQuery } from '../../types/types'; @@ -109,9 +111,12 @@ export function getAnalysesByVersionByDay( } export function parseQuery(urlQuery: RawQuery): Query { + const parsedMetrics = parseAsArray(urlQuery['custom_metrics'], parseAsString); + const customMetrics = parsedMetrics.map((metric) => MEASURES_REDIRECTION[metric] ?? metric); + return { category: parseAsString(urlQuery['category']), - customMetrics: parseAsArray(urlQuery['custom_metrics'], parseAsString), + customMetrics, from: parseAsDate(urlQuery['from']), graph: parseGraph(urlQuery['graph']), project: parseAsString(urlQuery['id']), diff --git a/server/sonar-web/src/main/js/helpers/measures.ts b/server/sonar-web/src/main/js/helpers/measures.ts index 3eda07fb334..7071e4c965e 100644 --- a/server/sonar-web/src/main/js/helpers/measures.ts +++ b/server/sonar-web/src/main/js/helpers/measures.ts @@ -28,6 +28,10 @@ import { translate, translateWithParameters } from './l10n'; import { getCurrentLocale } from './l10nBundle'; import { isDefined } from './types'; +export const MEASURES_REDIRECTION: Partial> = { + [MetricKey.wont_fix_issues]: MetricKey.accepted_issues, +}; + export function enhanceMeasuresWithMetrics( measures: Measure[], metrics: Metric[], diff --git a/server/sonar-web/src/main/js/helpers/mocks/metrics.ts b/server/sonar-web/src/main/js/helpers/mocks/metrics.ts index cc5f689ba96..6e48ffd22ff 100644 --- a/server/sonar-web/src/main/js/helpers/mocks/metrics.ts +++ b/server/sonar-web/src/main/js/helpers/mocks/metrics.ts @@ -1485,12 +1485,12 @@ export const DEFAULT_METRICS: Dict = { qualitative: false, hidden: false, }, - wont_fix_issues: { - id: 'AXJMbIl_PAOIsUIE3gt5', - key: 'wont_fix_issues', + accepted_issues: { + id: 'AXJMbIl_PAOIsUIE3ga7', + key: 'accepted_issues', type: 'INT', - name: "Won't Fix Issues", - description: "Won't fix issues", + name: 'Accepted Issues', + description: 'Accepted issues', domain: 'Issues', direction: -1, qualitative: false, diff --git a/server/sonar-web/src/main/js/types/metrics.ts b/server/sonar-web/src/main/js/types/metrics.ts index 14bc165900c..92578074dde 100644 --- a/server/sonar-web/src/main/js/types/metrics.ts +++ b/server/sonar-web/src/main/js/types/metrics.ts @@ -152,6 +152,7 @@ export enum MetricKey { uncovered_lines = 'uncovered_lines', violations = 'violations', vulnerabilities = 'vulnerabilities', + accepted_issues = 'accepted_issues', wont_fix_issues = 'wont_fix_issues', } -- 2.39.5