aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/apps/projectActivity/utils.js
diff options
context:
space:
mode:
authorGrégoire Aubert <gregoire.aubert@sonarsource.com>2017-06-23 17:34:10 +0200
committerGrégoire Aubert <gregoire.aubert@sonarsource.com>2017-07-04 14:15:34 +0200
commit3a604bda9aa574c291f764ca8791b9af91d66a67 (patch)
tree4e92e74a1c5fb3d9fa9c483fb3fb1b742b45ce68 /server/sonar-web/src/main/js/apps/projectActivity/utils.js
parent21cdccf048db95fdeae2bf7046c2f2d830d172f5 (diff)
downloadsonarqube-3a604bda9aa574c291f764ca8791b9af91d66a67.tar.gz
sonarqube-3a604bda9aa574c291f764ca8791b9af91d66a67.zip
SONAR-9414 Display a preview of the project activity graph on the project page
Diffstat (limited to 'server/sonar-web/src/main/js/apps/projectActivity/utils.js')
-rw-r--r--server/sonar-web/src/main/js/apps/projectActivity/utils.js42
1 files changed, 38 insertions, 4 deletions
diff --git a/server/sonar-web/src/main/js/apps/projectActivity/utils.js b/server/sonar-web/src/main/js/apps/projectActivity/utils.js
index 70447874ed1..2c0c3c818bc 100644
--- a/server/sonar-web/src/main/js/apps/projectActivity/utils.js
+++ b/server/sonar-web/src/main/js/apps/projectActivity/utils.js
@@ -19,6 +19,7 @@
*/
// @flow
import moment from 'moment';
+import { sortBy } from 'lodash';
import {
cleanQuery,
parseAsDate,
@@ -29,6 +30,7 @@ import {
import { translate } from '../../helpers/l10n';
import type { Analysis, MeasureHistory, Query } from './types';
import type { RawQuery } from '../../helpers/query';
+import type { Serie } from '../../components/charts/AdvancedTimeline';
export const EVENT_TYPES = ['VERSION', 'QUALITY_GATE', 'QUALITY_PROFILE', 'OTHER'];
export const GRAPH_TYPES = ['overview', 'coverage', 'duplications', 'remediation'];
@@ -69,6 +71,30 @@ export const generateCoveredLinesMetric = (
};
};
+export const generateSeries = (
+ measuresHistory: Array<MeasureHistory>,
+ graph: string,
+ dataType: string
+): Array<Serie> =>
+ measuresHistory.map(measure => {
+ if (measure.metric === 'uncovered_lines') {
+ return generateCoveredLinesMetric(
+ measure,
+ measuresHistory,
+ GRAPHS_METRICS[graph].indexOf(measure.metric)
+ );
+ }
+ return {
+ name: measure.metric,
+ translatedName: translate('metric', measure.metric, 'name'),
+ style: GRAPHS_METRICS[graph].indexOf(measure.metric),
+ data: measure.history.map(analysis => ({
+ x: analysis.date,
+ y: dataType === 'LEVEL' ? analysis.value : Number(analysis.value)
+ }))
+ };
+ });
+
export const getAnalysesByVersionByDay = (
analyses: Array<Analysis>
): Array<{
@@ -84,10 +110,18 @@ export const getAnalysesByVersionByDay = (
if (!currentVersion.byDay[day]) {
currentVersion.byDay[day] = [];
}
- currentVersion.byDay[day].push(analysis);
- const versionEvent = analysis.events.find(event => event.category === 'VERSION');
- if (versionEvent) {
- currentVersion.version = versionEvent.name;
+ const sortedEvents = sortBy(
+ analysis.events,
+ // versions last
+ event => (event.category === 'VERSION' ? 1 : 0),
+ // then the rest sorted by category
+ 'category'
+ );
+ currentVersion.byDay[day].push({ ...analysis, events: sortedEvents });
+
+ const lastEvent = sortedEvents[sortedEvents.length - 1];
+ if (lastEvent && lastEvent.category === 'VERSION') {
+ currentVersion.version = lastEvent.name;
acc.push({ version: undefined, byDay: {} });
}
return acc;