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

55 lines
1.2 KiB
JavaScript
Raw Normal View History

2021-10-27 15:23:28 +05:30
import { isEmpty } from 'lodash';
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-10-27 15:23:28 +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-10-27 15:23:28 +05:30
if (!isEmpty(res)) {
2022-02-27 12:50:16 +05:30
res.hasUnretrievableBlobs = res.blobs?.hasUnretrievableBlobs || false;
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.
2021-10-27 15:23:28 +05:30
res.blobs = res.blobs ? res.blobs.nodes : blobsDefault;
res.description = res.description || '';
2021-01-03 14:25:43 +05:30
}
return res;
},
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-04-22 19:07:51 +05:30
};
},
computed: {
isLoading() {
return this.$apollo.queries.snippet.loading;
},
2021-10-27 15:23:28 +05:30
blobs() {
return this.snippet?.blobs || [];
},
2020-04-22 19:07:51 +05:30
},
};