debian-mirror-gitlab/app/assets/javascripts/projects/pipelines/charts/components/app.vue

221 lines
5.9 KiB
Vue
Raw Normal View History

2020-03-13 15:44:24 +05:30
<script>
2021-03-08 18:12:59 +05:30
import { GlAlert, GlTabs, GlTab } from '@gitlab/ui';
import { s__ } from '~/locale';
2021-02-22 17:27:13 +05:30
import getPipelineCountByStatus from '../graphql/queries/get_pipeline_count_by_status.query.graphql';
import getProjectPipelineStatistics from '../graphql/queries/get_project_pipeline_statistics.query.graphql';
2021-03-08 18:12:59 +05:30
import PipelineCharts from './pipeline_charts.vue';
2020-03-13 15:44:24 +05:30
import {
2021-02-22 17:27:13 +05:30
DEFAULT,
LOAD_ANALYTICS_FAILURE,
LOAD_PIPELINES_FAILURE,
PARSE_FAILURE,
UNSUPPORTED_DATA,
2020-03-13 15:44:24 +05:30
} from '../constants';
2021-02-22 17:27:13 +05:30
const defaultAnalyticsValues = {
weekPipelinesTotals: [],
weekPipelinesLabels: [],
weekPipelinesSuccessful: [],
monthPipelinesLabels: [],
monthPipelinesTotals: [],
monthPipelinesSuccessful: [],
yearPipelinesLabels: [],
yearPipelinesTotals: [],
yearPipelinesSuccessful: [],
pipelineTimesLabels: [],
pipelineTimesValues: [],
};
2021-03-08 18:12:59 +05:30
const defaultCountValues = {
totalPipelines: {
count: 0,
},
successfulPipelines: {
count: 0,
},
};
2020-03-13 15:44:24 +05:30
export default {
components: {
2021-02-22 17:27:13 +05:30
GlAlert,
2021-03-08 18:12:59 +05:30
GlTabs,
GlTab,
PipelineCharts,
DeploymentFrequencyCharts: () =>
import('ee_component/projects/pipelines/charts/components/deployment_frequency_charts.vue'),
2020-03-13 15:44:24 +05:30
},
2021-02-22 17:27:13 +05:30
inject: {
2021-03-08 18:12:59 +05:30
shouldRenderDeploymentFrequencyCharts: {
type: Boolean,
default: false,
},
2021-02-22 17:27:13 +05:30
projectPath: {
type: String,
default: '',
2020-03-13 15:44:24 +05:30
},
},
data() {
return {
2021-02-22 17:27:13 +05:30
showFailureAlert: false,
failureType: null,
2021-03-08 18:12:59 +05:30
analytics: { ...defaultAnalyticsValues },
counts: { ...defaultCountValues },
2020-03-13 15:44:24 +05:30
};
},
2021-02-22 17:27:13 +05:30
apollo: {
counts: {
query: getPipelineCountByStatus,
variables() {
return {
projectPath: this.projectPath,
};
},
update(data) {
return data?.project;
},
error() {
this.reportFailure(LOAD_PIPELINES_FAILURE);
},
},
analytics: {
query: getProjectPipelineStatistics,
variables() {
return {
projectPath: this.projectPath,
};
},
update(data) {
return data?.project?.pipelineAnalytics;
},
error() {
this.reportFailure(LOAD_ANALYTICS_FAILURE);
},
},
},
2020-03-13 15:44:24 +05:30
computed: {
2021-02-22 17:27:13 +05:30
failure() {
switch (this.failureType) {
case LOAD_ANALYTICS_FAILURE:
return {
text: this.$options.errorTexts[LOAD_ANALYTICS_FAILURE],
variant: 'danger',
};
case PARSE_FAILURE:
return {
text: this.$options.errorTexts[PARSE_FAILURE],
variant: 'danger',
};
case UNSUPPORTED_DATA:
return {
text: this.$options.errorTexts[UNSUPPORTED_DATA],
variant: 'info',
};
default:
return {
text: this.$options.errorTexts[DEFAULT],
variant: 'danger',
};
}
},
lastWeekChartData() {
return {
labels: this.analytics.weekPipelinesLabels,
totals: this.analytics.weekPipelinesTotals,
success: this.analytics.weekPipelinesSuccessful,
};
},
lastMonthChartData() {
return {
labels: this.analytics.monthPipelinesLabels,
totals: this.analytics.monthPipelinesTotals,
success: this.analytics.monthPipelinesSuccessful,
};
},
lastYearChartData() {
return {
labels: this.analytics.yearPipelinesLabels,
totals: this.analytics.yearPipelinesTotals,
success: this.analytics.yearPipelinesSuccessful,
};
},
2021-03-08 18:12:59 +05:30
timesChartData() {
return {
labels: this.analytics.pipelineTimesLabels,
values: this.analytics.pipelineTimesValues,
};
2020-03-13 15:44:24 +05:30
},
2021-03-08 18:12:59 +05:30
successRatio() {
const { successfulPipelines, failedPipelines } = this.counts;
const successfulCount = successfulPipelines?.count;
const failedCount = failedPipelines?.count;
const ratio = (successfulCount / (successfulCount + failedCount)) * 100;
return failedCount === 0 ? 100 : ratio;
2020-03-13 15:44:24 +05:30
},
2021-03-08 18:12:59 +05:30
formattedCounts() {
const { totalPipelines, successfulPipelines, failedPipelines } = this.counts;
2020-03-13 15:44:24 +05:30
return {
2021-03-08 18:12:59 +05:30
total: totalPipelines?.count,
success: successfulPipelines?.count,
failed: failedPipelines?.count,
successRatio: this.successRatio,
2020-03-13 15:44:24 +05:30
};
},
2021-03-08 18:12:59 +05:30
},
methods: {
2021-02-22 17:27:13 +05:30
hideAlert() {
this.showFailureAlert = false;
},
reportFailure(type) {
this.showFailureAlert = true;
this.failureType = type;
},
2020-03-13 15:44:24 +05:30
},
2021-02-22 17:27:13 +05:30
errorTexts: {
[LOAD_ANALYTICS_FAILURE]: s__(
'PipelineCharts|An error has ocurred when retrieving the analytics data',
),
[LOAD_PIPELINES_FAILURE]: s__(
'PipelineCharts|An error has ocurred when retrieving the pipelines data',
),
[PARSE_FAILURE]: s__('PipelineCharts|There was an error parsing the data for the charts.'),
[DEFAULT]: s__('PipelineCharts|An unknown error occurred while processing CI/CD analytics.'),
},
2020-03-13 15:44:24 +05:30
};
</script>
<template>
<div>
2021-03-08 18:12:59 +05:30
<gl-alert v-if="showFailureAlert" :variant="failure.variant" @dismiss="hideAlert">{{
failure.text
}}</gl-alert>
<gl-tabs v-if="shouldRenderDeploymentFrequencyCharts">
<gl-tab :title="__('Pipelines')">
<pipeline-charts
:counts="formattedCounts"
:last-week="lastWeekChartData"
:last-month="lastMonthChartData"
:last-year="lastYearChartData"
:times-chart="timesChartData"
:loading="$apollo.queries.counts.loading"
@report-failure="reportFailure"
2020-03-13 15:44:24 +05:30
/>
2021-03-08 18:12:59 +05:30
</gl-tab>
<gl-tab :title="__('Deployments')">
<deployment-frequency-charts />
</gl-tab>
</gl-tabs>
<pipeline-charts
v-else
:counts="formattedCounts"
:last-week="lastWeekChartData"
:last-month="lastMonthChartData"
:last-year="lastYearChartData"
:times-chart="timesChartData"
:loading="$apollo.queries.counts.loading"
@report-failure="reportFailure"
/>
2020-03-13 15:44:24 +05:30
</div>
</template>