/* * SonarQube * Copyright (C) 2009-2023 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 { DrilldownLink, GreySeparator, LightLabel, LightPrimary } from 'design-system'; import * as React from 'react'; import { getLeakValue } from '../../../components/measure/utils'; import { isPullRequest } from '../../../helpers/branch-like'; import { getLocalizedMetricName, translate, translateWithParameters } from '../../../helpers/l10n'; import { findMeasure, formatMeasure, localizeMetric } from '../../../helpers/measures'; import { getComponentDrilldownUrl } from '../../../helpers/urls'; import { BranchLike } from '../../../types/branch-like'; import { MetricKey, MetricType } from '../../../types/metrics'; import { Component, MeasureEnhanced } from '../../../types/types'; import AfterMergeEstimate from '../pullRequests/AfterMergeEstimate'; import { MeasurementType, getMeasurementMetricKey } from '../utils'; import DrilldownMeasureValue from './DrilldownMeasureValue'; import MeasuresPanelCard from './MeasuresPanelCard'; import MeasuresPanelPercentMeasureLabel from './MeasuresPanelPercentMeasureLabel'; interface Props { branchLike?: BranchLike; component: Component; useDiffMetric: boolean; measures: MeasureEnhanced[]; ratingIcon: (value: string | undefined) => React.ReactElement; secondaryMetricKey?: MetricKey; type: MeasurementType; } export default function MeasuresPanelPercentMeasure(props: Props) { const { branchLike, component, measures, ratingIcon, secondaryMetricKey, type, useDiffMetric = false, } = props; const metricKey = getMeasurementMetricKey(type, useDiffMetric); const measure = findMeasure(measures, metricKey); let value; if (measure) { value = useDiffMetric ? getLeakValue(measure) : measure.value; } const url = getComponentDrilldownUrl({ componentKey: component.key, metric: metricKey, branchLike, listView: true, }); const formattedValue = formatMeasure(value, MetricType.Percent, { decimals: 2, omitExtraDecimalZeros: true, }); return ( {translate('overview.measurement_type', type)}} rating={ratingIcon(value)} > <>
{value === undefined ? ( ) : ( {formattedValue} )} {translate('overview.measurement_type', type)}
{!useDiffMetric && secondaryMetricKey && ( <>
{getLocalizedMetricName({ key: secondaryMetricKey })}
)} {isPullRequest(branchLike) && (
{translate('component_measures.facet_category.overall_category.estimated')}
)}
); }