debian-mirror-gitlab/app/assets/javascripts/pipelines/pipeline_details_bundle.js

131 lines
4.2 KiB
JavaScript
Raw Normal View History

2017-09-10 17:25:29 +05:30
import Vue from 'vue';
2020-10-24 23:57:45 +05:30
import { deprecatedCreateFlash as Flash } from '~/flash';
2021-06-08 01:23:25 +05:30
import { parseBoolean } from '~/lib/utils/common_utils';
2018-03-27 19:54:05 +05:30
import { __ } from '~/locale';
2021-03-11 19:13:27 +05:30
import Translate from '~/vue_shared/translate';
2021-02-22 17:27:13 +05:30
import PipelineGraphLegacy from './components/graph/graph_component_legacy.vue';
2019-12-26 22:10:19 +05:30
import TestReports from './components/test_reports/test_reports.vue';
2021-03-11 19:13:27 +05:30
import GraphBundleMixin from './mixins/graph_pipeline_bundle_mixin';
import createDagApp from './pipeline_details_dag';
2021-04-29 21:17:54 +05:30
import { createPipelinesDetailApp } from './pipeline_details_graph';
import { createPipelineHeaderApp } from './pipeline_details_header';
import { createPipelineNotificationApp } from './pipeline_details_notification';
import { apolloProvider } from './pipeline_shared_client';
2020-07-28 23:09:34 +05:30
import createTestReportsStore from './stores/test_reports';
2021-04-29 21:17:54 +05:30
import { reportToSentry } from './utils';
2017-09-10 17:25:29 +05:30
2018-03-27 19:54:05 +05:30
Vue.use(Translate);
2020-11-24 15:15:51 +05:30
const SELECTORS = {
PIPELINE_DETAILS: '.js-pipeline-details-vue',
PIPELINE_GRAPH: '#js-pipeline-graph-vue',
PIPELINE_HEADER: '#js-pipeline-header-vue',
2021-04-29 21:17:54 +05:30
PIPELINE_NOTIFICATION: '#js-pipeline-notification',
2020-11-24 15:15:51 +05:30
PIPELINE_TESTS: '#js-pipeline-tests-detail',
};
2021-03-08 18:12:59 +05:30
const createLegacyPipelinesDetailApp = (mediator) => {
2020-11-24 15:15:51 +05:30
if (!document.querySelector(SELECTORS.PIPELINE_GRAPH)) {
return;
}
2019-12-26 22:10:19 +05:30
// eslint-disable-next-line no-new
2017-09-10 17:25:29 +05:30
new Vue({
2020-11-24 15:15:51 +05:30
el: SELECTORS.PIPELINE_GRAPH,
2018-03-17 18:26:18 +05:30
components: {
2021-02-22 17:27:13 +05:30
PipelineGraphLegacy,
2018-03-17 18:26:18 +05:30
},
2019-12-21 20:55:43 +05:30
mixins: [GraphBundleMixin],
2017-09-10 17:25:29 +05:30
data() {
return {
mediator,
};
},
2021-03-08 18:12:59 +05:30
errorCaptured(err, _vm, info) {
reportToSentry('pipeline_details_bundle_legacy_details', `error: ${err}, info: ${info}`);
},
2017-09-10 17:25:29 +05:30
render(createElement) {
2021-02-22 17:27:13 +05:30
return createElement('pipeline-graph-legacy', {
2017-09-10 17:25:29 +05:30
props: {
isLoading: this.mediator.state.isLoading,
pipeline: this.mediator.store.state.pipeline,
2019-07-07 11:18:12 +05:30
mediator: this.mediator,
2018-10-15 14:42:47 +05:30
},
on: {
refreshPipelineGraph: this.requestRefreshPipelineGraph,
2021-01-29 00:20:46 +05:30
onResetDownstream: (parentPipeline, pipeline) =>
this.resetDownstreamPipelines(parentPipeline, pipeline),
2021-03-08 18:12:59 +05:30
onClickUpstreamPipeline: (pipeline) => this.clickUpstreamPipeline(pipeline),
onClickDownstreamPipeline: (pipeline) => this.clickDownstreamPipeline(pipeline),
2017-09-10 17:25:29 +05:30
},
});
},
});
2020-05-24 23:13:21 +05:30
};
2017-09-10 17:25:29 +05:30
2020-07-28 23:09:34 +05:30
const createTestDetails = () => {
2020-11-24 15:15:51 +05:30
const el = document.querySelector(SELECTORS.PIPELINE_TESTS);
2021-06-08 01:23:25 +05:30
const { blobPath, emptyStateImagePath, hasTestReport, summaryEndpoint, suiteEndpoint } =
el?.dataset || {};
2020-07-28 23:09:34 +05:30
const testReportsStore = createTestReportsStore({
2021-03-11 19:13:27 +05:30
blobPath,
2020-10-24 23:57:45 +05:30
summaryEndpoint,
suiteEndpoint,
2020-07-28 23:09:34 +05:30
});
2020-05-24 23:13:21 +05:30
// eslint-disable-next-line no-new
new Vue({
2020-07-28 23:09:34 +05:30
el,
2020-05-24 23:13:21 +05:30
components: {
TestReports,
},
2021-06-08 01:23:25 +05:30
provide: {
emptyStateImagePath,
hasTestReport: parseBoolean(hasTestReport),
},
2020-07-28 23:09:34 +05:30
store: testReportsStore,
2020-05-24 23:13:21 +05:30
render(createElement) {
return createElement('test-reports');
},
});
};
2021-03-11 19:13:27 +05:30
export default async function initPipelineDetailsBundle() {
const canShowNewPipelineDetails =
gon.features.graphqlPipelineDetails || gon.features.graphqlPipelineDetailsUsers;
2021-01-29 00:20:46 +05:30
2021-03-11 19:13:27 +05:30
const { dataset } = document.querySelector(SELECTORS.PIPELINE_DETAILS);
2020-05-24 23:13:21 +05:30
2021-04-29 21:17:54 +05:30
try {
createPipelineHeaderApp(SELECTORS.PIPELINE_HEADER, apolloProvider, dataset.graphqlResourceEtag);
} catch {
Flash(__('An error occurred while loading a section of this page.'));
}
if (gon.features.pipelineGraphLayersView) {
2021-01-29 00:20:46 +05:30
try {
2021-04-29 21:17:54 +05:30
createPipelineNotificationApp(SELECTORS.PIPELINE_NOTIFICATION, apolloProvider);
} catch {
Flash(__('An error occurred while loading a section of this page.'));
}
}
2021-02-22 17:27:13 +05:30
2021-04-29 21:17:54 +05:30
if (canShowNewPipelineDetails) {
try {
createPipelinesDetailApp(SELECTORS.PIPELINE_GRAPH, apolloProvider, dataset);
2021-01-29 00:20:46 +05:30
} catch {
Flash(__('An error occurred while loading the pipeline.'));
}
} else {
2021-03-11 19:13:27 +05:30
const { default: PipelinesMediator } = await import(
/* webpackChunkName: 'PipelinesMediator' */ './pipeline_details_mediator'
);
const mediator = new PipelinesMediator({ endpoint: dataset.endpoint });
mediator.fetchPipeline();
2021-01-29 00:20:46 +05:30
createLegacyPipelinesDetailApp(mediator);
}
2021-01-03 14:25:43 +05:30
2021-04-29 21:17:54 +05:30
createDagApp(apolloProvider);
createTestDetails();
2021-01-29 00:20:46 +05:30
}