Commit e2b12946 authored by Scott Hampton's avatar Scott Hampton

Merge branch 'nfriend-refactoring-for-lead-time-graphs' into 'master'

Refactoring in preparation for lead time graphs

See merge request gitlab-org/gitlab!58442
parents 96d02a33 d290f0aa
...@@ -30,12 +30,16 @@ export default { ...@@ -30,12 +30,16 @@ export default {
<resizable-chart-container> <resizable-chart-container>
<gl-area-chart <gl-area-chart
slot-scope="{ width }" slot-scope="{ width }"
v-bind="$attrs"
:width="width" :width="width"
:height="$options.chartContainerHeight" :height="$options.chartContainerHeight"
:data="chartData" :data="chartData"
:include-legend-avg-max="false" :include-legend-avg-max="false"
:option="areaChartOptions" :option="areaChartOptions"
/> >
<slot slot="tooltip-title" name="tooltip-title"></slot>
<slot slot="tooltip-content" name="tooltip-content"></slot>
</gl-area-chart>
</resizable-chart-container> </resizable-chart-container>
</div> </div>
</template> </template>
...@@ -41,10 +41,14 @@ export default { ...@@ -41,10 +41,14 @@ export default {
<gl-segmented-control v-model="selectedChart" :options="chartRanges" class="gl-mb-4" /> <gl-segmented-control v-model="selectedChart" :options="chartRanges" class="gl-mb-4" />
<ci-cd-analytics-area-chart <ci-cd-analytics-area-chart
v-if="chart" v-if="chart"
v-bind="$attrs"
:chart-data="chart.data" :chart-data="chart.data"
:area-chart-options="chartOptions" :area-chart-options="chartOptions"
> >
{{ dateRange }} {{ dateRange }}
<slot slot="tooltip-title" name="tooltip-title"></slot>
<slot slot="tooltip-content" name="tooltip-content"></slot>
</ci-cd-analytics-area-chart> </ci-cd-analytics-area-chart>
</div> </div>
</template> </template>
import { s__ } from '~/locale';
/* eslint-disable @gitlab/require-i18n-strings */
export const LAST_WEEK = 'LAST_WEEK';
export const LAST_MONTH = 'LAST_MONTH';
export const LAST_90_DAYS = 'LAST_90_DAYS';
/* eslint-enable @gitlab/require-i18n-strings */
export const CHART_TITLE = s__('DeploymentFrequencyCharts|Deployments');
...@@ -5,13 +5,16 @@ import * as DoraApi from 'ee/api/dora_api'; ...@@ -5,13 +5,16 @@ import * as DoraApi from 'ee/api/dora_api';
import createFlash from '~/flash'; import createFlash from '~/flash';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import CiCdAnalyticsCharts from '~/projects/pipelines/charts/components/ci_cd_analytics_charts.vue'; import CiCdAnalyticsCharts from '~/projects/pipelines/charts/components/ci_cd_analytics_charts.vue';
import { LAST_WEEK, LAST_MONTH, LAST_90_DAYS } from './constants';
import { import {
allChartDefinitions, allChartDefinitions,
areaChartOptions, areaChartOptions,
chartDescriptionText, chartDescriptionText,
chartDocumentationHref, chartDocumentationHref,
} from './static_data'; LAST_WEEK,
LAST_MONTH,
LAST_90_DAYS,
CHART_TITLE,
} from './static_data/deployment_frequency';
import { apiDataToChartSeries } from './util'; import { apiDataToChartSeries } from './util';
export default { export default {
...@@ -53,7 +56,7 @@ export default { ...@@ -53,7 +56,7 @@ export default {
requestParams, requestParams,
); );
this.chartData[id] = apiDataToChartSeries(apiData, startDate, endDate); this.chartData[id] = apiDataToChartSeries(apiData, startDate, endDate, CHART_TITLE);
}), }),
); );
...@@ -61,9 +64,7 @@ export default { ...@@ -61,9 +64,7 @@ export default {
if (requestErrors.length) { if (requestErrors.length) {
createFlash({ createFlash({
message: s__( message: s__('DORA4Metrics|Something went wrong while getting deployment frequency data'),
'DeploymentFrequencyCharts|Something went wrong while getting deployment frequency data',
),
}); });
const allErrorMessages = requestErrors.join('\n'); const allErrorMessages = requestErrors.join('\n');
...@@ -82,7 +83,7 @@ export default { ...@@ -82,7 +83,7 @@ export default {
</script> </script>
<template> <template>
<div> <div>
<h4 class="gl-my-4">{{ s__('DeploymentFrequencyCharts|Deployments charts') }}</h4> <h4 class="gl-my-4">{{ s__('DORA4Metrics|Deployments charts') }}</h4>
<p data-testid="help-text"> <p data-testid="help-text">
<gl-sprintf :message="$options.chartDescriptionText"> <gl-sprintf :message="$options.chartDescriptionText">
<template #code="{ content }"> <template #code="{ content }">
......
import { helpPagePath } from '~/helpers/help_page_helper';
import { s__ } from '~/locale';
export * from './shared';
export const CHART_TITLE = s__('DORA4Metrics|Deployments');
export const areaChartOptions = {
xAxis: {
name: s__('DORA4Metrics|Date'),
type: 'category',
},
yAxis: {
name: s__('DORA4Metrics|Deployments'),
type: 'value',
minInterval: 1,
},
};
export const chartDescriptionText = s__(
'DORA4Metrics|These charts display the frequency of deployments to the production environment, as part of the DORA 4 metrics. The environment must be named %{codeStart}production%{codeEnd} for its data to appear in these charts.',
);
export const chartDocumentationHref = helpPagePath('user/analytics/ci_cd_analytics.html', {
anchor: 'deployment-frequency-charts',
});
import dateFormat from 'dateformat'; import dateFormat from 'dateformat';
import { helpPagePath } from '~/helpers/help_page_helper';
import { nDaysBefore, nMonthsBefore, getStartOfDay, dayAfter } from '~/lib/utils/datetime_utility'; import { nDaysBefore, nMonthsBefore, getStartOfDay, dayAfter } from '~/lib/utils/datetime_utility';
import { __, s__, sprintf } from '~/locale'; import { __, s__, sprintf } from '~/locale';
import { LAST_WEEK, LAST_MONTH, LAST_90_DAYS } from './constants';
/* eslint-disable @gitlab/require-i18n-strings */
export const LAST_WEEK = 'LAST_WEEK';
export const LAST_MONTH = 'LAST_MONTH';
export const LAST_90_DAYS = 'LAST_90_DAYS';
/* eslint-enable @gitlab/require-i18n-strings */
// Compute all relative dates based on the _beginning_ of today. // Compute all relative dates based on the _beginning_ of today.
// We use this date as the end date for the charts. This causes // We use this date as the end date for the charts. This causes
...@@ -10,7 +14,7 @@ import { LAST_WEEK, LAST_MONTH, LAST_90_DAYS } from './constants'; ...@@ -10,7 +14,7 @@ import { LAST_WEEK, LAST_MONTH, LAST_90_DAYS } from './constants';
const startOfToday = getStartOfDay(new Date(), { utc: true }); const startOfToday = getStartOfDay(new Date(), { utc: true });
// We use this date as the "to" parameter for the API. This allows // We use this date as the "to" parameter for the API. This allows
// us to get deployment information about the current day. // us to get DORA 4 metrics about the current day.
const startOfTomorrow = dayAfter(startOfToday, { utc: true }); const startOfTomorrow = dayAfter(startOfToday, { utc: true });
const lastWeek = nDaysBefore(startOfTomorrow, 7, { utc: true }); const lastWeek = nDaysBefore(startOfTomorrow, 7, { utc: true });
...@@ -31,7 +35,7 @@ export const allChartDefinitions = [ ...@@ -31,7 +35,7 @@ export const allChartDefinitions = [
{ {
id: LAST_WEEK, id: LAST_WEEK,
title: __('Last week'), title: __('Last week'),
range: sprintf(s__('DeploymentFrequencyCharts|%{startDate} - %{endDate}'), { range: sprintf(s__('DORA4Metrics|%{startDate} - %{endDate}'), {
startDate: dateFormat(lastWeek, titleDateFormatString, true), startDate: dateFormat(lastWeek, titleDateFormatString, true),
endDate: dateFormat(startOfToday, titleDateFormatString, true), endDate: dateFormat(startOfToday, titleDateFormatString, true),
}), }),
...@@ -45,7 +49,7 @@ export const allChartDefinitions = [ ...@@ -45,7 +49,7 @@ export const allChartDefinitions = [
{ {
id: LAST_MONTH, id: LAST_MONTH,
title: __('Last month'), title: __('Last month'),
range: sprintf(s__('DeploymentFrequencyCharts|%{startDate} - %{endDate}'), { range: sprintf(s__('DORA4Metrics|%{startDate} - %{endDate}'), {
startDate: dateFormat(lastMonth, titleDateFormatString, true), startDate: dateFormat(lastMonth, titleDateFormatString, true),
endDate: dateFormat(startOfToday, titleDateFormatString, true), endDate: dateFormat(startOfToday, titleDateFormatString, true),
}), }),
...@@ -59,7 +63,7 @@ export const allChartDefinitions = [ ...@@ -59,7 +63,7 @@ export const allChartDefinitions = [
{ {
id: LAST_90_DAYS, id: LAST_90_DAYS,
title: __('Last 90 days'), title: __('Last 90 days'),
range: sprintf(s__('%{startDate} - %{endDate}'), { range: sprintf(s__('DORA4Metrics|%{startDate} - %{endDate}'), {
startDate: dateFormat(last90Days, titleDateFormatString, true), startDate: dateFormat(last90Days, titleDateFormatString, true),
endDate: dateFormat(startOfToday, titleDateFormatString, true), endDate: dateFormat(startOfToday, titleDateFormatString, true),
}), }),
...@@ -71,23 +75,3 @@ export const allChartDefinitions = [ ...@@ -71,23 +75,3 @@ export const allChartDefinitions = [
}, },
}, },
]; ];
export const areaChartOptions = {
xAxis: {
name: s__('DeploymentFrequencyCharts|Date'),
type: 'category',
},
yAxis: {
name: s__('DeploymentFrequencyCharts|Deployments'),
type: 'value',
minInterval: 1,
},
};
export const chartDescriptionText = s__(
'DeploymentFrequencyCharts|These charts display the frequency of deployments to the production environment, as part of the DORA 4 metrics. The environment must be named %{codeStart}production%{codeEnd} for its data to appear in these charts.',
);
export const chartDocumentationHref = helpPagePath('user/analytics/ci_cd_analytics.html', {
anchor: 'deployment-frequency-charts',
});
import dateFormat from 'dateformat'; import dateFormat from 'dateformat';
import { getDatesInRange, nDaysBefore, getStartOfDay } from '~/lib/utils/datetime_utility'; import { getDatesInRange, nDaysBefore, getStartOfDay } from '~/lib/utils/datetime_utility';
import { CHART_TITLE } from './constants';
/** /**
* Converts the raw data fetched from the * Converts the raw data fetched from the
* [Deployment Frequency API](https://docs.gitlab.com/ee/api/project_analytics.html#list-project-deployment-frequencies) * [DORA Metrics API](https://docs.gitlab.com/ee/api/dora/metrics.html#get-project-level-dora-metrics)
* into series data consumable by * into series data consumable by
* [GlAreaChart](https://gitlab-org.gitlab.io/gitlab-ui/?path=/story/charts-area-chart--default) * [GlAreaChart](https://gitlab-org.gitlab.io/gitlab-ui/?path=/story/charts-area-chart--default)
* *
* @param {Array} apiData The raw JSON data from the API request * @param {Array} apiData The raw JSON data from the API request
* @param {Date} startDate The first day (inclusive) of the graph's date range * @param {Date} startDate The first day (inclusive) of the graph's date range
* @param {Date} endDate The last day (exclusive) of the graph's date range * @param {Date} endDate The last day (exclusive) of the graph's date range
* @param {String} seriesName The name of the series
* @param {*} emptyValue The value to substitute if the API data doesn't
* include data for a particular date
*/ */
export const apiDataToChartSeries = (apiData, startDate, endDate) => { export const apiDataToChartSeries = (apiData, startDate, endDate, seriesName, emptyValue = 0) => {
// Get a list of dates, one date per day in the graph's date range // Get a list of dates, one date per day in the graph's date range
const beginningOfStartDate = getStartOfDay(startDate, { utc: true }); const beginningOfStartDate = getStartOfDay(startDate, { utc: true });
const beginningOfEndDate = nDaysBefore(getStartOfDay(endDate, { utc: true }), 1, { utc: true }); const beginningOfEndDate = nDaysBefore(getStartOfDay(endDate, { utc: true }), 1, { utc: true });
...@@ -29,16 +31,16 @@ export const apiDataToChartSeries = (apiData, startDate, endDate) => { ...@@ -29,16 +31,16 @@ export const apiDataToChartSeries = (apiData, startDate, endDate) => {
return acc; return acc;
}, {}); }, {});
// Fill in the API data (the API data doesn't included data points for // Fill in the API data (the API may exclude data points for dates that have no data)
// days with 0 deployments) and transform it for use in the graph // and transform it for use in the graph
const data = dates.map((date) => { const data = dates.map((date) => {
const formattedDate = dateFormat(date, 'mmm d', true); const formattedDate = dateFormat(date, 'mmm d', true);
return [formattedDate, timestampToApiValue[date.getTime()] || 0]; return [formattedDate, timestampToApiValue[date.getTime()] ?? emptyValue];
}); });
return [ return [
{ {
name: CHART_TITLE, name: seriesName,
data, data,
}, },
]; ];
......
...@@ -14,10 +14,11 @@ describe('ee/projects/pipelines/charts/components/util.js', () => { ...@@ -14,10 +14,11 @@ describe('ee/projects/pipelines/charts/components/util.js', () => {
const startDate = new Date(2015, 5, 26, 10); const startDate = new Date(2015, 5, 26, 10);
const endDate = new Date(2015, 6, 4, 10); const endDate = new Date(2015, 6, 4, 10);
const chartTitle = 'Chart title';
const expected = [ const expected = [
{ {
name: 'Deployments', name: chartTitle,
data: [ data: [
['Jun 26', 0], ['Jun 26', 0],
['Jun 27', 0], ['Jun 27', 0],
...@@ -31,7 +32,7 @@ describe('ee/projects/pipelines/charts/components/util.js', () => { ...@@ -31,7 +32,7 @@ describe('ee/projects/pipelines/charts/components/util.js', () => {
}, },
]; ];
expect(apiDataToChartSeries(apiData, startDate, endDate)).toEqual(expected); expect(apiDataToChartSeries(apiData, startDate, endDate, chartTitle)).toEqual(expected);
}); });
}); });
}); });
...@@ -817,9 +817,6 @@ msgstr "" ...@@ -817,9 +817,6 @@ msgstr ""
msgid "%{spanStart}in%{spanEnd} %{errorFn}" msgid "%{spanStart}in%{spanEnd} %{errorFn}"
msgstr "" msgstr ""
msgid "%{startDate} - %{endDate}"
msgstr ""
msgid "%{start} to %{end}" msgid "%{start} to %{end}"
msgstr "" msgstr ""
...@@ -9609,6 +9606,24 @@ msgstr "" ...@@ -9609,6 +9606,24 @@ msgstr ""
msgid "DNS" msgid "DNS"
msgstr "" msgstr ""
msgid "DORA4Metrics|%{startDate} - %{endDate}"
msgstr ""
msgid "DORA4Metrics|Date"
msgstr ""
msgid "DORA4Metrics|Deployments"
msgstr ""
msgid "DORA4Metrics|Deployments charts"
msgstr ""
msgid "DORA4Metrics|Something went wrong while getting deployment frequency data"
msgstr ""
msgid "DORA4Metrics|These charts display the frequency of deployments to the production environment, as part of the DORA 4 metrics. The environment must be named %{codeStart}production%{codeEnd} for its data to appear in these charts."
msgstr ""
msgid "Dashboard" msgid "Dashboard"
msgstr "" msgstr ""
...@@ -10595,24 +10610,6 @@ msgstr "" ...@@ -10595,24 +10610,6 @@ msgstr ""
msgid "Deployment Frequency" msgid "Deployment Frequency"
msgstr "" msgstr ""
msgid "DeploymentFrequencyCharts|%{startDate} - %{endDate}"
msgstr ""
msgid "DeploymentFrequencyCharts|Date"
msgstr ""
msgid "DeploymentFrequencyCharts|Deployments"
msgstr ""
msgid "DeploymentFrequencyCharts|Deployments charts"
msgstr ""
msgid "DeploymentFrequencyCharts|Something went wrong while getting deployment frequency data"
msgstr ""
msgid "DeploymentFrequencyCharts|These charts display the frequency of deployments to the production environment, as part of the DORA 4 metrics. The environment must be named %{codeStart}production%{codeEnd} for its data to appear in these charts."
msgstr ""
msgid "Deployments" msgid "Deployments"
msgstr "" msgstr ""
......
...@@ -21,7 +21,11 @@ exports[`CiCdAnalyticsAreaChart matches the snapshot 1`] = ` ...@@ -21,7 +21,11 @@ exports[`CiCdAnalyticsAreaChart matches the snapshot 1`] = `
option="[object Object]" option="[object Object]"
thresholds="" thresholds=""
width="0" width="0"
/> >
<template />
<template />
</glareachart-stub>
</div> </div>
</div> </div>
`; `;
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