Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab_ci_yaml_visualization.vue « pipeline_graph « components « pipelines « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3cc76425e2a50dfe088369b7f074caf13867b9fb (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
<script>
import { GlTab, GlTabs } from '@gitlab/ui';
import jsYaml from 'js-yaml';
import PipelineGraph from './pipeline_graph.vue';
import { preparePipelineGraphData } from '../../utils';

export default {
  FILE_CONTENT_SELECTOR: '#blob-content',
  EMPTY_FILE_SELECTOR: '.nothing-here-block',

  components: {
    GlTab,
    GlTabs,
    PipelineGraph,
  },
  props: {
    blobData: {
      required: true,
      type: String,
    },
  },
  data() {
    return {
      selectedTabIndex: 0,
      pipelineData: {},
    };
  },
  computed: {
    isVisualizationTab() {
      return this.selectedTabIndex === 1;
    },
  },
  async created() {
    if (this.blobData) {
      // The blobData in this case represents the gitlab-ci.yml data
      const json = await jsYaml.load(this.blobData);
      this.pipelineData = preparePipelineGraphData(json);
    }
  },
  methods: {
    // This is used because the blob page still uses haml, and we can't make
    // our haml hide the unused section so we resort to a standard query here.
    toggleFileContent({ isFileTab }) {
      const el = document.querySelector(this.$options.FILE_CONTENT_SELECTOR);
      const emptySection = document.querySelector(this.$options.EMPTY_FILE_SELECTOR);

      const elementToHide = el || emptySection;

      if (!elementToHide) {
        return;
      }

      // Checking for the current style display prevents user
      // from toggling visiblity on and off when clicking on the tab
      if (!isFileTab && elementToHide.style.display !== 'none') {
        elementToHide.style.display = 'none';
      }

      if (isFileTab && elementToHide.style.display === 'none') {
        elementToHide.style.display = 'block';
      }
    },
  },
};
</script>
<template>
  <div>
    <div>
      <gl-tabs v-model="selectedTabIndex">
        <gl-tab :title="__('File')" @click="toggleFileContent({ isFileTab: true })" />
        <gl-tab :title="__('Visualization')" @click="toggleFileContent({ isFileTab: false })" />
      </gl-tabs>
    </div>
    <pipeline-graph v-if="isVisualizationTab" :pipeline-data="pipelineData" />
  </div>
</template>