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

snippets.js « mixins « snippets « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b72befef56b6524ac9e2986c83892ded9042a4be (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
import { isEmpty } from 'lodash';
import GetSnippetQuery from 'shared_queries/snippet/snippet.query.graphql';

const blobsDefault = [];

export const getSnippetMixin = {
  apollo: {
    snippet: {
      query: GetSnippetQuery,
      variables() {
        return {
          ids: [this.snippetGid],
        };
      },
      update(data) {
        const res = { ...data.snippets.nodes[0] };

        // Set `snippet.blobs` since some child components are coupled to this.
        if (!isEmpty(res)) {
          // It's possible for us to not get any blobs in a response.
          // In this case, we should default to current blobs.
          res.blobs = res.blobs ? res.blobs.nodes : blobsDefault;
          res.description = res.description || '';
        }

        return res;
      },
      skip() {
        return this.newSnippet;
      },
    },
  },
  props: {
    snippetGid: {
      type: String,
      required: true,
    },
  },
  data() {
    return {
      snippet: {},
      newSnippet: !this.snippetGid,
    };
  },
  computed: {
    isLoading() {
      return this.$apollo.queries.snippet.loading;
    },
    blobs() {
      return this.snippet?.blobs || [];
    },
  },
};