From 0b63e95a35082d9c191dd8c2be2a7cce7b03e985 Mon Sep 17 00:00:00 2001 From: Viktor Vorona Date: Fri, 23 Aug 2024 14:53:57 +0200 Subject: [PATCH] SONAR-22728 Fix Sonar Issues --- .../main/js/apps/code/components/CodeApp.tsx | 2 +- .../components/MeasureOverview.tsx | 2 +- .../drilldown/BubbleChartView.tsx | 2 +- .../main/js/apps/component-measures/utils.ts | 2 +- .../apps/overview/branches/BranchOverview.tsx | 33 +++++-------------- .../src/main/js/apps/projects/query.ts | 2 +- .../src/main/js/helpers/activity-graph.ts | 2 +- 7 files changed, 14 insertions(+), 31 deletions(-) diff --git a/server/sonar-web/src/main/js/apps/code/components/CodeApp.tsx b/server/sonar-web/src/main/js/apps/code/components/CodeApp.tsx index 8e5142fee57..e91bfd4b08d 100644 --- a/server/sonar-web/src/main/js/apps/code/components/CodeApp.tsx +++ b/server/sonar-web/src/main/js/apps/code/components/CodeApp.tsx @@ -120,7 +120,7 @@ function CodeApp(props: Readonly) { }; const handleSelect = (selectedComponent: ComponentMeasure) => { - if (selectedComponent.refKey) { + if (selectedComponent.refKey !== undefined) { const codeType = newCodeSelected ? CodeScope.New : CodeScope.Overall; const url = getProjectUrl(selectedComponent.refKey, selectedComponent.branch, codeType); router.push(url); diff --git a/server/sonar-web/src/main/js/apps/component-measures/components/MeasureOverview.tsx b/server/sonar-web/src/main/js/apps/component-measures/components/MeasureOverview.tsx index 98ce0aa3f81..d9b5f1e44aa 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/components/MeasureOverview.tsx +++ b/server/sonar-web/src/main/js/apps/component-measures/components/MeasureOverview.tsx @@ -105,7 +105,7 @@ export default function MeasureOverview(props: Readonly) { const updateSelected = (component: ComponentMeasureIntern) => { if (component && isView(component.qualifier)) { - router.push(getProjectUrl(component.refKey || component.key, component.branch)); + router.push(getProjectUrl(component.refKey ?? component.key, component.branch)); } else { updateQuery({ selected: component.key !== rootComponent.key ? component.key : undefined, diff --git a/server/sonar-web/src/main/js/apps/component-measures/drilldown/BubbleChartView.tsx b/server/sonar-web/src/main/js/apps/component-measures/drilldown/BubbleChartView.tsx index 1e434ec3079..3368e745100 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/drilldown/BubbleChartView.tsx +++ b/server/sonar-web/src/main/js/apps/component-measures/drilldown/BubbleChartView.tsx @@ -104,7 +104,7 @@ export default function BubbleChartView(props: Readonly) { const y = getMeasureVal(component, bubbleMetrics.y); const size = getMeasureVal(component, bubbleMetrics.size); const colors = bubbleMetrics.colors?.map((metric) => getMeasureVal(component, metric)); - if ((!x && x !== 0) || (!y && y !== 0) || (!size && size !== 0)) { + if (x === undefined || y === undefined || size === undefined) { return undefined; } 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 e8961d51ac7..e47f720209e 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 @@ -102,7 +102,7 @@ const ISSUES_METRICS = [ ]; export const populateDomainsFromMeasures = memoize( - (measures: MeasureEnhanced[], isLegacy?: boolean): Domain[] => { + (measures: MeasureEnhanced[], isLegacy = false): Domain[] => { let populatedMeasures = measures .filter((measure) => !DEPRECATED_METRICS.includes(measure.metric.key as MetricKey)) .map((measure) => { diff --git a/server/sonar-web/src/main/js/apps/overview/branches/BranchOverview.tsx b/server/sonar-web/src/main/js/apps/overview/branches/BranchOverview.tsx index b340d736035..e7834509ce4 100644 --- a/server/sonar-web/src/main/js/apps/overview/branches/BranchOverview.tsx +++ b/server/sonar-web/src/main/js/apps/overview/branches/BranchOverview.tsx @@ -54,18 +54,6 @@ import '../styles.css'; import { BRANCH_OVERVIEW_METRICS, HISTORY_METRICS_LIST, Status } from '../utils'; import BranchOverviewRenderer from './BranchOverviewRenderer'; -// TODO: remove this once backend ready -const NEW_METRICS = [ - MetricKey.software_quality_maintainability_rating, - MetricKey.software_quality_security_rating, - MetricKey.new_software_quality_security_rating, - MetricKey.software_quality_reliability_rating, - MetricKey.new_software_quality_reliability_rating, - MetricKey.software_quality_security_review_rating, - MetricKey.new_software_quality_security_review_rating, - MetricKey.new_software_quality_maintainability_rating, -]; - interface Props { branch?: Branch; branchesEnabled?: boolean; @@ -118,13 +106,12 @@ export default function BranchOverview(props: Readonly) { componentKey: component.key, branchLike: branch, metricKeys: - component.qualifier === ComponentQualifier.Project - ? projectQualityGateStatus?.conditions !== undefined - ? uniq([ - ...BRANCH_OVERVIEW_METRICS, - ...projectQualityGateStatus.conditions.map((c) => c.metricKey), - ]) - : BRANCH_OVERVIEW_METRICS + component.qualifier === ComponentQualifier.Project && + projectQualityGateStatus?.conditions !== undefined + ? uniq([ + ...BRANCH_OVERVIEW_METRICS, + ...projectQualityGateStatus.conditions.map((c) => c.metricKey), + ]) : BRANCH_OVERVIEW_METRICS, }); @@ -161,7 +148,7 @@ export default function BranchOverview(props: Readonly) { // We also need to load the application leak periods separately. getApplicationLeak(component.key, appBranchName).then( (leaks) => { - if (leaks && leaks.length) { + if (leaks && leaks.length > 0) { const sortedLeaks = sortBy(leaks, (leak) => { return new Date(leak.date); }); @@ -282,11 +269,7 @@ export default function BranchOverview(props: Readonly) { ) => { return getMeasuresWithPeriodAndMetrics( componentKey, - metricKeys.length > 0 - ? metricKeys - : BRANCH_OVERVIEW_METRICS.filter( - (metricKey) => !NEW_METRICS.includes(metricKey as MetricKey), - ), + metricKeys.length > 0 ? metricKeys : BRANCH_OVERVIEW_METRICS, getBranchLikeQuery(branchLike), ).then(({ component: { measures }, metrics, period }) => { return { diff --git a/server/sonar-web/src/main/js/apps/projects/query.ts b/server/sonar-web/src/main/js/apps/projects/query.ts index d8a80c99761..0a6edbb1563 100644 --- a/server/sonar-web/src/main/js/apps/projects/query.ts +++ b/server/sonar-web/src/main/js/apps/projects/query.ts @@ -235,7 +235,7 @@ function convertSize(metric: string, size: number): string { } } -function mapPropertyToMetric(property?: string, isLegacy: boolean = false): string | undefined { +function mapPropertyToMetric(property?: string, isLegacy = false): string | undefined { return property && (isLegacy ? propertyToMetricMapLegacy : propertyToMetricMap)[property]; } diff --git a/server/sonar-web/src/main/js/helpers/activity-graph.ts b/server/sonar-web/src/main/js/helpers/activity-graph.ts index d9472f69ad2..6d7ebd1b895 100644 --- a/server/sonar-web/src/main/js/helpers/activity-graph.ts +++ b/server/sonar-web/src/main/js/helpers/activity-graph.ts @@ -25,7 +25,7 @@ import { SOFTWARE_QUALITY_RATING_METRICS_MAP } from './constants'; export const mergeRatingMeasureHistory = ( historyData: TimeMachineResponse | undefined, parseDateFn: (date: string) => Date, - isLegacy: boolean = false, + isLegacy = false, ) => { const softwareQualityMeasures = Object.values(SOFTWARE_QUALITY_RATING_METRICS_MAP); const softwareQualityMeasuresMap = new Map< -- 2.39.5