]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9403 Fix metric translation for plugins metrics on project activity page
authorGrégoire Aubert <gregoire.aubert@sonarsource.com>
Tue, 18 Jul 2017 08:58:50 +0000 (10:58 +0200)
committerGrégoire Aubert <gregoire.aubert@sonarsource.com>
Tue, 18 Jul 2017 09:50:43 +0000 (11:50 +0200)
server/sonar-web/src/main/js/apps/overview/events/PreviewGraphTooltips.js
server/sonar-web/src/main/js/apps/overview/events/__tests__/PreviewGraphTooltips-test.js
server/sonar-web/src/main/js/apps/overview/events/__tests__/__snapshots__/PreviewGraphTooltips-test.js.snap
server/sonar-web/src/main/js/apps/projectActivity/components/GraphsLegendCustom.js
server/sonar-web/src/main/js/apps/projectActivity/components/GraphsTooltips.js
server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityAppContainer.js
server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/__snapshots__/GraphsTooltips-test.js.snap
server/sonar-web/src/main/js/apps/projectActivity/components/forms/AddGraphMetric.js

index 982320a3a7c42d382f257496e6698883afc239d6..3ee599225747663874dc594c8b803d148b8ab9d2 100644 (file)
@@ -21,6 +21,7 @@ import React from 'react';
 import BubblePopup from '../../../components/common/BubblePopup';
 import FormattedDate from '../../../components/ui/FormattedDate';
 import PreviewGraphTooltipsContent from './PreviewGraphTooltipsContent';
+import { getLocalizedMetricName } from '../../../helpers/l10n';
 import type { Metric } from '../types';
 import type { Serie } from '../../../components/charts/AdvancedTimeline';
 
@@ -68,7 +69,7 @@ export default class PreviewGraphTooltips extends React.PureComponent {
                   <PreviewGraphTooltipsContent
                     key={serie.name}
                     serie={serie}
-                    translatedName={metric && metric.custom ? metric.name : serie.translatedName}
+                    translatedName={metric ? getLocalizedMetricName(metric) : serie.translatedName}
                     value={this.props.formatValue(point.y)}
                   />
                 );
index 10a9a0864cbfe6c6cc0db5be06cd9a8172f5dc4c..1b37aaf36911e2d70a16c8d2a04867e7db6211a5 100644 (file)
@@ -24,7 +24,6 @@ import PreviewGraphTooltips from '../PreviewGraphTooltips';
 const SERIES_OVERVIEW = [
   {
     name: 'code_smells',
-    translatedName: 'Code Smells',
     style: 1,
     data: [
       {
@@ -39,7 +38,6 @@ const SERIES_OVERVIEW = [
   },
   {
     name: 'bugs',
-    translatedName: 'Bugs',
     style: 0,
     data: [
       {
@@ -54,7 +52,6 @@ const SERIES_OVERVIEW = [
   },
   {
     name: 'vulnerabilities',
-    translatedName: 'Vulnerabilities',
     style: 2,
     data: [
       {
@@ -70,6 +67,7 @@ const SERIES_OVERVIEW = [
 ];
 
 const METRICS = [
+  { key: 'code_smells', name: 'Code Smells', type: 'INT' },
   { key: 'bugs', name: 'Bugs', type: 'INT' },
   { key: 'vulnerabilities', name: 'Vulnerabilities', type: 'INT', custom: true }
 ];
index e8090585551aeb0d72551f978243541dbca45b47..455d71d0124a3116386c22eb7f3a20f535910d99 100644 (file)
@@ -41,7 +41,6 @@ exports[`should render correctly 1`] = `
               ],
               "name": "code_smells",
               "style": 1,
-              "translatedName": "Code Smells",
             }
           }
           translatedName="Code Smells"
@@ -62,7 +61,6 @@ exports[`should render correctly 1`] = `
               ],
               "name": "bugs",
               "style": 0,
-              "translatedName": "Bugs",
             }
           }
           translatedName="Bugs"
@@ -83,7 +81,6 @@ exports[`should render correctly 1`] = `
               ],
               "name": "vulnerabilities",
               "style": 2,
-              "translatedName": "Vulnerabilities",
             }
           }
           translatedName="Vulnerabilities"
index 540bb65961aab6724dbe368bfb017fd507e69336..72e4009e40177dc7c6253ff771c4dd471b9c4f45 100644 (file)
@@ -21,13 +21,14 @@ import React from 'react';
 import GraphsLegendItem from './GraphsLegendItem';
 import Tooltip from '../../../components/controls/Tooltip';
 import { hasDataValues } from '../utils';
-import { translate } from '../../../helpers/l10n';
+import { getLocalizedMetricName, translate } from '../../../helpers/l10n';
 import type { Metric } from '../types';
+import type { Serie } from '../../../components/charts/AdvancedTimeline';
 
 type Props = {
   metrics: Array<Metric>,
   removeMetric: string => void,
-  series: Array<{ name: string, translatedName: string, style: string }>
+  series: Array<Serie & { translatedName: string }>
 };
 
 export default function GraphsLegendCustom({ metrics, removeMetric, series }: Props) {
@@ -39,7 +40,7 @@ export default function GraphsLegendCustom({ metrics, removeMetric, series }: Pr
         const legendItem = (
           <GraphsLegendItem
             metric={serie.name}
-            name={metric && metric.custom ? metric.name : serie.translatedName}
+            name={metric ? getLocalizedMetricName(metric) : serie.translatedName}
             showWarning={!hasData}
             style={serie.style}
             removeMetric={removeMetric}
index d4b13addd4a2b8794d1b313de0efc11a9e1bcb26..43dd36a23236df9ddb2650e4017109f7eb2c6a71 100644 (file)
@@ -26,6 +26,7 @@ import GraphsTooltipsContentEvents from './GraphsTooltipsContentEvents';
 import GraphsTooltipsContentCoverage from './GraphsTooltipsContentCoverage';
 import GraphsTooltipsContentDuplication from './GraphsTooltipsContentDuplication';
 import GraphsTooltipsContentOverview from './GraphsTooltipsContentOverview';
+import { getLocalizedMetricName } from '../../../helpers/l10n';
 import type { Event, MeasureHistory, Metric } from '../types';
 import type { Serie } from '../../../components/charts/AdvancedTimeline';
 
@@ -85,7 +86,9 @@ export default class GraphsTooltips extends React.PureComponent {
                     <GraphsTooltipsContent
                       key={serie.name}
                       serie={serie}
-                      translatedName={metric && metric.custom ? metric.name : serie.translatedName}
+                      translatedName={
+                        metric ? getLocalizedMetricName(metric) : serie.translatedName
+                      }
                       value={this.props.formatValue(point.y)}
                     />
                   );
index dd3b3690c07ce559922a0fee2eaa3f4a246de988..035693ad5999e530a2f9c31ab4297a73056dc45f 100644 (file)
@@ -213,34 +213,32 @@ class ProjectActivityAppContainer extends React.PureComponent {
       ignoreHistory ? Promise.resolve() : this.fetchMeasuresHistory(graphMetrics)
     ]).then(response => {
       if (this.mounted) {
-        setTimeout(() => {
-          const newState = {
-            analyses: response[0].analyses,
-            analysesLoading: true,
-            loading: false,
-            metrics: response[1],
-            paging: response[0].paging
-          };
-          if (ignoreHistory) {
-            this.setState(newState);
-          } else {
+        const newState = {
+          analyses: response[0].analyses,
+          analysesLoading: true,
+          loading: false,
+          metrics: response[1],
+          paging: response[0].paging
+        };
+        if (ignoreHistory) {
+          this.setState(newState);
+        } else {
+          this.setState({
+            ...newState,
+            graphLoading: false,
+            measuresHistory: response[2]
+          });
+        }
+
+        this.loadAllActivities(query.project).then(({ analyses, paging }) => {
+          if (this.mounted) {
             this.setState({
-              ...newState,
-              graphLoading: false,
-              measuresHistory: response[2]
+              analyses,
+              analysesLoading: false,
+              paging
             });
           }
-
-          this.loadAllActivities(query.project).then(({ analyses, paging }) => {
-            if (this.mounted) {
-              this.setState({
-                analyses,
-                analysesLoading: false,
-                paging
-              });
-            }
-          });
-        }, 1000);
+        });
       }
     });
   }
index 8cc911548dca2d71f05cf6bec60e7668980a0680..ca571b58091ddd14445c9071e754c5c6187c8c88 100644 (file)
@@ -163,7 +163,7 @@ exports[`should render correctly for random graphs 1`] = `
               "translatedName": "metric.bugs.name",
             }
           }
-          translatedName="metric.bugs.name"
+          translatedName="Bugs"
           value="Formated.0"
         />
         <GraphsTooltipsContent
index 69c5a19d918cf2dd7ecb35965c9b9b03f7be795d..293af80020c2ae7e241f5076eac67ffcc4c5a659 100644 (file)
@@ -24,7 +24,11 @@ import Modal from 'react-modal';
 import Select from 'react-select';
 import Tooltip from '../../../../components/controls/Tooltip';
 import { isDiffMetric } from '../../../../helpers/measures';
-import { translate, translateWithParameters } from '../../../../helpers/l10n';
+import {
+  getLocalizedMetricName,
+  translate,
+  translateWithParameters
+} from '../../../../helpers/l10n';
 import type { Metric } from '../../types';
 
 type Props = {
@@ -67,7 +71,7 @@ export default class AddGraphMetric extends React.PureComponent {
       })
       .map((metric: Metric) => ({
         value: metric.key,
-        label: metric.custom ? metric.name : translate('metric', metric.key, 'name')
+        label: getLocalizedMetricName(metric)
       }));
   };