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

49 lines
918 B
JavaScript
Raw Normal View History

2021-01-29 00:20:46 +05:30
import GetSnippetQuery from 'shared_queries/snippet/snippet.query.graphql';
2020-04-22 19:07:51 +05:30
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 {
2021-01-29 00:20:46 +05:30
ids: [this.snippetGid],
2020-04-22 19:07:51 +05:30
};
},
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;
2021-01-29 00:20:46 +05:30
},
skip() {
return this.newSnippet;
2020-04-22 19:07:51 +05:30
},
},
},
props: {
snippetGid: {
type: String,
required: true,
},
},
data() {
return {
snippet: {},
2021-01-29 00:20:46 +05:30
newSnippet: !this.snippetGid,
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;
},
},
};