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

pipeline_mini_graph.vue « pipeline_mini_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: 7cdaec8146600c86fcb21c471a9e27d663f17403 (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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<script>
import { GlLoadingIcon } from '@gitlab/ui';
import { createAlert } from '~/alert';
import { __ } from '~/locale';
import { keepLatestDownstreamPipelines } from '~/pipelines/components/parsing_utils';
import {
  getQueryHeaders,
  toggleQueryPollingByVisibility,
} from '~/pipelines/components/graph/utils';
import { PIPELINE_MINI_GRAPH_POLL_INTERVAL } from '~/pipelines/constants';
import getLinkedPipelinesQuery from '~/pipelines/graphql/queries/get_linked_pipelines.query.graphql';
import getPipelineStagesQuery from '~/pipelines/graphql/queries/get_pipeline_stages.query.graphql';
import LegacyPipelineMiniGraph from './legacy_pipeline_mini_graph.vue';

export default {
  i18n: {
    linkedPipelinesFetchError: __('There was a problem fetching linked pipelines.'),
    stagesFetchError: __('There was a problem fetching the pipeline stages.'),
  },
  components: {
    GlLoadingIcon,
    LegacyPipelineMiniGraph,
  },
  props: {
    pipelineEtag: {
      type: String,
      required: true,
    },
    fullPath: {
      type: String,
      required: true,
    },
    iid: {
      type: String,
      required: true,
    },
    isMergeTrain: {
      type: Boolean,
      required: false,
      default: false,
    },
    pollInterval: {
      type: Number,
      required: false,
      default: PIPELINE_MINI_GRAPH_POLL_INTERVAL,
    },
  },
  data() {
    return {
      linkedPipelines: null,
      pipelineStages: [],
    };
  },
  apollo: {
    linkedPipelines: {
      context() {
        return getQueryHeaders(this.pipelineEtag);
      },
      query: getLinkedPipelinesQuery,
      pollInterval() {
        return this.pollInterval;
      },
      variables() {
        return {
          fullPath: this.fullPath,
          iid: this.iid,
        };
      },
      update({ project }) {
        return project?.pipeline || this.linkedpipelines;
      },
      error() {
        createAlert({ message: this.$options.i18n.linkedPipelinesFetchError });
      },
    },
    pipelineStages: {
      context() {
        return getQueryHeaders(this.pipelineEtag);
      },
      query: getPipelineStagesQuery,
      pollInterval() {
        return this.pollInterval;
      },
      variables() {
        return {
          fullPath: this.fullPath,
          iid: this.iid,
        };
      },
      update({ project }) {
        return project?.pipeline?.stages?.nodes || this.pipelineStages;
      },
      error() {
        createAlert({ message: this.$options.i18n.stagesFetchError });
      },
    },
  },
  computed: {
    downstreamPipelines() {
      return keepLatestDownstreamPipelines(this.linkedPipelines?.downstream?.nodes);
    },
    formattedStages() {
      return this.pipelineStages.map((stage) => {
        const { name, detailedStatus } = stage;
        return {
          // TODO: Once we fetch stage by ID with GraphQL,
          // this method will change.
          // see https://gitlab.com/gitlab-org/gitlab/-/issues/384853
          id: stage.id,
          dropdown_path: `${this.pipelinePath}/stage.json?stage=${name}`,
          name,
          path: `${this.pipelinePath}#${name}`,
          status: {
            details_path: `${this.pipelinePath}#${name}`,
            has_details: detailedStatus?.hasDetails || false,
            ...detailedStatus,
          },
          title: `${name}: ${detailedStatus?.text || ''}`,
        };
      });
    },
    pipelinePath() {
      return this.linkedPipelines?.path || '';
    },
    upstreamPipeline() {
      return this.linkedPipelines?.upstream;
    },
  },
  mounted() {
    toggleQueryPollingByVisibility(this.$apollo.queries.linkedPipelines);
    toggleQueryPollingByVisibility(this.$apollo.queries.pipelineStages);
  },
};
</script>

<template>
  <div>
    <gl-loading-icon v-if="$apollo.queries.pipelineStages.loading" />
    <legacy-pipeline-mini-graph
      v-else
      data-testid="pipeline-mini-graph"
      is-graphql
      :downstream-pipelines="downstreamPipelines"
      :is-merge-train="isMergeTrain"
      :pipeline-path="pipelinePath"
      :stages="formattedStages"
      :upstream-pipeline="upstreamPipeline"
    />
  </div>
</template>