diff options
Diffstat (limited to 'app/assets/javascripts/snippets/mixins/snippets.js')
-rw-r--r-- | app/assets/javascripts/snippets/mixins/snippets.js | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/app/assets/javascripts/snippets/mixins/snippets.js b/app/assets/javascripts/snippets/mixins/snippets.js index 7552eae97fc..b72befef56b 100644 --- a/app/assets/javascripts/snippets/mixins/snippets.js +++ b/app/assets/javascripts/snippets/mixins/snippets.js @@ -1,3 +1,4 @@ +import { isEmpty } from 'lodash'; import GetSnippetQuery from 'shared_queries/snippet/snippet.query.graphql'; const blobsDefault = []; @@ -12,20 +13,18 @@ export const getSnippetMixin = { }; }, update(data) { - const res = data.snippets.nodes[0]; + const res = { ...data.snippets.nodes[0] }; // Set `snippet.blobs` since some child components are coupled to this. - if (res) { + 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 : this.blobs; + res.blobs = res.blobs ? res.blobs.nodes : blobsDefault; + res.description = res.description || ''; } return res; }, - result(res) { - this.blobs = res.data.snippets.nodes[0]?.blobs || blobsDefault; - }, skip() { return this.newSnippet; }, @@ -41,12 +40,14 @@ export const getSnippetMixin = { return { snippet: {}, newSnippet: !this.snippetGid, - blobs: blobsDefault, }; }, computed: { isLoading() { return this.$apollo.queries.snippet.loading; }, + blobs() { + return this.snippet?.blobs || []; + }, }, }; |