Commit 58ae16f9 authored by Ezekiel Kigbo's avatar Ezekiel Kigbo

Refactor prepare time metrics function

Moves the function to a separate utility and
adds some specs
parent 1b486454
......@@ -2,9 +2,8 @@
import Api from 'ee/api';
import { __, s__ } from '~/locale';
import createFlash from '~/flash';
import { slugify } from '~/lib/utils/text_utility';
import MetricCard from '../../shared/components/metric_card.vue';
import { removeFlash } from '../utils';
import { removeFlash, prepareTimeMetricsData } from '../utils';
const I18N_TEXT = {
'lead-time': s__('ValueStreamAnalytics|Median time from issue created to issue closed.'),
......@@ -47,15 +46,7 @@ export default {
this.loading = true;
return Api.cycleAnalyticsTimeSummaryData(this.groupPath, this.additionalParams)
.then(({ data }) => {
this.data = data.map(({ title: label, ...rest }) => {
const key = slugify(label);
return {
...rest,
label,
key,
tooltipText: I18N_TEXT[key] || '',
};
});
this.data = prepareTimeMetricsData(data, I18N_TEXT);
})
.catch(() => {
createFlash(
......
......@@ -3,7 +3,7 @@ import dateFormat from 'dateformat';
import { s__, sprintf } from '~/locale';
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
import httpStatus from '~/lib/utils/http_status';
import { convertToSnakeCase } from '~/lib/utils/text_utility';
import { convertToSnakeCase, slugify } from '~/lib/utils/text_utility';
import { hideFlash } from '~/flash';
import {
newDate,
......@@ -378,3 +378,14 @@ export const transformStagesForPathNavigation = ({ stages, medians, selectedStag
stage.title === CAPITALIZED_STAGE_NAME.OVERVIEW ? 0 : 1,
);
};
export const prepareTimeMetricsData = (data = [], tooltipText = {}) =>
data.map(({ title: label, ...rest }) => {
const key = slugify(label);
return {
...rest,
label,
key,
tooltipText: tooltipText[key] || '',
};
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment