Commit 21559c8f authored by Phil Hughes's avatar Phil Hughes

Merge branch...

Merge branch '205205-end-to-end-failure-for-qa-specs-features-ee-browser_ui-3_create-design_management_spec-rb' into 'master'

Fix design comments on production environment

Closes #205205

See merge request gitlab-org/gitlab!25103
parents 24012a7e 3584d377
...@@ -20,7 +20,6 @@ const defaultClient = createDefaultClient( ...@@ -20,7 +20,6 @@ const defaultClient = createDefaultClient(
return defaultDataIdFromObject(object); return defaultDataIdFromObject(object);
}, },
}, },
assumeImmutableResults: true,
}, },
); );
......
/* eslint no-param-reassign: ["error", { "props": false }] */
import produce from 'immer';
import createFlash from '~/flash'; import createFlash from '~/flash';
import { extractCurrentDiscussion, extractDesign } from './design_management_utils'; import { extractCurrentDiscussion, extractDesign } from './design_management_utils';
import { import {
...@@ -10,20 +7,13 @@ import { ...@@ -10,20 +7,13 @@ import {
designDeletionError, designDeletionError,
} from './error_messages'; } 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 deleteDesignsFromStore = (store, query, selectedDesigns) => {
const sourceData = store.readQuery(query); const data = store.readQuery(query);
const data = produce(sourceData, draftData => { const changedDesigns = data.project.issue.designCollection.designs.edges.filter(
const changedDesigns = designsOf(sourceData).edges.filter( ({ node }) => !selectedDesigns.includes(node.filename),
({ node }) => !selectedDesigns.includes(node.filename), );
); data.project.issue.designCollection.designs.edges = [...changedDesigns];
designsOf(draftData).edges = [...changedDesigns];
});
store.writeQuery({ store.writeQuery({
...query, ...query,
...@@ -41,13 +31,13 @@ const deleteDesignsFromStore = (store, query, selectedDesigns) => { ...@@ -41,13 +31,13 @@ const deleteDesignsFromStore = (store, query, selectedDesigns) => {
const addNewVersionToStore = (store, query, version) => { const addNewVersionToStore = (store, query, version) => {
if (!version) return; if (!version) return;
const sourceData = store.readQuery(query); const data = store.readQuery(query);
const newEdge = { node: version, __typename: 'DesignVersionEdge' };
const newVersion = { node: version, __typename: 'DesignVersionEdge' };
const data = produce(sourceData, draftData => { data.project.issue.designCollection.versions.edges = [
draftData.project.issue.designCollection.versions.edges.unshift(newVersion); newEdge,
}); ...data.project.issue.designCollection.versions.edges,
];
store.writeQuery({ store.writeQuery({
...query, ...query,
...@@ -56,48 +46,56 @@ const addNewVersionToStore = (store, query, version) => { ...@@ -56,48 +46,56 @@ const addNewVersionToStore = (store, query, version) => {
}; };
const addDiscussionCommentToStore = (store, createNote, query, queryVariables, discussionId) => { const addDiscussionCommentToStore = (store, createNote, query, queryVariables, discussionId) => {
const sourceData = store.readQuery({ const data = store.readQuery({
query, query,
variables: queryVariables, variables: queryVariables,
}); });
const newParticipant = { const design = extractDesign(data);
__typename: 'UserEdge', const currentDiscussion = extractCurrentDiscussion(design.discussions, discussionId);
node: { currentDiscussion.node.notes.edges = [
// eslint-disable-next-line @gitlab/i18n/no-non-i18n-strings ...currentDiscussion.node.notes.edges,
__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', __typename: 'NoteEdge',
node: createNote.note, node: createNote.note,
}); },
];
if (!isParticipating(design, createNote.note.author.username)) {
design.issue.participants.edges.push(newParticipant);
}
design.notesCount += 1;
});
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,
},
},
];
}
store.writeQuery({ store.writeQuery({
query, query,
variables: queryVariables, variables: queryVariables,
data, data: {
...data,
design: {
...design,
},
},
}); });
}; };
const addImageDiffNoteToStore = (store, createImageDiffNote, query, variables) => { const addImageDiffNoteToStore = (store, createImageDiffNote, query, variables) => {
const sourceData = store.readQuery({ const data = store.readQuery({
query, query,
variables, variables,
}); });
const newDiscussion = { const newDiscussion = {
__typename: 'DiscussionEdge', __typename: 'DiscussionEdge',
node: { node: {
...@@ -117,38 +115,43 @@ const addImageDiffNoteToStore = (store, createImageDiffNote, query, variables) = ...@@ -117,38 +115,43 @@ const addImageDiffNoteToStore = (store, createImageDiffNote, query, variables) =
}, },
}, },
}; };
const design = extractDesign(data);
const newParticipant = { const notesCount = design.notesCount + 1;
__typename: 'UserEdge', design.discussions.edges = [...design.discussions.edges, newDiscussion];
node: { if (
// eslint-disable-next-line @gitlab/i18n/no-non-i18n-strings !design.issue.participants.edges.some(
__typename: 'User', participant => participant.node.username === createImageDiffNote.note.author.username,
...createImageDiffNote.note.author, )
}, ) {
}; design.issue.participants.edges = [
...design.issue.participants.edges,
const data = produce(sourceData, draftData => { {
const design = extractDesign(draftData); __typename: 'UserEdge',
design.discussions.edges.push(newDiscussion); node: {
// eslint-disable-next-line @gitlab/i18n/no-non-i18n-strings
if (!isParticipating(design, createImageDiffNote.note.author.username)) { __typename: 'User',
design.issue.participants.edges.push(newParticipant); ...createImageDiffNote.note.author,
} },
},
design.notesCount += 1; ];
}); }
store.writeQuery({ store.writeQuery({
query, query,
variables, variables,
data, data: {
...data,
design: {
...design,
notesCount,
},
},
}); });
}; };
const addNewDesignToStore = (store, designManagementUpload, query) => { 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)) { if (!acc.find(d => d.filename === design.node.filename)) {
acc.push(design.node); acc.push(design.node);
} }
...@@ -169,7 +172,7 @@ const addNewDesignToStore = (store, designManagementUpload, query) => { ...@@ -169,7 +172,7 @@ const addNewDesignToStore = (store, designManagementUpload, query) => {
const newVersions = [ const newVersions = [
...(newVersionNode || []), ...(newVersionNode || []),
...sourceData.project.issue.designCollection.versions.edges, ...data.project.issue.designCollection.versions.edges,
]; ];
const updatedDesigns = { const updatedDesigns = {
...@@ -187,9 +190,7 @@ const addNewDesignToStore = (store, designManagementUpload, query) => { ...@@ -187,9 +190,7 @@ const addNewDesignToStore = (store, designManagementUpload, query) => {
}, },
}; };
const data = produce(sourceData, draftData => { data.project.issue.designCollection = updatedDesigns;
draftData.project.issue.designCollection = updatedDesigns;
});
store.writeQuery({ store.writeQuery({
...query, ...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