summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/pipelines/pipeline_details_bundle.js
blob: c3444f38ea0f3d3138b8155942fe71c9877e1737 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import Vue from 'vue';
import { deprecatedCreateFlash as Flash } from '~/flash';
import { __ } from '~/locale';
import Translate from '~/vue_shared/translate';
import PipelineGraphLegacy from './components/graph/graph_component_legacy.vue';
import { reportToSentry } from './components/graph/utils';
import TestReports from './components/test_reports/test_reports.vue';
import GraphBundleMixin from './mixins/graph_pipeline_bundle_mixin';
import createDagApp from './pipeline_details_dag';
import createTestReportsStore from './stores/test_reports';

Vue.use(Translate);

const SELECTORS = {
  PIPELINE_DETAILS: '.js-pipeline-details-vue',
  PIPELINE_GRAPH: '#js-pipeline-graph-vue',
  PIPELINE_HEADER: '#js-pipeline-header-vue',
  PIPELINE_TESTS: '#js-pipeline-tests-detail',
};

const createLegacyPipelinesDetailApp = (mediator) => {
  if (!document.querySelector(SELECTORS.PIPELINE_GRAPH)) {
    return;
  }
  // eslint-disable-next-line no-new
  new Vue({
    el: SELECTORS.PIPELINE_GRAPH,
    components: {
      PipelineGraphLegacy,
    },
    mixins: [GraphBundleMixin],
    data() {
      return {
        mediator,
      };
    },
    errorCaptured(err, _vm, info) {
      reportToSentry('pipeline_details_bundle_legacy_details', `error: ${err}, info: ${info}`);
    },
    render(createElement) {
      return createElement('pipeline-graph-legacy', {
        props: {
          isLoading: this.mediator.state.isLoading,
          pipeline: this.mediator.store.state.pipeline,
          mediator: this.mediator,
        },
        on: {
          refreshPipelineGraph: this.requestRefreshPipelineGraph,
          onResetDownstream: (parentPipeline, pipeline) =>
            this.resetDownstreamPipelines(parentPipeline, pipeline),
          onClickUpstreamPipeline: (pipeline) => this.clickUpstreamPipeline(pipeline),
          onClickDownstreamPipeline: (pipeline) => this.clickDownstreamPipeline(pipeline),
        },
      });
    },
  });
};

const createTestDetails = () => {
  const el = document.querySelector(SELECTORS.PIPELINE_TESTS);
  const { blobPath, summaryEndpoint, suiteEndpoint } = el?.dataset || {};
  const testReportsStore = createTestReportsStore({
    blobPath,
    summaryEndpoint,
    suiteEndpoint,
  });

  // eslint-disable-next-line no-new
  new Vue({
    el,
    components: {
      TestReports,
    },
    store: testReportsStore,
    render(createElement) {
      return createElement('test-reports');
    },
  });
};

export default async function initPipelineDetailsBundle() {
  createTestDetails();
  createDagApp();

  const canShowNewPipelineDetails =
    gon.features.graphqlPipelineDetails || gon.features.graphqlPipelineDetailsUsers;

  const { dataset } = document.querySelector(SELECTORS.PIPELINE_DETAILS);

  if (canShowNewPipelineDetails) {
    try {
      const { createPipelinesDetailApp } = await import(
        /* webpackChunkName: 'createPipelinesDetailApp' */ './pipeline_details_graph'
      );

      createPipelinesDetailApp(SELECTORS.PIPELINE_GRAPH, dataset);
    } catch {
      Flash(__('An error occurred while loading the pipeline.'));
    }
  } else {
    const { default: PipelinesMediator } = await import(
      /* webpackChunkName: 'PipelinesMediator' */ './pipeline_details_mediator'
    );
    const mediator = new PipelinesMediator({ endpoint: dataset.endpoint });
    mediator.fetchPipeline();

    createLegacyPipelinesDetailApp(mediator);
  }

  try {
    const { createPipelineHeaderApp } = await import(
      /* webpackChunkName: 'createPipelineHeaderApp' */ './pipeline_details_header'
    );
    createPipelineHeaderApp(SELECTORS.PIPELINE_HEADER);
  } catch {
    Flash(__('An error occurred while loading a section of this page.'));
  }
}