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

53 lines
1.1 KiB
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-03-11 19:13:27 +05:30
update(data) {
2021-01-03 14:25:43 +05:30
const res = data.snippets.nodes[0];
2021-03-11 19:13:27 +05:30
// Set `snippet.blobs` since some child components are coupled to this.
2021-01-03 14:25:43 +05:30
if (res) {
2021-03-11 19:13:27 +05:30
// 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 : this.blobs;
2021-01-03 14:25:43 +05:30
}
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;
},
},
};