Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
b04374d5
Commit
b04374d5
authored
Aug 04, 2021
by
Denys Mishunov
Committed by
Natalia Tepluhina
Aug 04, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor Snippets application to update Apollo cache in immutable way
parent
b5edb1c7
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
18 additions
and
18 deletions
+18
-18
app/assets/javascripts/snippets/components/snippet_blob_view.vue
...ets/javascripts/snippets/components/snippet_blob_view.vue
+0
-9
app/assets/javascripts/snippets/index.js
app/assets/javascripts/snippets/index.js
+7
-1
app/assets/javascripts/snippets/mixins/snippets.js
app/assets/javascripts/snippets/mixins/snippets.js
+8
-7
spec/frontend/snippets/components/show_spec.js
spec/frontend/snippets/components/show_spec.js
+3
-1
No files found.
app/assets/javascripts/snippets/components/snippet_blob_view.vue
View file @
b04374d5
...
@@ -29,15 +29,6 @@ export default {
...
@@ -29,15 +29,6 @@ export default {
update
(
data
)
{
update
(
data
)
{
return
this
.
onContentUpdate
(
data
);
return
this
.
onContentUpdate
(
data
);
},
},
result
()
{
if
(
this
.
activeViewerType
===
RICH_BLOB_VIEWER
)
{
// eslint-disable-next-line vue/no-mutating-props
this
.
blob
.
richViewer
.
renderError
=
null
;
}
else
{
// eslint-disable-next-line vue/no-mutating-props
this
.
blob
.
simpleViewer
.
renderError
=
null
;
}
},
skip
()
{
skip
()
{
return
this
.
viewer
.
renderError
;
return
this
.
viewer
.
renderError
;
},
},
...
...
app/assets/javascripts/snippets/index.js
View file @
b04374d5
...
@@ -14,7 +14,13 @@ export default function appFactory(el, Component) {
...
@@ -14,7 +14,13 @@ export default function appFactory(el, Component) {
}
}
const
apolloProvider
=
new
VueApollo
({
const
apolloProvider
=
new
VueApollo
({
defaultClient
:
createDefaultClient
({},
{
batchMax
:
1
}),
defaultClient
:
createDefaultClient
(
{},
{
batchMax
:
1
,
assumeImmutableResults
:
true
,
},
),
});
});
const
{
const
{
...
...
app/assets/javascripts/snippets/mixins/snippets.js
View file @
b04374d5
import
{
isEmpty
}
from
'
lodash
'
;
import
GetSnippetQuery
from
'
shared_queries/snippet/snippet.query.graphql
'
;
import
GetSnippetQuery
from
'
shared_queries/snippet/snippet.query.graphql
'
;
const
blobsDefault
=
[];
const
blobsDefault
=
[];
...
@@ -12,20 +13,18 @@ export const getSnippetMixin = {
...
@@ -12,20 +13,18 @@ export const getSnippetMixin = {
};
};
},
},
update
(
data
)
{
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.
// 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.
// It's possible for us to not get any blobs in a response.
// In this case, we should default to current blobs.
// 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
;
return
res
;
},
},
result
(
res
)
{
this
.
blobs
=
res
.
data
.
snippets
.
nodes
[
0
]?.
blobs
||
blobsDefault
;
},
skip
()
{
skip
()
{
return
this
.
newSnippet
;
return
this
.
newSnippet
;
},
},
...
@@ -41,12 +40,14 @@ export const getSnippetMixin = {
...
@@ -41,12 +40,14 @@ export const getSnippetMixin = {
return
{
return
{
snippet
:
{},
snippet
:
{},
newSnippet
:
!
this
.
snippetGid
,
newSnippet
:
!
this
.
snippetGid
,
blobs
:
blobsDefault
,
};
};
},
},
computed
:
{
computed
:
{
isLoading
()
{
isLoading
()
{
return
this
.
$apollo
.
queries
.
snippet
.
loading
;
return
this
.
$apollo
.
queries
.
snippet
.
loading
;
},
},
blobs
()
{
return
this
.
snippet
?.
blobs
||
[];
},
},
},
};
};
spec/frontend/snippets/components/show_spec.js
View file @
b04374d5
...
@@ -71,8 +71,10 @@ describe('Snippet view app', () => {
...
@@ -71,8 +71,10 @@ describe('Snippet view app', () => {
it
(
'
renders correct snippet-blob components
'
,
()
=>
{
it
(
'
renders correct snippet-blob components
'
,
()
=>
{
createComponent
({
createComponent
({
data
:
{
data
:
{
snippet
:
{
blobs
:
[
Blob
,
BinaryBlob
],
blobs
:
[
Blob
,
BinaryBlob
],
},
},
},
});
});
const
blobs
=
wrapper
.
findAll
(
SnippetBlob
);
const
blobs
=
wrapper
.
findAll
(
SnippetBlob
);
expect
(
blobs
.
length
).
toBe
(
2
);
expect
(
blobs
.
length
).
toBe
(
2
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment