From cb5bb2fb084e1a00fa6b1beb03343f26ce1d6f2d Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Wed, 17 Aug 2016 10:58:16 +0200 Subject: [PATCH] SONAR-7963 Display duplications on new code (#1148) --- .../config/complementary.js | 4 +- .../apps/overview/components/OverviewApp.js | 4 +- .../js/apps/overview/main/Duplications.js | 67 +++++++++++++++++-- .../resources/org/sonar/l10n/core.properties | 3 + 4 files changed, 69 insertions(+), 9 deletions(-) diff --git a/server/sonar-web/src/main/js/apps/component-measures/config/complementary.js b/server/sonar-web/src/main/js/apps/component-measures/config/complementary.js index e11d3d8e3e5..b33de901b5f 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/config/complementary.js +++ b/server/sonar-web/src/main/js/apps/component-measures/config/complementary.js @@ -55,5 +55,7 @@ export default { 'new_it_uncovered_conditions': ['new_it_branch_coverage'], 'duplicated_lines_density': ['duplicated_lines'], - 'duplicated_lines': ['duplicated_lines_density'] + 'new_duplicated_lines_density': ['new_duplicated_lines'], + 'duplicated_lines': ['duplicated_lines_density'], + 'new_duplicated_lines': ['new_duplicated_lines_density'] }; diff --git a/server/sonar-web/src/main/js/apps/overview/components/OverviewApp.js b/server/sonar-web/src/main/js/apps/overview/components/OverviewApp.js index c5f1859f6b0..2c65059b388 100644 --- a/server/sonar-web/src/main/js/apps/overview/components/OverviewApp.js +++ b/server/sonar-web/src/main/js/apps/overview/components/OverviewApp.js @@ -70,11 +70,13 @@ const METRICS = [ // duplications 'duplicated_lines_density', + 'new_duplicated_lines_density', 'duplicated_blocks', // size 'ncloc', - 'ncloc_language_distribution' + 'ncloc_language_distribution', + 'new_lines' ]; const HISTORY_METRICS_LIST = [ diff --git a/server/sonar-web/src/main/js/apps/overview/main/Duplications.js b/server/sonar-web/src/main/js/apps/overview/main/Duplications.js index 06d9c113942..7c1c564bb65 100644 --- a/server/sonar-web/src/main/js/apps/overview/main/Duplications.js +++ b/server/sonar-web/src/main/js/apps/overview/main/Duplications.js @@ -18,11 +18,10 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import React from 'react'; - import enhance from './enhance'; import { DrilldownLink } from '../../../components/shared/drilldown-link'; import { getMetricName } from '../helpers/metrics'; -import { formatMeasure } from '../../../helpers/measures'; +import { formatMeasure, getPeriodValue } from '../../../helpers/measures'; import { translate } from '../../../helpers/l10n'; class Duplications extends React.Component { @@ -72,6 +71,64 @@ class Duplications extends React.Component { ); } + renderNewDuplications () { + const { component, measures, leakPeriod } = this.props; + const newDuplicationsMeasure = measures + .find(measure => measure.metric.key === 'new_duplicated_lines_density'); + const newLinesMeasure = measures + .find(measure => measure.metric.key === 'new_lines'); + + const newDuplicationsValue = newDuplicationsMeasure ? + getPeriodValue(newDuplicationsMeasure, leakPeriod.index) : null; + const newLinesValue = newLinesMeasure ? + getPeriodValue(newLinesMeasure, leakPeriod.index) : null; + + const formattedValue = newDuplicationsValue != null ? ( +
+ + + {formatMeasure(newDuplicationsValue, 'PERCENT')} + + +
+ ) : ( + — + ); + + const label = newLinesValue != null ? ( +
+ {translate('overview.duplications_on')} +
+ + + {formatMeasure(newLinesValue, 'SHORT_INT')} + + + {getMetricName('new_lines')} +
+ ) : ( +
+ {getMetricName('new_duplications')} +
+ ); + + return ( +
+
+ {formattedValue} +
+ {label} +
+ ); + } + renderNutshell () { return (
@@ -92,14 +149,10 @@ class Duplications extends React.Component { return null; } - const measure = this.props.renderMeasureVariation( - 'duplicated_lines_density', - getMetricName('duplications')); - return (
- {measure} + {this.renderNewDuplications()}
{this.renderTimeline('after')} diff --git a/sonar-core/src/main/resources/org/sonar/l10n/core.properties b/sonar-core/src/main/resources/org/sonar/l10n/core.properties index 23a7512cc87..bd87b30126a 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -3014,10 +3014,13 @@ overview.metric.tests=Tests overview.metric.new_coverage=Coverage on New Code overview.metric.duplications=Duplications overview.metric.duplicated_blocks=Duplicated Blocks +overview.metric.new_duplications=Duplications on New Code overview.metric.ncloc=Lines of Code +overview.metric.new_lines=New Lines overview.metric.new_lines_to_cover=New Lines to Cover overview.metric.files=Files overview.coverage_on=Coverage on +overview.duplications_on=Duplications on overview.period.previous_version=since {0} overview.period.previous_version_only_date=since previous version -- 2.39.5