Commit cb5f362b authored by Marvin Karegyeya's avatar Marvin Karegyeya Committed by Martin Wortschack

Remove addissues function logic from list model

parent 62ac1467
......@@ -164,48 +164,7 @@ class List {
}
addIssue(issue, listFrom, newIndex) {
let moveBeforeId = null;
let moveAfterId = null;
if (!this.findIssue(issue.id)) {
if (newIndex !== undefined) {
this.issues.splice(newIndex, 0, issue);
if (this.issues[newIndex - 1]) {
moveBeforeId = this.issues[newIndex - 1].id;
}
if (this.issues[newIndex + 1]) {
moveAfterId = this.issues[newIndex + 1].id;
}
} else {
this.issues.push(issue);
}
if (this.label) {
issue.addLabel(this.label);
}
if (this.assignee) {
if (listFrom && listFrom.type === 'assignee') {
issue.removeAssignee(listFrom.assignee);
}
issue.addAssignee(this.assignee);
}
if (IS_EE && this.milestone) {
if (listFrom && listFrom.type === 'milestone') {
issue.removeMilestone(listFrom.milestone);
}
issue.addMilestone(this.milestone);
}
if (listFrom) {
this.issuesSize += 1;
this.updateIssueLabel(issue, listFrom, moveBeforeId, moveAfterId);
}
}
boardsStore.addListIssue(this, issue, listFrom, newIndex);
}
moveIssue(issue, oldIndex, newIndex, moveBeforeId, moveAfterId) {
......
......@@ -125,6 +125,50 @@ const boardsStore = {
path: '',
});
},
addListIssue(list, issue, listFrom, newIndex) {
let moveBeforeId = null;
let moveAfterId = null;
if (!list.findIssue(issue.id)) {
if (newIndex !== undefined) {
list.issues.splice(newIndex, 0, issue);
if (list.issues[newIndex - 1]) {
moveBeforeId = list.issues[newIndex - 1].id;
}
if (list.issues[newIndex + 1]) {
moveAfterId = list.issues[newIndex + 1].id;
}
} else {
list.issues.push(issue);
}
if (list.label) {
issue.addLabel(list.label);
}
if (list.assignee) {
if (listFrom && listFrom.type === 'assignee') {
issue.removeAssignee(listFrom.assignee);
}
issue.addAssignee(list.assignee);
}
if (IS_EE && list.milestone) {
if (listFrom && listFrom.type === 'milestone') {
issue.removeMilestone(listFrom.milestone);
}
issue.addMilestone(list.milestone);
}
if (listFrom) {
list.issuesSize += 1;
list.updateIssueLabel(issue, listFrom, moveBeforeId, moveAfterId);
}
}
},
welcomeIsHidden() {
return parseBoolean(Cookies.get('issue_board_welcome_hidden'));
},
......
---
title: removes store logic from issue board models
merge_request: 21408
author: nuwe1
type: other
......@@ -1041,6 +1041,66 @@ describe('boardsStore', () => {
});
});
describe('addListIssue', () => {
let list;
const issue1 = new ListIssue({
title: 'Testing',
id: 2,
iid: 2,
confidential: false,
labels: [
{
color: '#ff0000',
description: 'testing;',
id: 5000,
priority: undefined,
textColor: 'white',
title: 'Test',
},
],
assignees: [],
});
const issue2 = new ListIssue({
title: 'Testing',
id: 1,
iid: 1,
confidential: false,
labels: [
{
id: 1,
title: 'test',
color: 'red',
description: 'testing',
},
],
assignees: [
{
id: 1,
name: 'name',
username: 'username',
avatar_url: 'http://avatar_url',
},
],
real_path: 'path/to/issue',
});
beforeEach(() => {
list = new List(listObj);
list.addIssue(issue1);
setupDefaultResponses();
});
it('adds issues that are not already on the list', () => {
expect(list.findIssue(issue2.id)).toBe(undefined);
expect(list.issues).toEqual([issue1]);
boardsStore.addListIssue(list, issue2);
expect(list.findIssue(issue2.id)).toBe(issue2);
expect(list.issues.length).toBe(2);
expect(list.issues).toEqual([issue1, issue2]);
});
});
describe('updateIssue', () => {
let issue;
let patchSpy;
......
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