diff options
author | ssjenka <ssjenka@ops-slave-fedora25-1.internal.sonarsource.com> | 2017-07-18 13:29:15 +0200 |
---|---|---|
committer | ssjenka <ssjenka@ops-slave-fedora25-1.internal.sonarsource.com> | 2017-07-18 13:29:15 +0200 |
commit | f3c05bcc9a63fd20dafe0411490265103b599179 (patch) | |
tree | f13d597f5bf7bb3fbc375592cfef8cc9e1cdf7a1 /server/sonar-web/src | |
parent | 7210cafc32b2e496c295ef37f48938fe702f97dc (diff) | |
parent | 0c7f9f2bae260585a2bbf8c149f771bdfa7ecd90 (diff) | |
download | sonarqube-f3c05bcc9a63fd20dafe0411490265103b599179.tar.gz sonarqube-f3c05bcc9a63fd20dafe0411490265103b599179.zip |
Automatic merge from branch-6.5
* origin/branch-6.5:
SONAR-9403 Display project activity custom graphs on the project dashboard too
SONAR-9403 Fix metric translation for plugins metrics on project activity page
Diffstat (limited to 'server/sonar-web/src')
10 files changed, 69 insertions, 56 deletions
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 ca6094836ef..8ca0ce8f45c 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 @@ -33,9 +33,9 @@ import { getAllTimeMachineData } from '../../../api/time-machine'; import { enhanceMeasuresWithMetrics } from '../../../helpers/measures'; import { getLeakPeriod } from '../../../helpers/periods'; import { TooltipsContainer } from '../../../components/mixins/tooltips-mixin'; -import { getGraph } from '../../../helpers/storage'; +import { getCustomGraph, getGraph } from '../../../helpers/storage'; import { METRICS, HISTORY_METRICS_LIST } from '../utils'; -import { GRAPHS_METRICS_DISPLAYED } from '../../projectActivity/utils'; +import { getDisplayedHistoryMetrics } from '../../projectActivity/utils'; import type { Component, History, MeasuresList, Period } from '../types'; import '../styles.css'; @@ -101,10 +101,11 @@ export default class OverviewApp extends React.PureComponent { } loadHistory(component: Component) { - let graphMetrics = GRAPHS_METRICS_DISPLAYED[getGraph()]; + let graphMetrics = getDisplayedHistoryMetrics(getGraph(), getCustomGraph()); if (!graphMetrics || graphMetrics.length <= 0) { - graphMetrics = GRAPHS_METRICS_DISPLAYED['overview']; + graphMetrics = getDisplayedHistoryMetrics('overview', []); } + const metrics = uniq(HISTORY_METRICS_LIST.concat(graphMetrics)); return getAllTimeMachineData(component.key, metrics).then(r => { if (this.mounted) { diff --git a/server/sonar-web/src/main/js/apps/overview/events/PreviewGraph.js b/server/sonar-web/src/main/js/apps/overview/events/PreviewGraph.js index 42817e83c1e..63424f5a6d6 100644 --- a/server/sonar-web/src/main/js/apps/overview/events/PreviewGraph.js +++ b/server/sonar-web/src/main/js/apps/overview/events/PreviewGraph.js @@ -21,10 +21,10 @@ import React from 'react'; import { minBy } from 'lodash'; import { AutoSizer } from 'react-virtualized'; -import { generateSeries, GRAPHS_METRICS_DISPLAYED } from '../../projectActivity/utils'; -import { getGraph } from '../../../helpers/storage'; import AdvancedTimeline from '../../../components/charts/AdvancedTimeline'; import PreviewGraphTooltips from './PreviewGraphTooltips'; +import { generateSeries, getDisplayedHistoryMetrics } from '../../projectActivity/utils'; +import { getCustomGraph, getGraph } from '../../../helpers/storage'; import { formatMeasure, getShortType } from '../../../helpers/measures'; import type { Serie } from '../../../components/charts/AdvancedTimeline'; import type { History, Metric } from '../types'; @@ -37,6 +37,7 @@ type Props = { }; type State = { + customMetrics: Array<string>, graph: string, metricsType: string, selectedDate: ?Date, @@ -54,12 +55,14 @@ export default class PreviewGraph extends React.PureComponent { constructor(props: Props) { super(props); const graph = getGraph(); - const metricsType = this.getMetricType(props.metrics, graph); + const customMetrics = getCustomGraph(); + const metricsType = this.getMetricType(props.metrics, graph, customMetrics); this.state = { + customMetrics, graph, metricsType, selectedDate: null, - series: this.getSeries(props.history, graph, metricsType), + series: this.getSeries(props.history, graph, customMetrics, metricsType), tooltipIdx: null, tooltipXPos: null }; @@ -68,11 +71,13 @@ export default class PreviewGraph extends React.PureComponent { componentWillReceiveProps(nextProps: Props) { if (nextProps.history !== this.props.history || nextProps.metrics !== this.props.metrics) { const graph = getGraph(); - const metricsType = this.getMetricType(nextProps.metrics, graph); + const customMetrics = getCustomGraph(); + const metricsType = this.getMetricType(nextProps.metrics, graph, customMetrics); this.setState({ + customMetrics, graph, metricsType, - series: this.getSeries(nextProps.history, graph, metricsType) + series: this.getSeries(nextProps.history, graph, customMetrics, metricsType) }); } } @@ -80,20 +85,25 @@ export default class PreviewGraph extends React.PureComponent { formatValue = (tick: number | string) => formatMeasure(tick, getShortType(this.state.metricsType)); - getDisplayedMetrics = (graph: string): Array<string> => { - const metrics: Array<string> = GRAPHS_METRICS_DISPLAYED[graph]; + getDisplayedMetrics = (graph: string, customMetrics: Array<string>): Array<string> => { + const metrics: Array<string> = getDisplayedHistoryMetrics(graph, customMetrics); if (!metrics || metrics.length <= 0) { - return GRAPHS_METRICS_DISPLAYED['overview']; + return getDisplayedHistoryMetrics('overview', customMetrics); } return metrics; }; - getSeries = (history: ?History, graph: string, metricsType: string) => { + getSeries = ( + history: ?History, + graph: string, + customMetrics: Array<string>, + metricsType: string + ) => { const myHistory = history; if (!myHistory) { return []; } - const metrics = this.getDisplayedMetrics(graph); + const metrics = this.getDisplayedMetrics(graph, customMetrics); const firstValid = minBy( metrics.map(metric => myHistory[metric].find(p => p.value || p.value === 0)), 'date' @@ -107,8 +117,8 @@ export default class PreviewGraph extends React.PureComponent { return generateSeries(measureHistory, graph, metricsType, metrics); }; - getMetricType = (metrics: Array<Metric>, graph: string) => { - const metricKey = this.getDisplayedMetrics(graph)[0]; + getMetricType = (metrics: Array<Metric>, graph: string, customMetrics: Array<string>) => { + const metricKey = this.getDisplayedMetrics(graph, customMetrics)[0]; const metric = metrics.find(metric => metric.key === metricKey); return metric ? metric.type : 'INT'; }; diff --git a/server/sonar-web/src/main/js/apps/overview/events/PreviewGraphTooltips.js b/server/sonar-web/src/main/js/apps/overview/events/PreviewGraphTooltips.js index 982320a3a7c..3ee59922574 100644 --- a/server/sonar-web/src/main/js/apps/overview/events/PreviewGraphTooltips.js +++ b/server/sonar-web/src/main/js/apps/overview/events/PreviewGraphTooltips.js @@ -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)} /> ); diff --git a/server/sonar-web/src/main/js/apps/overview/events/__tests__/PreviewGraphTooltips-test.js b/server/sonar-web/src/main/js/apps/overview/events/__tests__/PreviewGraphTooltips-test.js index 10a9a0864cb..1b37aaf3691 100644 --- a/server/sonar-web/src/main/js/apps/overview/events/__tests__/PreviewGraphTooltips-test.js +++ b/server/sonar-web/src/main/js/apps/overview/events/__tests__/PreviewGraphTooltips-test.js @@ -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 } ]; diff --git a/server/sonar-web/src/main/js/apps/overview/events/__tests__/__snapshots__/PreviewGraphTooltips-test.js.snap b/server/sonar-web/src/main/js/apps/overview/events/__tests__/__snapshots__/PreviewGraphTooltips-test.js.snap index e8090585551..455d71d0124 100644 --- a/server/sonar-web/src/main/js/apps/overview/events/__tests__/__snapshots__/PreviewGraphTooltips-test.js.snap +++ b/server/sonar-web/src/main/js/apps/overview/events/__tests__/__snapshots__/PreviewGraphTooltips-test.js.snap @@ -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" diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/GraphsLegendCustom.js b/server/sonar-web/src/main/js/apps/projectActivity/components/GraphsLegendCustom.js index 540bb65961a..72e4009e401 100644 --- a/server/sonar-web/src/main/js/apps/projectActivity/components/GraphsLegendCustom.js +++ b/server/sonar-web/src/main/js/apps/projectActivity/components/GraphsLegendCustom.js @@ -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} diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/GraphsTooltips.js b/server/sonar-web/src/main/js/apps/projectActivity/components/GraphsTooltips.js index d4b13addd4a..43dd36a2323 100644 --- a/server/sonar-web/src/main/js/apps/projectActivity/components/GraphsTooltips.js +++ b/server/sonar-web/src/main/js/apps/projectActivity/components/GraphsTooltips.js @@ -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)} /> ); diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityAppContainer.js b/server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityAppContainer.js index dd3b3690c07..035693ad599 100644 --- a/server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityAppContainer.js +++ b/server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityAppContainer.js @@ -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); + }); } }); } diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/__snapshots__/GraphsTooltips-test.js.snap b/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/__snapshots__/GraphsTooltips-test.js.snap index 8cc911548dc..ca571b58091 100644 --- a/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/__snapshots__/GraphsTooltips-test.js.snap +++ b/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/__snapshots__/GraphsTooltips-test.js.snap @@ -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 diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/forms/AddGraphMetric.js b/server/sonar-web/src/main/js/apps/projectActivity/components/forms/AddGraphMetric.js index 6d75c964004..b36f79e9c44 100644 --- a/server/sonar-web/src/main/js/apps/projectActivity/components/forms/AddGraphMetric.js +++ b/server/sonar-web/src/main/js/apps/projectActivity/components/forms/AddGraphMetric.js @@ -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) })); }; |