]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7963 Display duplications on new code (#1148)
authorStas Vilchik <vilchiks@gmail.com>
Wed, 17 Aug 2016 08:58:16 +0000 (10:58 +0200)
committerGitHub <noreply@github.com>
Wed, 17 Aug 2016 08:58:16 +0000 (10:58 +0200)
server/sonar-web/src/main/js/apps/component-measures/config/complementary.js
server/sonar-web/src/main/js/apps/overview/components/OverviewApp.js
server/sonar-web/src/main/js/apps/overview/main/Duplications.js
sonar-core/src/main/resources/org/sonar/l10n/core.properties

index e11d3d8e3e5285c2efef237518f475aeecc8949f..b33de901b5f530e88cc7c3fb4115123d88774fcf 100644 (file)
@@ -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']
 };
index c5f1859f6b0278a520ab342374a679064795cc32..2c65059b388ecfd51f7f19d213cbceee0047e1b4 100644 (file)
@@ -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 = [
index 06d9c1139422459f03f68714cb96befa890839d7..7c1c564bb656366a37621248bd95146de48467d0 100644 (file)
  * 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 ? (
+        <div>
+          <DrilldownLink
+              component={component.key}
+              metric={newDuplicationsMeasure.metric.key}
+              period={leakPeriod.index}>
+            <span className="js-overview-main-new-duplications">
+              {formatMeasure(newDuplicationsValue, 'PERCENT')}
+            </span>
+          </DrilldownLink>
+        </div>
+    ) : (
+        <span>—</span>
+    );
+
+    const label = newLinesValue != null ? (
+        <div className="overview-domain-measure-label">
+          {translate('overview.duplications_on')}
+          <br/>
+          <DrilldownLink
+              className="spacer-right overview-domain-secondary-measure-value"
+              component={component.key}
+              metric={newLinesMeasure.metric.key}
+              period={leakPeriod.index}>
+            <span className="js-overview-main-new-lines">
+              {formatMeasure(newLinesValue, 'SHORT_INT')}
+            </span>
+          </DrilldownLink>
+          {getMetricName('new_lines')}
+        </div>
+    ) : (
+        <div className="overview-domain-measure-label">
+          {getMetricName('new_duplications')}
+        </div>
+    );
+
+    return (
+        <div className="overview-domain-measure">
+          <div className="overview-domain-measure-value">
+            {formattedValue}
+          </div>
+          {label}
+        </div>
+    );
+  }
+
   renderNutshell () {
     return (
         <div className="overview-domain-nutshell">
@@ -92,14 +149,10 @@ class Duplications extends React.Component {
       return null;
     }
 
-    const measure = this.props.renderMeasureVariation(
-        'duplicated_lines_density',
-        getMetricName('duplications'));
-
     return (
         <div className="overview-domain-leak">
           <div className="overview-domain-measures">
-            {measure}
+            {this.renderNewDuplications()}
           </div>
 
           {this.renderTimeline('after')}
index 23a7512cc87278f8fdebf00e71461efab3d9b83c..bd87b30126a50459d8abfe6c925b5793b8e5a3d1 100644 (file)
@@ -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