Commit 08cd6b69 authored by Simon Knox's avatar Simon Knox

Merge branch 'consolidate-board-item-ids' into 'master'

Consolidate the use of IDs in board state [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!69733
parents 257011dc f4ddad56
import { sortBy, cloneDeep } from 'lodash'; import { sortBy, cloneDeep } from 'lodash';
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
import { ListType, MilestoneIDs } from './constants'; import { ListType, MilestoneIDs } from './constants';
export function getMilestone() { export function getMilestone() {
...@@ -49,12 +48,10 @@ export function formatListIssues(listIssues) { ...@@ -49,12 +48,10 @@ export function formatListIssues(listIssues) {
return { return {
...map, ...map,
[list.id]: sortedIssues.map((i) => { [list.id]: sortedIssues.map((i) => {
const id = getIdFromGraphQLId(i.id); const { id } = i;
const listIssue = { const listIssue = {
...i, ...i,
id,
fullId: i.id,
labels: i.labels?.nodes || [], labels: i.labels?.nodes || [],
assignees: i.assignees?.nodes || [], assignees: i.assignees?.nodes || [],
}; };
......
...@@ -96,7 +96,7 @@ export default { ...@@ -96,7 +96,7 @@ export default {
<template #header> <template #header>
<sidebar-todo-widget <sidebar-todo-widget
class="gl-mt-3" class="gl-mt-3"
:issuable-id="activeBoardItem.fullId" :issuable-id="activeBoardItem.id"
:issuable-iid="activeBoardItem.iid" :issuable-iid="activeBoardItem.iid"
:full-path="fullPath" :full-path="fullPath"
:issuable-type="issuableType" :issuable-type="issuableType"
......
...@@ -208,7 +208,7 @@ export default { ...@@ -208,7 +208,7 @@ export default {
newIndex = children.length; newIndex = children.length;
} }
const getItemId = (el) => Number(el.dataset.itemId); const getItemId = (el) => el.dataset.itemId;
// If item is being moved within the same list // If item is being moved within the same list
if (from === to) { if (from === to) {
...@@ -234,7 +234,7 @@ export default { ...@@ -234,7 +234,7 @@ export default {
} }
this.moveItem({ this.moveItem({
itemId: Number(itemId), itemId,
itemIid, itemIid,
itemPath, itemPath,
fromListId: from.dataset.listId, fromListId: from.dataset.listId,
......
...@@ -574,8 +574,8 @@ export default { ...@@ -574,8 +574,8 @@ export default {
boardId: fullBoardId, boardId: fullBoardId,
fromListId: getIdFromGraphQLId(fromListId), fromListId: getIdFromGraphQLId(fromListId),
toListId: getIdFromGraphQLId(toListId), toListId: getIdFromGraphQLId(toListId),
moveBeforeId, moveBeforeId: moveBeforeId ? getIdFromGraphQLId(moveBeforeId) : undefined,
moveAfterId, moveAfterId: moveAfterId ? getIdFromGraphQLId(moveAfterId) : undefined,
// 'mutationVariables' allows EE code to pass in extra parameters. // 'mutationVariables' allows EE code to pass in extra parameters.
...mutationVariables, ...mutationVariables,
}, },
...@@ -642,7 +642,7 @@ export default { ...@@ -642,7 +642,7 @@ export default {
} }
const rawIssue = data.createIssue?.issue; const rawIssue = data.createIssue?.issue;
const formattedIssue = formatIssue({ ...rawIssue, id: getIdFromGraphQLId(rawIssue.id) }); const formattedIssue = formatIssue(rawIssue);
dispatch('removeListItem', { listId: list.id, itemId: placeholderId }); dispatch('removeListItem', { listId: list.id, itemId: placeholderId });
dispatch('addListItem', { list, item: formattedIssue, position: 0 }); dispatch('addListItem', { list, item: formattedIssue, position: 0 });
}) })
...@@ -678,7 +678,7 @@ export default { ...@@ -678,7 +678,7 @@ export default {
} }
commit(types.UPDATE_BOARD_ITEM_BY_ID, { commit(types.UPDATE_BOARD_ITEM_BY_ID, {
itemId: getIdFromGraphQLId(data.updateIssue?.issue?.id) || activeBoardItem.id, itemId: data.updateIssue?.issue?.id || activeBoardItem.id,
prop: 'labels', prop: 'labels',
value: data.updateIssue.issue.labels.nodes, value: data.updateIssue.issue.labels.nodes,
}); });
......
...@@ -16,7 +16,7 @@ export default { ...@@ -16,7 +16,7 @@ export default {
}, },
activeBoardItem: (state) => { activeBoardItem: (state) => {
return state.boardItems[state.activeId] || { iid: '', id: '', fullId: '' }; return state.boardItems[state.activeId] || { iid: '', id: '' };
}, },
groupPathForActiveIssue: (_, getters) => { groupPathForActiveIssue: (_, getters) => {
......
import { cloneDeep, pull, union } from 'lodash'; import { cloneDeep, pull, union } from 'lodash';
import Vue from 'vue'; import Vue from 'vue';
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
import { s__, __ } from '~/locale'; import { s__, __ } from '~/locale';
import { formatIssue } from '../boards_util'; import { formatIssue } from '../boards_util';
import { issuableTypes } from '../constants'; import { issuableTypes } from '../constants';
...@@ -201,8 +200,7 @@ export default { ...@@ -201,8 +200,7 @@ export default {
}, },
[mutationTypes.MUTATE_ISSUE_SUCCESS]: (state, { issue }) => { [mutationTypes.MUTATE_ISSUE_SUCCESS]: (state, { issue }) => {
const issueId = getIdFromGraphQLId(issue.id); Vue.set(state.boardItems, issue.id, formatIssue(issue));
Vue.set(state.boardItems, issueId, formatIssue({ ...issue, id: issueId }));
}, },
[mutationTypes.ADD_BOARD_ITEM_TO_LIST]: ( [mutationTypes.ADD_BOARD_ITEM_TO_LIST]: (
......
...@@ -3,7 +3,6 @@ import { GlDropdownItem } from '@gitlab/ui'; ...@@ -3,7 +3,6 @@ import { GlDropdownItem } from '@gitlab/ui';
import { cloneDeep } from 'lodash'; import { cloneDeep } from 'lodash';
import Vue from 'vue'; import Vue from 'vue';
import createFlash from '~/flash'; import createFlash from '~/flash';
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
import { IssuableType } from '~/issue_show/constants'; import { IssuableType } from '~/issue_show/constants';
import { __, n__ } from '~/locale'; import { __, n__ } from '~/locale';
import SidebarAssigneesRealtime from '~/sidebar/components/assignees/assignees_realtime.vue'; import SidebarAssigneesRealtime from '~/sidebar/components/assignees/assignees_realtime.vue';
...@@ -173,7 +172,7 @@ export default { ...@@ -173,7 +172,7 @@ export default {
}) })
.then(({ data }) => { .then(({ data }) => {
this.$emit('assignees-updated', { this.$emit('assignees-updated', {
id: getIdFromGraphQLId(data.issuableSetAssignees.issuable.id), id: data.issuableSetAssignees.issuable.id,
assignees: data.issuableSetAssignees.issuable.assignees.nodes, assignees: data.issuableSetAssignees.issuable.assignees.nodes,
}); });
return data; return data;
......
import { FiltersInfo as FiltersInfoCE } from '~/boards/boards_util'; import { FiltersInfo as FiltersInfoCE } from '~/boards/boards_util';
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
import { objectToQuery, queryToObject } from '~/lib/utils/url_utility'; import { objectToQuery, queryToObject } from '~/lib/utils/url_utility';
import { import {
EPIC_LANE_BASE_HEIGHT, EPIC_LANE_BASE_HEIGHT,
...@@ -61,12 +60,10 @@ export function formatListEpics(listEpics) { ...@@ -61,12 +60,10 @@ export function formatListEpics(listEpics) {
return { return {
...map, ...map,
[list.id]: sortedEpics.map((i) => { [list.id]: sortedEpics.map((i) => {
const id = getIdFromGraphQLId(i.id); const { id } = i;
const listEpic = { const listEpic = {
...i, ...i,
id,
fullId: i.id,
labels: i.labels?.nodes || [], labels: i.labels?.nodes || [],
assignees: i.assignees?.nodes || [], assignees: i.assignees?.nodes || [],
}; };
......
...@@ -64,7 +64,7 @@ export default { ...@@ -64,7 +64,7 @@ export default {
<template #header> <template #header>
<sidebar-todo-widget <sidebar-todo-widget
class="gl-mt-3" class="gl-mt-3"
:issuable-id="activeBoardItem.fullId" :issuable-id="activeBoardItem.id"
:issuable-iid="activeBoardItem.iid" :issuable-iid="activeBoardItem.iid"
:full-path="fullPath" :full-path="fullPath"
:issuable-type="issuableType" :issuable-type="issuableType"
......
...@@ -151,7 +151,7 @@ export default { ...@@ -151,7 +151,7 @@ export default {
} }
this.moveIssue({ this.moveIssue({
itemId: Number(itemId), itemId,
itemIid, itemIid,
itemPath, itemPath,
fromListId: from.dataset.listId, fromListId: from.dataset.listId,
......
...@@ -11,12 +11,10 @@ import listsIssuesQuery from '~/boards/graphql/lists_issues.query.graphql'; ...@@ -11,12 +11,10 @@ import listsIssuesQuery from '~/boards/graphql/lists_issues.query.graphql';
import projectBoardMembersQuery from '~/boards/graphql/project_board_members.query.graphql'; import projectBoardMembersQuery from '~/boards/graphql/project_board_members.query.graphql';
import actionsCE, { gqlClient } from '~/boards/stores/actions'; import actionsCE, { gqlClient } from '~/boards/stores/actions';
import * as typesCE from '~/boards/stores/mutation_types'; import * as typesCE from '~/boards/stores/mutation_types';
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
import { historyPushState, convertObjectPropsToCamelCase } from '~/lib/utils/common_utils'; import { historyPushState, convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
import { mergeUrlParams, removeParams, queryToObject } from '~/lib/utils/url_utility'; import { mergeUrlParams, removeParams, queryToObject } from '~/lib/utils/url_utility';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import { import {
fullEpicId,
fullEpicBoardId, fullEpicBoardId,
formatEpic, formatEpic,
formatListEpics, formatListEpics,
...@@ -384,12 +382,12 @@ export default { ...@@ -384,12 +382,12 @@ export default {
.mutate({ .mutate({
mutation: epicMoveListMutation, mutation: epicMoveListMutation,
variables: { variables: {
epicId: fullEpicId(itemId), epicId: itemId,
boardId: fullEpicBoardId(boardId), boardId: fullEpicBoardId(boardId),
fromListId, fromListId,
toListId, toListId,
moveAfterId: moveAfterId ? fullEpicId(moveAfterId) : undefined, moveBeforeId,
moveBeforeId: moveBeforeId ? fullEpicId(moveBeforeId) : undefined, moveAfterId,
}, },
}) })
.then(({ data }) => { .then(({ data }) => {
...@@ -561,7 +559,7 @@ export default { ...@@ -561,7 +559,7 @@ export default {
} }
const rawEpic = data.createEpic?.epic; const rawEpic = data.createEpic?.epic;
const formattedEpic = formatEpic({ ...rawEpic, id: getIdFromGraphQLId(rawEpic.id) }); const formattedEpic = formatEpic(rawEpic);
dispatch('removeListItem', { listId: list.id, itemId: placeholderId }); dispatch('removeListItem', { listId: list.id, itemId: placeholderId });
dispatch('addListItem', { list, item: formattedEpic, position: 0 }); dispatch('addListItem', { list, item: formattedEpic, position: 0 });
}) })
......
...@@ -8,6 +8,7 @@ import setWindowLocation from 'helpers/set_window_location_helper'; ...@@ -8,6 +8,7 @@ import setWindowLocation from 'helpers/set_window_location_helper';
import { mockLabel } from './mock_data'; import { mockLabel } from './mock_data';
const listId = 'gid://gitlab/Boards::EpicList/3'; const listId = 'gid://gitlab/Boards::EpicList/3';
const epicId = 'gid://gitlab/Epic/1';
describe('formatEpic', () => { describe('formatEpic', () => {
it('formats raw epic object for state', () => { it('formats raw epic object for state', () => {
...@@ -19,7 +20,7 @@ describe('formatEpic', () => { ...@@ -19,7 +20,7 @@ describe('formatEpic', () => {
]; ];
const rawEpic = { const rawEpic = {
id: 1, id: epicId,
title: 'Foo', title: 'Foo',
labels: { labels: {
nodes: labels, nodes: labels,
...@@ -48,7 +49,7 @@ describe('formatListEpics', () => { ...@@ -48,7 +49,7 @@ describe('formatListEpics', () => {
{ {
node: { node: {
title: 'epic title', title: 'epic title',
id: 'gid://gitlab/Epic/1', id: epicId,
labels: { labels: {
nodes: [mockLabel], nodes: [mockLabel],
}, },
...@@ -64,15 +65,14 @@ describe('formatListEpics', () => { ...@@ -64,15 +65,14 @@ describe('formatListEpics', () => {
expect(result).toEqual({ expect(result).toEqual({
boardItems: { boardItems: {
1: { [epicId]: {
assignees: [], assignees: [],
id: 1, id: epicId,
fullId: 'gid://gitlab/Epic/1',
labels: [mockLabel], labels: [mockLabel],
title: 'epic title', title: 'epic title',
}, },
}, },
listData: { [listId]: [1] }, listData: { [listId]: [epicId] },
listItemsCount: 1, listItemsCount: 1,
}); });
}); });
......
...@@ -147,8 +147,7 @@ export const mockIssueGroupPath = 'gitlab-org'; ...@@ -147,8 +147,7 @@ export const mockIssueGroupPath = 'gitlab-org';
export const mockIssueProjectPath = `${mockIssueGroupPath}/gitlab-test`; export const mockIssueProjectPath = `${mockIssueGroupPath}/gitlab-test`;
export const mockIssue = { export const mockIssue = {
id: '436', id: 'gid://gitlab/Issue/436',
fullId: 'gid://gitlab/Issue/436',
iid: '27', iid: '27',
title: 'Issue 1', title: 'Issue 1',
referencePath: `${mockIssueProjectPath}#27`, referencePath: `${mockIssueProjectPath}#27`,
...@@ -233,8 +232,7 @@ export const mockEpic = { ...@@ -233,8 +232,7 @@ export const mockEpic = {
}; };
export const mockFormattedBoardEpic = { export const mockFormattedBoardEpic = {
fullId: 'gid://gitlab/Epic/41', id: 'gid://gitlab/Epic/41',
id: 41,
iid: '1', iid: '1',
title: 'Epic title', title: 'Epic title',
referencePath: 'gitlab-org/gitlab-subgroup&41', referencePath: 'gitlab-org/gitlab-subgroup&41',
......
...@@ -14,7 +14,6 @@ import { mockMoveIssueParams, mockMoveData, mockMoveState } from 'jest/boards/mo ...@@ -14,7 +14,6 @@ import { mockMoveIssueParams, mockMoveData, mockMoveState } from 'jest/boards/mo
import { formatListIssues } from '~/boards/boards_util'; import { formatListIssues } from '~/boards/boards_util';
import listsIssuesQuery from '~/boards/graphql/lists_issues.query.graphql'; import listsIssuesQuery from '~/boards/graphql/lists_issues.query.graphql';
import * as typesCE from '~/boards/stores/mutation_types'; import * as typesCE from '~/boards/stores/mutation_types';
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
import * as commonUtils from '~/lib/utils/common_utils'; import * as commonUtils from '~/lib/utils/common_utils';
import { mergeUrlParams, removeParams } from '~/lib/utils/url_utility'; import { mergeUrlParams, removeParams } from '~/lib/utils/url_utility';
import { import {
...@@ -1044,7 +1043,7 @@ describe('addListNewEpic', () => { ...@@ -1044,7 +1043,7 @@ describe('addListNewEpic', () => {
type: 'addListItem', type: 'addListItem',
payload: { payload: {
list: fakeList, list: fakeList,
item: { ...mockEpic, id: getIdFromGraphQLId(mockEpic.id), assignees: [] }, item: { ...mockEpic, assignees: [] },
position: 0, position: 0,
}, },
}, },
......
...@@ -192,8 +192,7 @@ export const mockIssue = { ...@@ -192,8 +192,7 @@ export const mockIssue = {
export const mockActiveIssue = { export const mockActiveIssue = {
...mockIssue, ...mockIssue,
fullId: 'gid://gitlab/Issue/436', id: 'gid://gitlab/Issue/436',
id: 436,
iid: '27', iid: '27',
subscribed: false, subscribed: false,
emailsDisabled: false, emailsDisabled: false,
......
...@@ -26,7 +26,6 @@ import issueCreateMutation from '~/boards/graphql/issue_create.mutation.graphql' ...@@ -26,7 +26,6 @@ import issueCreateMutation from '~/boards/graphql/issue_create.mutation.graphql'
import actions, { gqlClient } from '~/boards/stores/actions'; import actions, { gqlClient } from '~/boards/stores/actions';
import * as types from '~/boards/stores/mutation_types'; import * as types from '~/boards/stores/mutation_types';
import mutations from '~/boards/stores/mutations'; import mutations from '~/boards/stores/mutations';
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
import { import {
mockLists, mockLists,
...@@ -1213,8 +1212,8 @@ describe('updateMovedIssueCard', () => { ...@@ -1213,8 +1212,8 @@ describe('updateMovedIssueCard', () => {
describe('updateIssueOrder', () => { describe('updateIssueOrder', () => {
const issues = { const issues = {
436: mockIssue, [mockIssue.id]: mockIssue,
437: mockIssue2, [mockIssue2.id]: mockIssue2,
}; };
const state = { const state = {
...@@ -1223,7 +1222,7 @@ describe('updateIssueOrder', () => { ...@@ -1223,7 +1222,7 @@ describe('updateIssueOrder', () => {
}; };
const moveData = { const moveData = {
itemId: 436, itemId: mockIssue.id,
fromListId: 'gid://gitlab/List/1', fromListId: 'gid://gitlab/List/1',
toListId: 'gid://gitlab/List/2', toListId: 'gid://gitlab/List/2',
}; };
...@@ -1482,7 +1481,7 @@ describe('addListNewIssue', () => { ...@@ -1482,7 +1481,7 @@ describe('addListNewIssue', () => {
type: 'addListItem', type: 'addListItem',
payload: { payload: {
list: fakeList, list: fakeList,
item: formatIssue({ ...mockIssue, id: getIdFromGraphQLId(mockIssue.id) }), item: formatIssue(mockIssue),
position: 0, position: 0,
}, },
}, },
......
...@@ -77,12 +77,12 @@ describe('Boards - Getters', () => { ...@@ -77,12 +77,12 @@ describe('Boards - Getters', () => {
}); });
describe('getBoardItemById', () => { describe('getBoardItemById', () => {
const state = { boardItems: { 1: 'issue' } }; const state = { boardItems: { 'gid://gitlab/Issue/1': 'issue' } };
it.each` it.each`
id | expected id | expected
${'1'} | ${'issue'} ${'gid://gitlab/Issue/1'} | ${'issue'}
${''} | ${{}} ${''} | ${{}}
`('returns $expected when $id is passed to state', ({ id, expected }) => { `('returns $expected when $id is passed to state', ({ id, expected }) => {
expect(getters.getBoardItemById(state)(id)).toEqual(expected); expect(getters.getBoardItemById(state)(id)).toEqual(expected);
}); });
...@@ -90,11 +90,11 @@ describe('Boards - Getters', () => { ...@@ -90,11 +90,11 @@ describe('Boards - Getters', () => {
describe('activeBoardItem', () => { describe('activeBoardItem', () => {
it.each` it.each`
id | expected id | expected
${'1'} | ${'issue'} ${'gid://gitlab/Issue/1'} | ${'issue'}
${''} | ${{ id: '', iid: '', fullId: '' }} ${''} | ${{ id: '', iid: '' }}
`('returns $expected when $id is passed to state', ({ id, expected }) => { `('returns $expected when $id is passed to state', ({ id, expected }) => {
const state = { boardItems: { 1: 'issue' }, activeId: id }; const state = { boardItems: { 'gid://gitlab/Issue/1': 'issue' }, activeId: id };
expect(getters.activeBoardItem(state)).toEqual(expected); expect(getters.activeBoardItem(state)).toEqual(expected);
}); });
......
...@@ -407,7 +407,7 @@ describe('Board Store Mutations', () => { ...@@ -407,7 +407,7 @@ describe('Board Store Mutations', () => {
describe('MUTATE_ISSUE_SUCCESS', () => { describe('MUTATE_ISSUE_SUCCESS', () => {
it('updates issue in issues state', () => { it('updates issue in issues state', () => {
const issues = { const issues = {
436: { id: rawIssue.id }, [rawIssue.id]: { id: rawIssue.id },
}; };
state = { state = {
...@@ -419,7 +419,7 @@ describe('Board Store Mutations', () => { ...@@ -419,7 +419,7 @@ describe('Board Store Mutations', () => {
issue: rawIssue, issue: rawIssue,
}); });
expect(state.boardItems).toEqual({ 436: { ...mockIssue, id: 436 } }); expect(state.boardItems).toEqual({ [mockIssue.id]: mockIssue });
}); });
}); });
......
...@@ -206,7 +206,7 @@ describe('Sidebar assignees widget', () => { ...@@ -206,7 +206,7 @@ describe('Sidebar assignees widget', () => {
status: null, status: null,
}, },
], ],
id: 1, id: 'gid://gitlab/Issue/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