debian-mirror-gitlab/app/assets/javascripts/snippets/mixins/snippets.js

49 lines
918 B
JavaScript
Raw Normal View History

2020-04-22 19:07:51 +05:30
import GetSnippetQuery from '../queries/snippet.query.graphql';
2020-07-28 23:09:34 +05:30
const blobsDefault = [];
2020-04-22 19:07:51 +05:30
export const getSnippetMixin = {
apollo: {
snippet: {
query: GetSnippetQuery,
variables() {
return {
ids: this.snippetGid,
};
},
2021-01-03 14:25:43 +05:30
update: data => {
const res = data.snippets.nodes[0];
if (res) {
res.blobs = res.blobs.nodes;
}
return res;
},
2020-04-22 19:07:51 +05:30
result(res) {
2021-01-03 14:25:43 +05:30
this.blobs = res.data.snippets.nodes[0]?.blobs || blobsDefault;
2020-04-22 19:07:51 +05:30
if (this.onSnippetFetch) {
this.onSnippetFetch(res);
}
},
},
},
props: {
snippetGid: {
type: String,
required: true,
},
},
data() {
return {
snippet: {},
newSnippet: false,
2020-07-28 23:09:34 +05:30
blobs: blobsDefault,
2020-04-22 19:07:51 +05:30
};
},
computed: {
isLoading() {
return this.$apollo.queries.snippet.loading;
},
},
};