diff options
Diffstat (limited to 'server/sonar-web/src/main/js/helpers/measures.js')
-rw-r--r-- | server/sonar-web/src/main/js/helpers/measures.js | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/server/sonar-web/src/main/js/helpers/measures.js b/server/sonar-web/src/main/js/helpers/measures.js index 0a66ef903b7..bf6df21284a 100644 --- a/server/sonar-web/src/main/js/helpers/measures.js +++ b/server/sonar-web/src/main/js/helpers/measures.js @@ -80,6 +80,39 @@ export function getShortType (type) { return type; } +/** + * Map metrics + * @param {Array} measures + * @param {Array} metrics + * @returns {Array} + */ +export function enhanceMeasuresWithMetrics (measures, metrics) { + return measures.map(measure => { + const metric = metrics.find(metric => metric.key === measure.metric); + return { ...measure, metric }; + }); +} + +/** + * Get period value of a measure + * @param measure + * @param periodIndex + */ +export function getPeriodValue (measure, periodIndex) { + const { periods } = measure; + const period = periods.find(period => period.index === periodIndex); + return period ? period.value : null; +} + +/** + * Check if metric is differential + * @param {string} metricKey + * @returns {boolean} + */ +export function isDiffMetric (metricKey) { + return metricKey.indexOf('new_') === 0; +} + /* * Helpers */ |