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

merge_request_status_badge.vue « components « merge_requests « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3d5478757a8372e13e45b7532638ab27cb0e5a33 (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
<script>
import Vue from 'vue';
import { fetchPolicies } from '~/lib/graphql';
import StatusBadge from '~/issuable/components/status_badge.vue';

export const badgeState = Vue.observable({
  state: '',
  updateStatus: null,
});

export default {
  components: {
    StatusBadge,
  },
  inject: {
    query: { default: null },
    projectPath: { default: null },
    iid: { default: null },
  },
  props: {
    initialState: {
      type: String,
      required: false,
      default: null,
    },
    issuableType: {
      type: String,
      required: false,
      default: '',
    },
  },
  data() {
    if (!this.iid) {
      return {
        state: this.initialState,
      };
    }

    if (!badgeState.state && this.initialState) {
      badgeState.state = this.initialState;
    }

    return badgeState;
  },
  created() {
    if (!badgeState.updateStatus) {
      badgeState.updateStatus = this.fetchState;
    }
  },
  beforeDestroy() {
    if (badgeState.updateStatus && this.query) {
      badgeState.updateStatus = null;
    }
  },
  methods: {
    async fetchState() {
      const { data } = await this.$apollo.query({
        query: this.query,
        variables: {
          projectPath: this.projectPath,
          iid: this.iid,
        },
        fetchPolicy: fetchPolicies.NO_CACHE,
      });

      badgeState.state = data?.workspace?.issuable?.state;
    },
  },
};
</script>

<template>
  <status-badge class="gl-align-self-center gl-mr-3" :issuable-type="issuableType" :state="state" />
</template>