Commit b63a9d10 authored by Florie Guibert's avatar Florie Guibert

Boards refactor - Stop using ListIssue model

Remove ListIssue model from VueX state for GraphQL boards
parent a8993d30
import { sortBy } from 'lodash'; import { sortBy } from 'lodash';
import ListIssue from 'ee_else_ce/boards/models/issue';
import { ListType } from './constants'; import { ListType } from './constants';
import { getIdFromGraphQLId } from '~/graphql_shared/utils'; import { getIdFromGraphQLId } from '~/graphql_shared/utils';
import boardsStore from '~/boards/stores/boards_store'; import boardsStore from '~/boards/stores/boards_store';
...@@ -21,11 +20,11 @@ export function formatBoardLists(lists) { ...@@ -21,11 +20,11 @@ export function formatBoardLists(lists) {
} }
export function formatIssue(issue) { export function formatIssue(issue) {
return new ListIssue({ return {
...issue, ...issue,
labels: issue.labels?.nodes || [], labels: issue.labels?.nodes || [],
assignees: issue.assignees?.nodes || [], assignees: issue.assignees?.nodes || [],
}); };
} }
export function formatListIssues(listIssues) { export function formatListIssues(listIssues) {
...@@ -44,12 +43,12 @@ export function formatListIssues(listIssues) { ...@@ -44,12 +43,12 @@ export function formatListIssues(listIssues) {
[list.id]: sortedIssues.map(i => { [list.id]: sortedIssues.map(i => {
const id = getIdFromGraphQLId(i.id); const id = getIdFromGraphQLId(i.id);
const listIssue = new ListIssue({ const listIssue = {
...i, ...i,
id, id,
labels: i.labels?.nodes || [], labels: i.labels?.nodes || [],
assignees: i.assignees?.nodes || [], assignees: i.assignees?.nodes || [],
}); };
issues[id] = listIssue; issues[id] = listIssue;
...@@ -83,21 +82,30 @@ export function fullLabelId(label) { ...@@ -83,21 +82,30 @@ export function fullLabelId(label) {
} }
export function moveIssueListHelper(issue, fromList, toList) { export function moveIssueListHelper(issue, fromList, toList) {
if (toList.type === ListType.label) { const updatedIssue = issue;
issue.addLabel(toList.label); if (
toList.type === ListType.label &&
!updatedIssue.labels.find(label => label.id === toList.label.id)
) {
updatedIssue.labels.push(toList.label);
} }
if (fromList && fromList.type === ListType.label) { if (fromList?.label && fromList.type === ListType.label) {
issue.removeLabel(fromList.label); updatedIssue.labels = updatedIssue.labels.filter(label => fromList.label.id !== label.id);
} }
if (toList.type === ListType.assignee) { if (
issue.addAssignee(toList.assignee); toList.type === ListType.assignee &&
!updatedIssue.assignees.find(assignee => assignee.id === toList.assignee.id)
) {
updatedIssue.assignees.push(toList.assignee);
} }
if (fromList && fromList.type === ListType.assignee) { if (fromList?.assignee && fromList.type === ListType.assignee) {
issue.removeAssignee(fromList.assignee); updatedIssue.assignees = updatedIssue.assignees.filter(
assignee => assignee.id !== fromList.assignee.id,
);
} }
return issue; return updatedIssue;
} }
export default { export default {
......
...@@ -158,9 +158,13 @@ export default { ...@@ -158,9 +158,13 @@ export default {
class="confidential-icon gl-mr-2" class="confidential-icon gl-mr-2"
:aria-label="__('Confidential')" :aria-label="__('Confidential')"
/> />
<a :href="issue.path" :title="issue.title" class="js-no-trigger" @mousemove.stop>{{ <a
issue.title :href="issue.path || issue.webUrl || ''"
}}</a> :title="issue.title"
class="js-no-trigger"
@mousemove.stop
>{{ issue.title }}</a
>
</h4> </h4>
</div> </div>
<div v-if="showLabelFooter" class="board-card-labels gl-mt-2 gl-display-flex gl-flex-wrap"> <div v-if="showLabelFooter" class="board-card-labels gl-mt-2 gl-display-flex gl-flex-wrap">
...@@ -196,7 +200,11 @@ export default { ...@@ -196,7 +200,11 @@ export default {
#{{ issue.iid }} #{{ issue.iid }}
</span> </span>
<span class="board-info-items gl-mt-3 gl-display-inline-block"> <span class="board-info-items gl-mt-3 gl-display-inline-block">
<issue-due-date v-if="issue.dueDate" :date="issue.dueDate" :closed="issue.closed" /> <issue-due-date
v-if="issue.dueDate"
:date="issue.dueDate"
:closed="issue.closed || Boolean(issue.closedAt)"
/>
<issue-time-estimate v-if="issue.timeEstimate" :estimate="issue.timeEstimate" /> <issue-time-estimate v-if="issue.timeEstimate" :estimate="issue.timeEstimate" />
<issue-card-weight <issue-card-weight
v-if="validIssueWeight" v-if="validIssueWeight"
......
/* global ListIssue */
/* global List */ /* global List */
import Vue from 'vue'; import Vue from 'vue';
import '~/boards/models/list'; import '~/boards/models/list';
import '~/boards/models/issue';
export const mockLists = [ export const mockLists = [
{ {
...@@ -95,7 +93,7 @@ export const rawIssue = { ...@@ -95,7 +93,7 @@ export const rawIssue = {
}; };
export const mockIssue = { export const mockIssue = {
id: 'gid://gitlab/Issue/436', id: '436',
iid: 27, iid: 27,
title: 'Issue 1', title: 'Issue 1',
referencePath: '#27', referencePath: '#27',
...@@ -111,10 +109,8 @@ export const mockIssue = { ...@@ -111,10 +109,8 @@ export const mockIssue = {
}, },
}; };
export const mockIssueWithModel = new ListIssue({ ...mockIssue, id: '436' });
export const mockIssue2 = { export const mockIssue2 = {
id: 'gid://gitlab/Issue/437', id: '437',
iid: 28, iid: 28,
title: 'Issue 2', title: 'Issue 2',
referencePath: '#28', referencePath: '#28',
...@@ -130,8 +126,6 @@ export const mockIssue2 = { ...@@ -130,8 +126,6 @@ export const mockIssue2 = {
}, },
}; };
export const mockIssue2WithModel = new ListIssue({ ...mockIssue2, id: '437' });
export const mockIssue3 = { export const mockIssue3 = {
id: 'gid://gitlab/Issue/438', id: 'gid://gitlab/Issue/438',
iid: 29, iid: 29,
......
...@@ -14,10 +14,9 @@ import { mergeUrlParams, removeParams } from '~/lib/utils/url_utility'; ...@@ -14,10 +14,9 @@ import { mergeUrlParams, removeParams } from '~/lib/utils/url_utility';
import { import {
mockLists, mockLists,
mockIssue, mockIssue,
mockIssue2,
mockEpic, mockEpic,
rawIssue, rawIssue,
mockIssueWithModel,
mockIssue2WithModel,
mockListsWithModel, mockListsWithModel,
} from '../mock_data'; } from '../mock_data';
...@@ -635,8 +634,8 @@ describe('moveIssue', () => { ...@@ -635,8 +634,8 @@ describe('moveIssue', () => {
}; };
const issues = { const issues = {
'436': mockIssueWithModel, '436': mockIssue,
'437': mockIssue2WithModel, '437': mockIssue2,
}; };
const state = { const state = {
...@@ -673,7 +672,7 @@ describe('moveIssue', () => { ...@@ -673,7 +672,7 @@ describe('moveIssue', () => {
{ {
type: types.MOVE_ISSUE, type: types.MOVE_ISSUE,
payload: { payload: {
originalIssue: mockIssueWithModel, originalIssue: mockIssue,
fromListId: 'gid://gitlab/List/1', fromListId: 'gid://gitlab/List/1',
toListId: 'gid://gitlab/List/2', toListId: 'gid://gitlab/List/2',
epicId, epicId,
...@@ -714,7 +713,7 @@ describe('moveIssue', () => { ...@@ -714,7 +713,7 @@ describe('moveIssue', () => {
{ {
type: types.MOVE_ISSUE, type: types.MOVE_ISSUE,
payload: { payload: {
originalIssue: mockIssueWithModel, originalIssue: mockIssue,
fromListId: 'gid://gitlab/List/1', fromListId: 'gid://gitlab/List/1',
toListId: 'gid://gitlab/List/2', toListId: 'gid://gitlab/List/2',
epicId, epicId,
...@@ -723,7 +722,7 @@ describe('moveIssue', () => { ...@@ -723,7 +722,7 @@ describe('moveIssue', () => {
{ {
type: types.MOVE_ISSUE_FAILURE, type: types.MOVE_ISSUE_FAILURE,
payload: { payload: {
originalIssue: mockIssueWithModel, originalIssue: mockIssue,
fromListId: 'gid://gitlab/List/1', fromListId: 'gid://gitlab/List/1',
toListId: 'gid://gitlab/List/2', toListId: 'gid://gitlab/List/2',
originalIndex: 0, originalIndex: 0,
......
import mutations from 'ee/boards/stores/mutations'; import mutations from 'ee/boards/stores/mutations';
import { import { mockIssue, mockIssue2, mockEpics, mockEpic, mockListsWithModel } from '../mock_data';
mockIssue,
mockIssue2,
mockEpics,
mockEpic,
mockListsWithModel,
mockIssueWithModel,
mockIssue2WithModel,
} from '../mock_data';
const expectNotImplemented = action => { const expectNotImplemented = action => {
it('is not implemented', () => { it('is not implemented', () => {
...@@ -280,13 +272,13 @@ describe('RESET_EPICS', () => { ...@@ -280,13 +272,13 @@ describe('RESET_EPICS', () => {
describe('MOVE_ISSUE', () => { describe('MOVE_ISSUE', () => {
beforeEach(() => { beforeEach(() => {
const listIssues = { const listIssues = {
'gid://gitlab/List/1': [mockListsWithModel.id, mockIssue2WithModel.id], 'gid://gitlab/List/1': [mockIssue.id, mockIssue2.id],
'gid://gitlab/List/2': [], 'gid://gitlab/List/2': [],
}; };
const issues = { const issues = {
'436': mockIssueWithModel, '436': mockIssue,
'437': mockIssue2WithModel, '437': mockIssue2,
}; };
state = { state = {
...@@ -300,15 +292,15 @@ describe('MOVE_ISSUE', () => { ...@@ -300,15 +292,15 @@ describe('MOVE_ISSUE', () => {
expect(state.issues['437'].epic.id).toEqual('gid://gitlab/Epic/40'); expect(state.issues['437'].epic.id).toEqual('gid://gitlab/Epic/40');
mutations.MOVE_ISSUE(state, { mutations.MOVE_ISSUE(state, {
originalIssue: mockIssue2WithModel, originalIssue: mockIssue2,
fromListId: 'gid://gitlab/List/1', fromListId: 'gid://gitlab/List/1',
toListId: 'gid://gitlab/List/2', toListId: 'gid://gitlab/List/2',
epicId, epicId,
}); });
const updatedListIssues = { const updatedListIssues = {
'gid://gitlab/List/1': [mockListsWithModel.id], 'gid://gitlab/List/1': [mockIssue.id],
'gid://gitlab/List/2': [mockIssue2WithModel.id], 'gid://gitlab/List/2': [mockIssue2.id],
}; };
expect(state.issuesByListId).toEqual(updatedListIssues); expect(state.issuesByListId).toEqual(updatedListIssues);
...@@ -319,15 +311,15 @@ describe('MOVE_ISSUE', () => { ...@@ -319,15 +311,15 @@ describe('MOVE_ISSUE', () => {
expect(state.issues['437'].epic.id).toEqual('gid://gitlab/Epic/40'); expect(state.issues['437'].epic.id).toEqual('gid://gitlab/Epic/40');
mutations.MOVE_ISSUE(state, { mutations.MOVE_ISSUE(state, {
originalIssue: mockIssue2WithModel, originalIssue: mockIssue2,
fromListId: 'gid://gitlab/List/1', fromListId: 'gid://gitlab/List/1',
toListId: 'gid://gitlab/List/2', toListId: 'gid://gitlab/List/2',
epicId: null, epicId: null,
}); });
const updatedListIssues = { const updatedListIssues = {
'gid://gitlab/List/1': [mockListsWithModel.id], 'gid://gitlab/List/1': [mockIssue.id],
'gid://gitlab/List/2': [mockIssue2WithModel.id], 'gid://gitlab/List/2': [mockIssue2.id],
}; };
expect(state.issuesByListId).toEqual(updatedListIssues); expect(state.issuesByListId).toEqual(updatedListIssues);
......
/* global List */ /* global List */
/* global ListIssue */
import Vuex from 'vuex'; import Vuex from 'vuex';
import { useFakeRequestAnimationFrame } from 'helpers/fake_request_animation_frame'; import { useFakeRequestAnimationFrame } from 'helpers/fake_request_animation_frame';
...@@ -7,7 +6,6 @@ import { createLocalVue, mount } from '@vue/test-utils'; ...@@ -7,7 +6,6 @@ import { createLocalVue, mount } from '@vue/test-utils';
import eventHub from '~/boards/eventhub'; import eventHub from '~/boards/eventhub';
import BoardList from '~/boards/components/board_list_new.vue'; import BoardList from '~/boards/components/board_list_new.vue';
import BoardCard from '~/boards/components/board_card.vue'; import BoardCard from '~/boards/components/board_card.vue';
import '~/boards/models/issue';
import '~/boards/models/list'; import '~/boards/models/list';
import { listObj, mockIssuesByListId, issues, mockIssues } from './mock_data'; import { listObj, mockIssuesByListId, issues, mockIssues } from './mock_data';
import defaultState from '~/boards/stores/state'; import defaultState from '~/boards/stores/state';
...@@ -52,7 +50,7 @@ const createComponent = ({ ...@@ -52,7 +50,7 @@ const createComponent = ({
...listProps, ...listProps,
doNotFetchIssues: true, doNotFetchIssues: true,
}); });
const issue = new ListIssue({ const issue = {
title: 'Testing', title: 'Testing',
id: 1, id: 1,
iid: 1, iid: 1,
...@@ -60,7 +58,7 @@ const createComponent = ({ ...@@ -60,7 +58,7 @@ const createComponent = ({
labels: [], labels: [],
assignees: [], assignees: [],
...listIssueProps, ...listIssueProps,
}); };
if (!Object.prototype.hasOwnProperty.call(listProps, 'issuesSize')) { if (!Object.prototype.hasOwnProperty.call(listProps, 'issuesSize')) {
list.issuesSize = 1; list.issuesSize = 1;
} }
......
/* global ListIssue */
/* global List */ /* global List */
import Vue from 'vue'; import Vue from 'vue';
import { keyBy } from 'lodash'; import { keyBy } from 'lodash';
import '~/boards/models/list'; import '~/boards/models/list';
import '~/boards/models/issue';
import boardsStore from '~/boards/stores/boards_store'; import boardsStore from '~/boards/stores/boards_store';
export const boardObj = { export const boardObj = {
...@@ -184,8 +182,6 @@ export const mockActiveIssue = { ...@@ -184,8 +182,6 @@ export const mockActiveIssue = {
emailsDisabled: false, emailsDisabled: false,
}; };
export const mockIssueWithModel = new ListIssue(mockIssue);
export const mockIssue2 = { export const mockIssue2 = {
id: 'gid://gitlab/Issue/437', id: 'gid://gitlab/Issue/437',
iid: 28, iid: 28,
...@@ -203,8 +199,6 @@ export const mockIssue2 = { ...@@ -203,8 +199,6 @@ export const mockIssue2 = {
}, },
}; };
export const mockIssue2WithModel = new ListIssue(mockIssue2);
export const mockIssue3 = { export const mockIssue3 = {
id: 'gid://gitlab/Issue/438', id: 'gid://gitlab/Issue/438',
iid: 29, iid: 29,
......
...@@ -4,8 +4,7 @@ import { ...@@ -4,8 +4,7 @@ import {
mockLists, mockLists,
mockListsById, mockListsById,
mockIssue, mockIssue,
mockIssueWithModel, mockIssue2,
mockIssue2WithModel,
rawIssue, rawIssue,
mockIssues, mockIssues,
mockMilestone, mockMilestone,
...@@ -500,8 +499,8 @@ describe('moveIssue', () => { ...@@ -500,8 +499,8 @@ describe('moveIssue', () => {
}; };
const issues = { const issues = {
'436': mockIssueWithModel, '436': mockIssue,
'437': mockIssue2WithModel, '437': mockIssue2,
}; };
const state = { const state = {
...@@ -537,7 +536,7 @@ describe('moveIssue', () => { ...@@ -537,7 +536,7 @@ describe('moveIssue', () => {
{ {
type: types.MOVE_ISSUE, type: types.MOVE_ISSUE,
payload: { payload: {
originalIssue: mockIssueWithModel, originalIssue: mockIssue,
fromListId: 'gid://gitlab/List/1', fromListId: 'gid://gitlab/List/1',
toListId: 'gid://gitlab/List/2', toListId: 'gid://gitlab/List/2',
}, },
...@@ -612,7 +611,7 @@ describe('moveIssue', () => { ...@@ -612,7 +611,7 @@ describe('moveIssue', () => {
{ {
type: types.MOVE_ISSUE, type: types.MOVE_ISSUE,
payload: { payload: {
originalIssue: mockIssueWithModel, originalIssue: mockIssue,
fromListId: 'gid://gitlab/List/1', fromListId: 'gid://gitlab/List/1',
toListId: 'gid://gitlab/List/2', toListId: 'gid://gitlab/List/2',
}, },
...@@ -620,7 +619,7 @@ describe('moveIssue', () => { ...@@ -620,7 +619,7 @@ describe('moveIssue', () => {
{ {
type: types.MOVE_ISSUE_FAILURE, type: types.MOVE_ISSUE_FAILURE,
payload: { payload: {
originalIssue: mockIssueWithModel, originalIssue: mockIssue,
fromListId: 'gid://gitlab/List/1', fromListId: 'gid://gitlab/List/1',
toListId: 'gid://gitlab/List/2', toListId: 'gid://gitlab/List/2',
originalIndex: 0, originalIndex: 0,
......
import mutations from '~/boards/stores/mutations'; import mutations from '~/boards/stores/mutations';
import * as types from '~/boards/stores/mutation_types'; import * as types from '~/boards/stores/mutation_types';
import defaultState from '~/boards/stores/state'; import defaultState from '~/boards/stores/state';
import { import { mockListsWithModel, mockLists, rawIssue, mockIssue, mockIssue2 } from '../mock_data';
mockListsWithModel,
mockLists,
rawIssue,
mockIssue,
mockIssue2,
mockIssueWithModel,
mockIssue2WithModel,
} from '../mock_data';
const expectNotImplemented = action => { const expectNotImplemented = action => {
it('is not implemented', () => { it('is not implemented', () => {
...@@ -355,8 +347,8 @@ describe('Board Store Mutations', () => { ...@@ -355,8 +347,8 @@ describe('Board Store Mutations', () => {
}; };
const issues = { const issues = {
'1': mockIssueWithModel, '1': mockIssue,
'2': mockIssue2WithModel, '2': mockIssue2,
}; };
state = { state = {
...@@ -367,7 +359,7 @@ describe('Board Store Mutations', () => { ...@@ -367,7 +359,7 @@ describe('Board Store Mutations', () => {
}; };
mutations.MOVE_ISSUE(state, { mutations.MOVE_ISSUE(state, {
originalIssue: mockIssue2WithModel, originalIssue: mockIssue2,
fromListId: 'gid://gitlab/List/1', fromListId: 'gid://gitlab/List/1',
toListId: 'gid://gitlab/List/2', toListId: 'gid://gitlab/List/2',
}); });
...@@ -396,7 +388,7 @@ describe('Board Store Mutations', () => { ...@@ -396,7 +388,7 @@ describe('Board Store Mutations', () => {
issue: rawIssue, issue: rawIssue,
}); });
expect(state.issues).toEqual({ '436': { ...mockIssueWithModel, id: 436 } }); expect(state.issues).toEqual({ '436': { ...mockIssue, id: 436 } });
}); });
}); });
......
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