Commit add62e65 authored by Nicolò Maria Mezzopera's avatar Nicolò Maria Mezzopera

Merge branch...

Merge branch '217715-refactor-design-management-queries-and-mutations-to-stop-using-edges' into 'master'

Refactor Design Management queries and mutations to stop using 'edges'

Closes #217715

See merge request gitlab-org/gitlab!38166
parents 5a4e89c3 349d5202
...@@ -48,7 +48,7 @@ export default { ...@@ -48,7 +48,7 @@ export default {
}; };
}, },
discussionParticipants() { discussionParticipants() {
return extractParticipants(this.issue.participants); return extractParticipants(this.issue.participants.nodes);
}, },
resolvedDiscussions() { resolvedDiscussions() {
return this.discussions.filter(discussion => discussion.resolved); return this.discussions.filter(discussion => discussion.resolved);
......
...@@ -18,7 +18,7 @@ export default { ...@@ -18,7 +18,7 @@ export default {
if (!this.queryVersion) return 0; if (!this.queryVersion) return 0;
const idx = this.allVersions.findIndex( const idx = this.allVersions.findIndex(
version => this.findVersionId(version.node.id) === this.queryVersion, version => this.findVersionId(version.id) === this.queryVersion,
); );
// if the currentVersionId isn't a valid version (i.e. not in allVersions) // if the currentVersionId isn't a valid version (i.e. not in allVersions)
...@@ -29,7 +29,7 @@ export default { ...@@ -29,7 +29,7 @@ export default {
if (this.queryVersion) return this.queryVersion; if (this.queryVersion) return this.queryVersion;
const currentVersion = this.allVersions[this.currentVersionIdx]; const currentVersion = this.allVersions[this.currentVersionIdx];
return this.findVersionId(currentVersion.node.id); return this.findVersionId(currentVersion.id);
}, },
dropdownText() { dropdownText() {
if (this.isLatestVersion) { if (this.isLatestVersion) {
...@@ -51,23 +51,21 @@ export default { ...@@ -51,23 +51,21 @@ export default {
<template> <template>
<gl-new-dropdown :text="dropdownText" size="small" class="design-version-dropdown"> <gl-new-dropdown :text="dropdownText" size="small" class="design-version-dropdown">
<gl-new-dropdown-item v-for="(version, index) in allVersions" :key="version.node.id"> <gl-new-dropdown-item v-for="(version, index) in allVersions" :key="version.id">
<router-link <router-link
class="d-flex js-version-link" class="d-flex js-version-link"
:to="{ path: $route.path, query: { version: findVersionId(version.node.id) } }" :to="{ path: $route.path, query: { version: findVersionId(version.id) } }"
> >
<div class="flex-grow-1 ml-2"> <div class="flex-grow-1 ml-2">
<div> <div>
<strong <strong
>{{ __('Version') }} {{ allVersions.length - index }} >{{ __('Version') }} {{ allVersions.length - index }}
<span v-if="findVersionId(version.node.id) === latestVersionId" <span v-if="findVersionId(version.id) === latestVersionId">({{ __('latest') }})</span>
>({{ __('latest') }})</span
>
</strong> </strong>
</div> </div>
</div> </div>
<i <i
v-if="findVersionId(version.node.id) === currentVersionId" v-if="findVersionId(version.id) === currentVersionId"
class="fa fa-check float-right gl-mr-2" class="fa fa-check float-right gl-mr-2"
></i> ></i>
</router-link> </router-link>
......
...@@ -8,10 +8,8 @@ mutation createImageDiffNote($input: CreateImageDiffNoteInput!) { ...@@ -8,10 +8,8 @@ mutation createImageDiffNote($input: CreateImageDiffNoteInput!) {
id id
replyId replyId
notes { notes {
edges { nodes {
node { ...DesignNote
...DesignNote
}
} }
} }
} }
......
...@@ -5,11 +5,9 @@ mutation uploadDesign($files: [Upload!]!, $projectPath: ID!, $iid: ID!) { ...@@ -5,11 +5,9 @@ mutation uploadDesign($files: [Upload!]!, $projectPath: ID!, $iid: ID!) {
designs { designs {
...DesignItem ...DesignItem
versions { versions {
edges { nodes {
node { id
id sha
sha
}
} }
} }
} }
......
...@@ -7,19 +7,15 @@ query getDesign($fullPath: ID!, $iid: String!, $atVersion: ID, $filenames: [Stri ...@@ -7,19 +7,15 @@ query getDesign($fullPath: ID!, $iid: String!, $atVersion: ID, $filenames: [Stri
issue(iid: $iid) { issue(iid: $iid) {
designCollection { designCollection {
designs(atVersion: $atVersion, filenames: $filenames) { designs(atVersion: $atVersion, filenames: $filenames) {
edges { nodes {
node { ...DesignItem
...DesignItem issue {
issue { title
title webPath
webPath webUrl
webUrl participants {
participants { nodes {
edges { ...Author
node {
...Author
}
}
} }
} }
} }
......
...@@ -7,17 +7,13 @@ query getDesignList($fullPath: ID!, $iid: String!, $atVersion: ID) { ...@@ -7,17 +7,13 @@ query getDesignList($fullPath: ID!, $iid: String!, $atVersion: ID) {
issue(iid: $iid) { issue(iid: $iid) {
designCollection { designCollection {
designs(atVersion: $atVersion) { designs(atVersion: $atVersion) {
edges { nodes {
node { ...DesignListItem
...DesignListItem
}
} }
} }
versions { versions {
edges { nodes {
node { ...VersionListItem
...VersionListItem
}
} }
} }
} }
......
...@@ -2,7 +2,6 @@ import { propertyOf } from 'lodash'; ...@@ -2,7 +2,6 @@ import { propertyOf } from 'lodash';
import createFlash from '~/flash'; import createFlash from '~/flash';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import getDesignListQuery from '../graphql/queries/get_design_list.query.graphql'; import getDesignListQuery from '../graphql/queries/get_design_list.query.graphql';
import { extractNodes } from '../utils/design_management_utils';
import allVersionsMixin from './all_versions'; import allVersionsMixin from './all_versions';
import { DESIGNS_ROUTE_NAME } from '../router/constants'; import { DESIGNS_ROUTE_NAME } from '../router/constants';
...@@ -19,9 +18,15 @@ export default { ...@@ -19,9 +18,15 @@ export default {
}; };
}, },
update: data => { update: data => {
const designEdges = propertyOf(data)(['project', 'issue', 'designCollection', 'designs']); const designNodes = propertyOf(data)([
if (designEdges) { 'project',
return extractNodes(designEdges); 'issue',
'designCollection',
'designs',
'nodes',
]);
if (designNodes) {
return designNodes;
} }
return []; return [];
}, },
......
...@@ -12,7 +12,7 @@ export default { ...@@ -12,7 +12,7 @@ export default {
atVersion: null, atVersion: null,
}; };
}, },
update: data => data.project.issue.designCollection.versions.edges, update: data => data.project.issue.designCollection.versions.nodes,
}, },
}, },
inject: { inject: {
...@@ -28,7 +28,7 @@ export default { ...@@ -28,7 +28,7 @@ export default {
return ( return (
this.$route.query.version && this.$route.query.version &&
this.allVersions && this.allVersions &&
this.allVersions.some(version => version.node.id.endsWith(this.$route.query.version)) this.allVersions.some(version => version.id.endsWith(this.$route.query.version))
); );
}, },
designsVersion() { designsVersion() {
...@@ -38,7 +38,7 @@ export default { ...@@ -38,7 +38,7 @@ export default {
}, },
latestVersionId() { latestVersionId() {
const latestVersion = this.allVersions[0]; const latestVersion = this.allVersions[0];
return latestVersion && findVersionId(latestVersion.node.id); return latestVersion && findVersionId(latestVersion.id);
}, },
isLatestVersion() { isLatestVersion() {
if (this.allVersions.length > 0) { if (this.allVersions.length > 0) {
......
...@@ -12,10 +12,10 @@ import { ...@@ -12,10 +12,10 @@ import {
const deleteDesignsFromStore = (store, query, selectedDesigns) => { const deleteDesignsFromStore = (store, query, selectedDesigns) => {
const data = store.readQuery(query); const data = store.readQuery(query);
const changedDesigns = data.project.issue.designCollection.designs.edges.filter( const changedDesigns = data.project.issue.designCollection.designs.nodes.filter(
({ node }) => !selectedDesigns.includes(node.filename), node => !selectedDesigns.includes(node.filename),
); );
data.project.issue.designCollection.designs.edges = [...changedDesigns]; data.project.issue.designCollection.designs.nodes = [...changedDesigns];
store.writeQuery({ store.writeQuery({
...query, ...query,
...@@ -34,11 +34,10 @@ const addNewVersionToStore = (store, query, version) => { ...@@ -34,11 +34,10 @@ const addNewVersionToStore = (store, query, version) => {
if (!version) return; if (!version) return;
const data = store.readQuery(query); const data = store.readQuery(query);
const newEdge = { node: version, __typename: 'DesignVersionEdge' };
data.project.issue.designCollection.versions.edges = [ data.project.issue.designCollection.versions.nodes = [
newEdge, version,
...data.project.issue.designCollection.versions.edges, ...data.project.issue.designCollection.versions.nodes,
]; ];
store.writeQuery({ store.writeQuery({
...@@ -59,18 +58,15 @@ const addDiscussionCommentToStore = (store, createNote, query, queryVariables, d ...@@ -59,18 +58,15 @@ const addDiscussionCommentToStore = (store, createNote, query, queryVariables, d
design.notesCount += 1; design.notesCount += 1;
if ( if (
!design.issue.participants.edges.some( !design.issue.participants.nodes.some(
participant => participant.node.username === createNote.note.author.username, participant => participant.username === createNote.note.author.username,
) )
) { ) {
design.issue.participants.edges = [ design.issue.participants.nodes = [
...design.issue.participants.edges, ...design.issue.participants.nodes,
{ {
__typename: 'UserEdge', __typename: 'User',
node: { ...createNote.note.author,
__typename: 'User',
...createNote.note.author,
},
}, },
]; ];
} }
...@@ -108,18 +104,15 @@ const addImageDiffNoteToStore = (store, createImageDiffNote, query, variables) = ...@@ -108,18 +104,15 @@ const addImageDiffNoteToStore = (store, createImageDiffNote, query, variables) =
const notesCount = design.notesCount + 1; const notesCount = design.notesCount + 1;
design.discussions.nodes = [...design.discussions.nodes, newDiscussion]; design.discussions.nodes = [...design.discussions.nodes, newDiscussion];
if ( if (
!design.issue.participants.edges.some( !design.issue.participants.nodes.some(
participant => participant.node.username === createImageDiffNote.note.author.username, participant => participant.username === createImageDiffNote.note.author.username,
) )
) { ) {
design.issue.participants.edges = [ design.issue.participants.nodes = [
...design.issue.participants.edges, ...design.issue.participants.nodes,
{ {
__typename: 'UserEdge', __typename: 'User',
node: { ...createImageDiffNote.note.author,
__typename: 'User',
...createImageDiffNote.note.author,
},
}, },
]; ];
} }
...@@ -166,9 +159,9 @@ const updateImageDiffNoteInStore = (store, updateImageDiffNote, query, variables ...@@ -166,9 +159,9 @@ const updateImageDiffNoteInStore = (store, updateImageDiffNote, query, variables
const addNewDesignToStore = (store, designManagementUpload, query) => { const addNewDesignToStore = (store, designManagementUpload, query) => {
const data = store.readQuery(query); const data = store.readQuery(query);
const newDesigns = data.project.issue.designCollection.designs.edges.reduce((acc, design) => { const newDesigns = data.project.issue.designCollection.designs.nodes.reduce((acc, design) => {
if (!acc.find(d => d.filename === design.node.filename)) { if (!acc.find(d => d.filename === design.filename)) {
acc.push(design.node); acc.push(design);
} }
return acc; return acc;
...@@ -178,30 +171,27 @@ const addNewDesignToStore = (store, designManagementUpload, query) => { ...@@ -178,30 +171,27 @@ const addNewDesignToStore = (store, designManagementUpload, query) => {
const findNewVersions = designManagementUpload.designs.find(design => design.versions); const findNewVersions = designManagementUpload.designs.find(design => design.versions);
if (findNewVersions) { if (findNewVersions) {
const findNewVersionsEdges = findNewVersions.versions.edges; const findNewVersionsNodes = findNewVersions.versions.nodes;
if (findNewVersionsEdges && findNewVersionsEdges.length) { if (findNewVersionsNodes && findNewVersionsNodes.length) {
newVersionNode = [findNewVersionsEdges[0]]; newVersionNode = [findNewVersionsNodes[0]];
} }
} }
const newVersions = [ const newVersions = [
...(newVersionNode || []), ...(newVersionNode || []),
...data.project.issue.designCollection.versions.edges, ...data.project.issue.designCollection.versions.nodes,
]; ];
const updatedDesigns = { const updatedDesigns = {
__typename: 'DesignCollection', __typename: 'DesignCollection',
designs: { designs: {
__typename: 'DesignConnection', __typename: 'DesignConnection',
edges: newDesigns.map(design => ({ nodes: newDesigns,
__typename: 'DesignEdge',
node: design,
})),
}, },
versions: { versions: {
__typename: 'DesignVersionConnection', __typename: 'DesignVersionConnection',
edges: newVersions, nodes: newVersions,
}, },
}; };
......
...@@ -5,17 +5,7 @@ export const isValidDesignFile = ({ type }) => ...@@ -5,17 +5,7 @@ export const isValidDesignFile = ({ type }) =>
(type.match(VALID_DESIGN_FILE_MIMETYPE.regex) || []).length > 0; (type.match(VALID_DESIGN_FILE_MIMETYPE.regex) || []).length > 0;
/** /**
* Returns formatted array that doesn't contain * Returns formatted array of discussions
* `edges`->`node` nesting
*
* @param {Array} elements
*/
export const extractNodes = elements => elements.edges.map(({ node }) => node);
/**
* Returns formatted array of discussions that doesn't contain
* `edges`->`node` nesting for child notes
* *
* @param {Array} discussions * @param {Array} discussions
*/ */
...@@ -40,9 +30,9 @@ export const findVersionId = id => (id.match('::Version/(.+$)') || [])[1]; ...@@ -40,9 +30,9 @@ export const findVersionId = id => (id.match('::Version/(.+$)') || [])[1];
export const findNoteId = id => (id.match('DiffNote/(.+$)') || [])[1]; export const findNoteId = id => (id.match('DiffNote/(.+$)') || [])[1];
export const extractDesigns = data => data.project.issue.designCollection.designs.edges; export const extractDesigns = data => data.project.issue.designCollection.designs.nodes;
export const extractDesign = data => (extractDesigns(data) || [])[0]?.node; export const extractDesign = data => (extractDesigns(data) || [])[0];
/** /**
* Generates optimistic response for a design upload mutation * Generates optimistic response for a design upload mutation
...@@ -72,13 +62,10 @@ export const designUploadOptimisticResponse = files => { ...@@ -72,13 +62,10 @@ export const designUploadOptimisticResponse = files => {
}, },
versions: { versions: {
__typename: 'DesignVersionConnection', __typename: 'DesignVersionConnection',
edges: { nodes: {
__typename: 'DesignVersionEdge', __typename: 'DesignVersion',
node: { id: -uniqueId(),
__typename: 'DesignVersion', sha: -uniqueId(),
id: -uniqueId(),
sha: -uniqueId(),
},
}, },
}, },
})); }));
...@@ -123,6 +110,6 @@ const normalizeAuthor = author => ({ ...@@ -123,6 +110,6 @@ const normalizeAuthor = author => ({
avatar_url: author.avatarUrl, avatar_url: author.avatarUrl,
}); });
export const extractParticipants = users => users.edges.map(({ node }) => normalizeAuthor(node)); export const extractParticipants = users => users.map(node => normalizeAuthor(node));
export const getPageLayoutElement = () => document.querySelector('.layout-page'); export const getPageLayoutElement = () => document.querySelector('.layout-page');
export default [ export default [
{ {
node: { id: 'gid://gitlab/DesignManagement::Version/3',
id: 'gid://gitlab/DesignManagement::Version/3', sha: '0945756378e0b1588b9dd40d5a6b99e8b7198f55',
sha: '0945756378e0b1588b9dd40d5a6b99e8b7198f55',
},
}, },
{ {
node: { id: 'gid://gitlab/DesignManagement::Version/2',
id: 'gid://gitlab/DesignManagement::Version/2', sha: '5b063fef0cd7213b312db65b30e24f057df21b20',
sha: '5b063fef0cd7213b312db65b30e24f057df21b20',
},
}, },
]; ];
export default [ export default [
{ {
node: { id: 'gid://gitlab/DesignManagement::Version/1',
id: 'gid://gitlab/DesignManagement::Version/1', sha: 'b389071a06c153509e11da1f582005b316667001',
sha: 'b389071a06c153509e11da1f582005b316667001',
},
}, },
]; ];
...@@ -12,14 +12,12 @@ export default { ...@@ -12,14 +12,12 @@ export default {
webPath: 'full-issue-path', webPath: 'full-issue-path',
webUrl: 'full-issue-url', webUrl: 'full-issue-url',
participants: { participants: {
edges: [ nodes: [
{ {
node: { name: 'Administrator',
name: 'Administrator', username: 'root',
username: 'root', webUrl: 'link-to-author',
webUrl: 'link-to-author', avatarUrl: 'link-to-avatar',
avatarUrl: 'link-to-avatar',
},
}, },
], ],
}, },
......
...@@ -5,11 +5,7 @@ export default { ...@@ -5,11 +5,7 @@ export default {
issue: { issue: {
designCollection: { designCollection: {
designs: { designs: {
edges: [ nodes: [design],
{
node: design,
},
],
}, },
}, },
}, },
......
...@@ -3,7 +3,7 @@ export default { ...@@ -3,7 +3,7 @@ export default {
issue: { issue: {
designCollection: { designCollection: {
designs: { designs: {
edges: [], nodes: [],
}, },
}, },
}, },
......
...@@ -57,9 +57,7 @@ const mockDesigns = [ ...@@ -57,9 +57,7 @@ const mockDesigns = [
]; ];
const mockVersion = { const mockVersion = {
node: { id: 'gid://gitlab/DesignManagement::Version/1',
id: 'gid://gitlab/DesignManagement::Version/1',
},
}; };
describe('Design management index page', () => { describe('Design management index page', () => {
...@@ -240,13 +238,10 @@ describe('Design management index page', () => { ...@@ -240,13 +238,10 @@ describe('Design management index page', () => {
}, },
versions: { versions: {
__typename: 'DesignVersionConnection', __typename: 'DesignVersionConnection',
edges: { nodes: {
__typename: 'DesignVersionEdge', __typename: 'DesignVersion',
node: { id: expect.anything(),
__typename: 'DesignVersion', sha: expect.anything(),
id: expect.anything(),
sha: expect.anything(),
},
}, },
}, },
}, },
......
...@@ -51,7 +51,7 @@ describe('extractDiscussions', () => { ...@@ -51,7 +51,7 @@ describe('extractDiscussions', () => {
}; };
}); });
it('discards the edges.node artifacts of GraphQL', () => { it('discards the node artifacts of GraphQL', () => {
expect(extractDiscussions(discussions)).toEqual([ expect(extractDiscussions(discussions)).toEqual([
{ id: 1, notes: ['a'], index: 1 }, { id: 1, notes: ['a'], index: 1 },
{ id: 2, notes: ['b'], index: 2 }, { id: 2, notes: ['b'], index: 2 },
...@@ -96,10 +96,7 @@ describe('optimistic responses', () => { ...@@ -96,10 +96,7 @@ describe('optimistic responses', () => {
discussions: { __typename: 'DesignDiscussion', nodes: [] }, discussions: { __typename: 'DesignDiscussion', nodes: [] },
versions: { versions: {
__typename: 'DesignVersionConnection', __typename: 'DesignVersionConnection',
edges: { nodes: { __typename: 'DesignVersion', id: -1, sha: -1 },
__typename: 'DesignVersionEdge',
node: { __typename: 'DesignVersion', id: -1, sha: -1 },
},
}, },
}, },
], ],
......
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