Commit 3584d377 authored by ntepluhina's avatar ntepluhina

Reverted immer changes

parent 4376e173
......@@ -20,7 +20,6 @@ const defaultClient = createDefaultClient(
return defaultDataIdFromObject(object);
},
},
assumeImmutableResults: true,
},
);
......
/* eslint no-param-reassign: ["error", { "props": false }] */
import produce from 'immer';
import createFlash from '~/flash';
import { extractCurrentDiscussion, extractDesign } from './design_management_utils';
import {
......@@ -10,20 +7,13 @@ 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 sourceData = store.readQuery(query);
const data = store.readQuery(query);
const data = produce(sourceData, draftData => {
const changedDesigns = designsOf(sourceData).edges.filter(
const changedDesigns = data.project.issue.designCollection.designs.edges.filter(
({ node }) => !selectedDesigns.includes(node.filename),
);
designsOf(draftData).edges = [...changedDesigns];
});
data.project.issue.designCollection.designs.edges = [...changedDesigns];
store.writeQuery({
...query,
......@@ -41,13 +31,13 @@ const deleteDesignsFromStore = (store, query, selectedDesigns) => {
const addNewVersionToStore = (store, query, version) => {
if (!version) return;
const sourceData = store.readQuery(query);
const newVersion = { node: version, __typename: 'DesignVersionEdge' };
const data = store.readQuery(query);
const newEdge = { node: version, __typename: 'DesignVersionEdge' };
const data = produce(sourceData, draftData => {
draftData.project.issue.designCollection.versions.edges.unshift(newVersion);
});
data.project.issue.designCollection.versions.edges = [
newEdge,
...data.project.issue.designCollection.versions.edges,
];
store.writeQuery({
...query,
......@@ -56,48 +46,56 @@ const addNewVersionToStore = (store, query, version) => {
};
const addDiscussionCommentToStore = (store, createNote, query, queryVariables, discussionId) => {
const sourceData = store.readQuery({
const data = store.readQuery({
query,
variables: queryVariables,
});
const newParticipant = {
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,
{
__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: {
...data,
design: {
...design,
},
},
});
};
const addImageDiffNoteToStore = (store, createImageDiffNote, query, variables) => {
const sourceData = store.readQuery({
const data = store.readQuery({
query,
variables,
});
const newDiscussion = {
__typename: 'DiscussionEdge',
node: {
......@@ -117,38 +115,43 @@ const addImageDiffNoteToStore = (store, createImageDiffNote, query, variables) =
},
},
};
const newParticipant = {
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,
{
__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: {
...data,
design: {
...design,
notesCount,
},
},
});
};
const addNewDesignToStore = (store, designManagementUpload, query) => {
const sourceData = store.readQuery(query);
const data = store.readQuery(query);
const newDesigns = designsOf(sourceData).edges.reduce((acc, design) => {
const newDesigns = data.project.issue.designCollection.designs.edges.reduce((acc, design) => {
if (!acc.find(d => d.filename === design.node.filename)) {
acc.push(design.node);
}
......@@ -169,7 +172,7 @@ const addNewDesignToStore = (store, designManagementUpload, query) => {
const newVersions = [
...(newVersionNode || []),
...sourceData.project.issue.designCollection.versions.edges,
...data.project.issue.designCollection.versions.edges,
];
const updatedDesigns = {
......@@ -187,9 +190,7 @@ const addNewDesignToStore = (store, designManagementUpload, query) => {
},
};
const data = produce(sourceData, draftData => {
draftData.project.issue.designCollection = updatedDesigns;
});
data.project.issue.designCollection = updatedDesigns;
store.writeQuery({
...query,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment