Commit 4b3669f3 authored by Natalia Tepluhina's avatar Natalia Tepluhina

Merge branch 'design-management-add-todo-cache-updates' into 'master'

Part 2: Add todo-related queries/resolvers to Design Management

See merge request gitlab-org/gitlab!41647
parents 002047cb 4cd8ae32
...@@ -5,4 +5,9 @@ fragment DesignListItem on Design { ...@@ -5,4 +5,9 @@ fragment DesignListItem on Design {
notesCount notesCount
image image
imageV432x230 imageV432x230
currentUserTodos(state: pending) {
nodes {
id
}
}
} }
...@@ -190,25 +190,44 @@ const moveDesignInStore = (store, designManagementMove, query) => { ...@@ -190,25 +190,44 @@ const moveDesignInStore = (store, designManagementMove, query) => {
}; };
export const addPendingTodoToStore = (store, pendingTodo, query, queryVariables) => { export const addPendingTodoToStore = (store, pendingTodo, query, queryVariables) => {
const data = store.readQuery({ const sourceData = store.readQuery({
query, query,
variables: queryVariables, variables: queryVariables,
}); });
// TODO produce new version of data that includes the new pendingTodo. const data = produce(sourceData, draftData => {
// This is only possible after BE MR: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/40555 const design = extractDesign(draftData);
const existingTodos = design.currentUserTodos?.nodes || [];
const newTodoNodes = [...existingTodos, { ...pendingTodo, __typename: 'Todo' }];
if (!design.currentUserTodos) {
design.currentUserTodos = {
__typename: 'TodoConnection',
nodes: newTodoNodes,
};
} else {
design.currentUserTodos.nodes = newTodoNodes;
}
});
store.writeQuery({ query, variables: queryVariables, data }); store.writeQuery({ query, variables: queryVariables, data });
}; };
export const deletePendingTodoFromStore = (store, pendingTodo, query, queryVariables) => { export const deletePendingTodoFromStore = (store, todoMarkDone, query, queryVariables) => {
const data = store.readQuery({ const sourceData = store.readQuery({
query, query,
variables: queryVariables, variables: queryVariables,
}); });
// TODO produce new version of data without the pendingTodo. const {
// This is only possible after BE MR: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/40555 todo: { id: todoId },
} = todoMarkDone;
const data = produce(sourceData, draftData => {
const design = extractDesign(draftData);
const existingTodos = design.currentUserTodos?.nodes || [];
design.currentUserTodos.nodes = existingTodos.filter(({ id }) => id !== todoId);
});
store.writeQuery({ query, variables: queryVariables, data }); store.writeQuery({ query, variables: queryVariables, data });
}; };
......
...@@ -13,6 +13,9 @@ export const designListQueryResponse = { ...@@ -13,6 +13,9 @@ export const designListQueryResponse = {
notesCount: 3, notesCount: 3,
image: 'image-1', image: 'image-1',
imageV432x230: 'image-1', imageV432x230: 'image-1',
currentUserTodos: {
nodes: [],
},
}, },
{ {
id: '2', id: '2',
...@@ -21,6 +24,9 @@ export const designListQueryResponse = { ...@@ -21,6 +24,9 @@ export const designListQueryResponse = {
notesCount: 2, notesCount: 2,
image: 'image-2', image: 'image-2',
imageV432x230: 'image-2', imageV432x230: 'image-2',
currentUserTodos: {
nodes: [],
},
}, },
{ {
id: '3', id: '3',
...@@ -29,6 +35,9 @@ export const designListQueryResponse = { ...@@ -29,6 +35,9 @@ export const designListQueryResponse = {
notesCount: 1, notesCount: 1,
image: 'image-3', image: 'image-3',
imageV432x230: 'image-3', imageV432x230: 'image-3',
currentUserTodos: {
nodes: [],
},
}, },
], ],
}, },
...@@ -60,6 +69,9 @@ export const reorderedDesigns = [ ...@@ -60,6 +69,9 @@ export const reorderedDesigns = [
notesCount: 2, notesCount: 2,
image: 'image-2', image: 'image-2',
imageV432x230: 'image-2', imageV432x230: 'image-2',
currentUserTodos: {
nodes: [],
},
}, },
{ {
id: '1', id: '1',
...@@ -68,6 +80,9 @@ export const reorderedDesigns = [ ...@@ -68,6 +80,9 @@ export const reorderedDesigns = [
notesCount: 3, notesCount: 3,
image: 'image-1', image: 'image-1',
imageV432x230: 'image-1', imageV432x230: 'image-1',
currentUserTodos: {
nodes: [],
},
}, },
{ {
id: '3', id: '3',
...@@ -76,6 +91,9 @@ export const reorderedDesigns = [ ...@@ -76,6 +91,9 @@ export const reorderedDesigns = [
notesCount: 1, notesCount: 1,
image: 'image-3', image: 'image-3',
imageV432x230: 'image-3', imageV432x230: 'image-3',
currentUserTodos: {
nodes: [],
},
}, },
]; ];
......
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