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
f6da547b
Commit
f6da547b
authored
Feb 12, 2020
by
Natalia Tepluhina
Committed by
Phil Hughes
Feb 12, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor Apollo cache updates to be immutable in Design Management
parent
c8ace7cd
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
75 additions
and
75 deletions
+75
-75
ee/app/assets/javascripts/design_management/graphql.js
ee/app/assets/javascripts/design_management/graphql.js
+1
-0
ee/app/assets/javascripts/design_management/utils/cache_update.js
...ssets/javascripts/design_management/utils/cache_update.js
+74
-75
No files found.
ee/app/assets/javascripts/design_management/graphql.js
View file @
f6da547b
...
...
@@ -20,6 +20,7 @@ const defaultClient = createDefaultClient(
return
defaultDataIdFromObject
(
object
);
},
},
assumeImmutableResults
:
true
,
},
);
...
...
ee/app/assets/javascripts/design_management/utils/cache_update.js
View file @
f6da547b
/* eslint no-param-reassign: ["error", { "props": false }] */
import
produce
from
'
immer
'
;
import
createFlash
from
'
~/flash
'
;
import
{
extractCurrentDiscussion
,
extractDesign
}
from
'
./design_management_utils
'
;
import
{
...
...
@@ -7,13 +10,20 @@ import {
designDeletionError
,
}
from
'
./error_messages
'
;
const
designsOf
=
data
=>
data
.
project
.
issue
.
designCollection
.
designs
;
const
isParticipating
=
(
design
,
username
)
=>
design
.
issue
.
participants
.
edges
.
some
(
participant
=>
participant
.
node
.
username
===
username
);
const
deleteDesignsFromStore
=
(
store
,
query
,
selectedDesigns
)
=>
{
const
d
ata
=
store
.
readQuery
(
query
);
const
sourceD
ata
=
store
.
readQuery
(
query
);
const
changedDesigns
=
data
.
project
.
issue
.
designCollection
.
designs
.
edges
.
filter
(
const
data
=
produce
(
sourceData
,
draftData
=>
{
const
changedDesigns
=
designsOf
(
sourceData
).
edges
.
filter
(
({
node
})
=>
!
selectedDesigns
.
includes
(
node
.
filename
),
);
data
.
project
.
issue
.
designCollection
.
designs
.
edges
=
[...
changedDesigns
];
designsOf
(
draftData
).
edges
=
[...
changedDesigns
];
});
store
.
writeQuery
({
...
query
,
...
...
@@ -31,13 +41,13 @@ const deleteDesignsFromStore = (store, query, selectedDesigns) => {
const
addNewVersionToStore
=
(
store
,
query
,
version
)
=>
{
if
(
!
version
)
return
;
const
data
=
store
.
readQuery
(
query
);
const
newEdge
=
{
node
:
version
,
__typename
:
'
DesignVersionEdge
'
};
const
sourceData
=
store
.
readQuery
(
query
);
data
.
project
.
issue
.
designCollection
.
versions
.
edges
=
[
newEdge
,
...
data
.
project
.
issue
.
designCollection
.
versions
.
edges
,
];
const
newVersion
=
{
node
:
version
,
__typename
:
'
DesignVersionEdge
'
};
const
data
=
produce
(
sourceData
,
draftData
=>
{
draftData
.
project
.
issue
.
designCollection
.
versions
.
edges
.
unshift
(
newVersion
);
});
store
.
writeQuery
({
...
query
,
...
...
@@ -46,56 +56,48 @@ const addNewVersionToStore = (store, query, version) => {
};
const
addDiscussionCommentToStore
=
(
store
,
createNote
,
query
,
queryVariables
,
discussionId
)
=>
{
const
d
ata
=
store
.
readQuery
({
const
sourceD
ata
=
store
.
readQuery
({
query
,
variables
:
queryVariables
,
});
const
design
=
extractDesign
(
data
);
const
currentDiscussion
=
extractCurrentDiscussion
(
design
.
discussions
,
discussionId
);
currentDiscussion
.
node
.
notes
.
edges
=
[
...
currentDiscussion
.
node
.
notes
.
edges
,
{
__typename
:
'
NoteEdge
'
,
node
:
createNote
.
note
,
},
];
design
.
notesCount
+=
1
;
if
(
!
design
.
issue
.
participants
.
edges
.
some
(
participant
=>
participant
.
node
.
username
===
createNote
.
note
.
author
.
username
,
)
)
{
design
.
issue
.
participants
.
edges
=
[
...
design
.
issue
.
participants
.
edges
,
{
const
newParticipant
=
{
__typename
:
'
UserEdge
'
,
node
:
{
// eslint-disable-next-line @gitlab/i18n/no-non-i18n-strings
__typename
:
'
User
'
,
...
createNote
.
note
.
author
,
},
},
];
};
const
data
=
produce
(
sourceData
,
draftData
=>
{
const
design
=
extractDesign
(
draftData
);
const
currentDiscussion
=
extractCurrentDiscussion
(
design
.
discussions
,
discussionId
);
currentDiscussion
.
node
.
notes
.
edges
.
push
({
__typename
:
'
NoteEdge
'
,
node
:
createNote
.
note
,
});
if
(
!
isParticipating
(
design
,
createNote
.
note
.
author
.
username
))
{
design
.
issue
.
participants
.
edges
.
push
(
newParticipant
);
}
design
.
notesCount
+=
1
;
});
store
.
writeQuery
({
query
,
variables
:
queryVariables
,
data
:
{
...
data
,
design
:
{
...
design
,
},
},
data
,
});
};
const
addImageDiffNoteToStore
=
(
store
,
createImageDiffNote
,
query
,
variables
)
=>
{
const
d
ata
=
store
.
readQuery
({
const
sourceD
ata
=
store
.
readQuery
({
query
,
variables
,
});
const
newDiscussion
=
{
__typename
:
'
DiscussionEdge
'
,
node
:
{
...
...
@@ -115,43 +117,38 @@ const addImageDiffNoteToStore = (store, createImageDiffNote, query, variables) =
},
},
};
const
design
=
extractDesign
(
data
);
const
notesCount
=
design
.
notesCount
+
1
;
design
.
discussions
.
edges
=
[...
design
.
discussions
.
edges
,
newDiscussion
];
if
(
!
design
.
issue
.
participants
.
edges
.
some
(
participant
=>
participant
.
node
.
username
===
createImageDiffNote
.
note
.
author
.
username
,
)
)
{
design
.
issue
.
participants
.
edges
=
[
...
design
.
issue
.
participants
.
edges
,
{
const
newParticipant
=
{
__typename
:
'
UserEdge
'
,
node
:
{
// eslint-disable-next-line @gitlab/i18n/no-non-i18n-strings
__typename
:
'
User
'
,
...
createImageDiffNote
.
note
.
author
,
},
},
];
};
const
data
=
produce
(
sourceData
,
draftData
=>
{
const
design
=
extractDesign
(
draftData
);
design
.
discussions
.
edges
.
push
(
newDiscussion
);
if
(
!
isParticipating
(
design
,
createImageDiffNote
.
note
.
author
.
username
))
{
design
.
issue
.
participants
.
edges
.
push
(
newParticipant
);
}
design
.
notesCount
+=
1
;
});
store
.
writeQuery
({
query
,
variables
,
data
:
{
...
data
,
design
:
{
...
design
,
notesCount
,
},
},
data
,
});
};
const
addNewDesignToStore
=
(
store
,
designManagementUpload
,
query
)
=>
{
const
d
ata
=
store
.
readQuery
(
query
);
const
sourceD
ata
=
store
.
readQuery
(
query
);
const
newDesigns
=
d
ata
.
project
.
issue
.
designCollection
.
designs
.
edges
.
reduce
((
acc
,
design
)
=>
{
const
newDesigns
=
d
esignsOf
(
sourceData
)
.
edges
.
reduce
((
acc
,
design
)
=>
{
if
(
!
acc
.
find
(
d
=>
d
.
filename
===
design
.
node
.
filename
))
{
acc
.
push
(
design
.
node
);
}
...
...
@@ -172,7 +169,7 @@ const addNewDesignToStore = (store, designManagementUpload, query) => {
const
newVersions
=
[
...(
newVersionNode
||
[]),
...
d
ata
.
project
.
issue
.
designCollection
.
versions
.
edges
,
...
sourceD
ata
.
project
.
issue
.
designCollection
.
versions
.
edges
,
];
const
updatedDesigns
=
{
...
...
@@ -190,7 +187,9 @@ const addNewDesignToStore = (store, designManagementUpload, query) => {
},
};
data
.
project
.
issue
.
designCollection
=
updatedDesigns
;
const
data
=
produce
(
sourceData
,
draftData
=>
{
draftData
.
project
.
issue
.
designCollection
=
updatedDesigns
;
});
store
.
writeQuery
({
...
query
,
...
...
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