2020-03-13 15:44:24 +05:30
|
|
|
import Vue from 'vue';
|
2021-02-22 17:27:13 +05:30
|
|
|
import VueApollo from 'vue-apollo';
|
|
|
|
import createDefaultClient from '~/lib/graphql';
|
|
|
|
import ProjectPipelinesChartsLegacy from './components/app_legacy.vue';
|
2020-03-13 15:44:24 +05:30
|
|
|
import ProjectPipelinesCharts from './components/app.vue';
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
Vue.use(VueApollo);
|
|
|
|
|
|
|
|
const apolloProvider = new VueApollo({
|
|
|
|
defaultClient: createDefaultClient(),
|
|
|
|
});
|
|
|
|
|
|
|
|
const mountPipelineChartsApp = el => {
|
|
|
|
// Not all of the values will be defined since some them will be
|
|
|
|
// empty depending on the value of the graphql_pipeline_analytics
|
|
|
|
// feature flag, once the rollout of the feature flag is completed
|
|
|
|
// the undefined values will be deleted
|
2020-03-13 15:44:24 +05:30
|
|
|
const {
|
|
|
|
countsFailed,
|
|
|
|
countsSuccess,
|
|
|
|
countsTotal,
|
2021-01-29 00:20:46 +05:30
|
|
|
countsTotalDuration,
|
2020-03-13 15:44:24 +05:30
|
|
|
successRatio,
|
|
|
|
timesChartLabels,
|
|
|
|
timesChartValues,
|
|
|
|
lastWeekChartLabels,
|
|
|
|
lastWeekChartTotals,
|
|
|
|
lastWeekChartSuccess,
|
|
|
|
lastMonthChartLabels,
|
|
|
|
lastMonthChartTotals,
|
|
|
|
lastMonthChartSuccess,
|
|
|
|
lastYearChartLabels,
|
|
|
|
lastYearChartTotals,
|
|
|
|
lastYearChartSuccess,
|
2021-02-22 17:27:13 +05:30
|
|
|
projectPath,
|
2020-03-13 15:44:24 +05:30
|
|
|
} = el.dataset;
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
const parseAreaChartData = (labels, totals, success) => {
|
|
|
|
let parsedData = {};
|
|
|
|
|
|
|
|
try {
|
|
|
|
parsedData = {
|
|
|
|
labels: JSON.parse(labels),
|
|
|
|
totals: JSON.parse(totals),
|
|
|
|
success: JSON.parse(success),
|
|
|
|
};
|
|
|
|
} catch {
|
|
|
|
parsedData = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
return parsedData;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (gon?.features?.graphqlPipelineAnalytics) {
|
|
|
|
return new Vue({
|
|
|
|
el,
|
|
|
|
name: 'ProjectPipelinesChartsApp',
|
|
|
|
components: {
|
|
|
|
ProjectPipelinesCharts,
|
|
|
|
},
|
|
|
|
apolloProvider,
|
|
|
|
provide: {
|
|
|
|
projectPath,
|
|
|
|
},
|
|
|
|
render: createElement => createElement(ProjectPipelinesCharts, {}),
|
|
|
|
});
|
|
|
|
}
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
return new Vue({
|
|
|
|
el,
|
2021-02-22 17:27:13 +05:30
|
|
|
name: 'ProjectPipelinesChartsAppLegacy',
|
2020-03-13 15:44:24 +05:30
|
|
|
components: {
|
2021-02-22 17:27:13 +05:30
|
|
|
ProjectPipelinesChartsLegacy,
|
2020-03-13 15:44:24 +05:30
|
|
|
},
|
|
|
|
render: createElement =>
|
2021-02-22 17:27:13 +05:30
|
|
|
createElement(ProjectPipelinesChartsLegacy, {
|
2020-03-13 15:44:24 +05:30
|
|
|
props: {
|
|
|
|
counts: {
|
|
|
|
failed: countsFailed,
|
|
|
|
success: countsSuccess,
|
|
|
|
total: countsTotal,
|
|
|
|
successRatio,
|
2021-01-29 00:20:46 +05:30
|
|
|
totalDuration: countsTotalDuration,
|
2020-03-13 15:44:24 +05:30
|
|
|
},
|
|
|
|
timesChartData: {
|
|
|
|
labels: JSON.parse(timesChartLabels),
|
|
|
|
values: JSON.parse(timesChartValues),
|
|
|
|
},
|
|
|
|
lastWeekChartData: parseAreaChartData(
|
|
|
|
lastWeekChartLabels,
|
|
|
|
lastWeekChartTotals,
|
|
|
|
lastWeekChartSuccess,
|
|
|
|
),
|
|
|
|
lastMonthChartData: parseAreaChartData(
|
|
|
|
lastMonthChartLabels,
|
|
|
|
lastMonthChartTotals,
|
|
|
|
lastMonthChartSuccess,
|
|
|
|
),
|
|
|
|
lastYearChartData: parseAreaChartData(
|
|
|
|
lastYearChartLabels,
|
|
|
|
lastYearChartTotals,
|
|
|
|
lastYearChartSuccess,
|
|
|
|
),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
};
|
2021-02-22 17:27:13 +05:30
|
|
|
|
|
|
|
export default () => {
|
|
|
|
const el = document.querySelector('#js-project-pipelines-charts-app');
|
|
|
|
return !el ? {} : mountPipelineChartsApp(el);
|
|
|
|
};
|