Commit c021bbb2 authored by Simon Knox's avatar Simon Knox

Merge branch 'simplify-board-find-list-function' into 'master'

Simplify findList and removeList functions in board store

See merge request gitlab-org/gitlab!51685
parents 9cf9a05b b7b3f6e1
...@@ -242,7 +242,7 @@ export default { ...@@ -242,7 +242,7 @@ export default {
let toList; let toList;
if (to) { if (to) {
const containerEl = to.closest('.js-board-list'); const containerEl = to.closest('.js-board-list');
toList = boardsStore.findList('id', Number(containerEl.dataset.board), ''); toList = boardsStore.findList('id', Number(containerEl.dataset.board));
} }
/** /**
......
...@@ -101,7 +101,7 @@ const boardsStore = { ...@@ -101,7 +101,7 @@ const boardsStore = {
}, },
new(listObj) { new(listObj) {
const list = this.addList(listObj); const list = this.addList(listObj);
const backlogList = this.findList('type', 'backlog', 'backlog'); const backlogList = this.findList('type', 'backlog');
list list
.save() .save()
...@@ -185,8 +185,8 @@ const boardsStore = { ...@@ -185,8 +185,8 @@ const boardsStore = {
return list.issues.find((issue) => issue.id === id); return list.issues.find((issue) => issue.id === id);
}, },
removeList(id, type = 'blank') { removeList(id) {
const list = this.findList('id', id, type); const list = this.findList('id', id);
if (!list) return; if (!list) return;
...@@ -461,15 +461,8 @@ const boardsStore = { ...@@ -461,15 +461,8 @@ const boardsStore = {
moveAfterId: afterId, moveAfterId: afterId,
}); });
}, },
findList(key, val, type = 'label') { findList(key, val) {
const filteredList = this.state.lists.filter((list) => { return this.state.lists.find((list) => list[key] === val);
const byType = type
? list.type === type || list.type === 'assignee' || list.type === 'milestone'
: true;
return list[key] === val && byType;
});
return filteredList[0];
}, },
findListByLabelId(id) { findListByLabelId(id) {
return this.state.lists.find((list) => list.type === 'label' && list.label.id === id); return this.state.lists.find((list) => list.type === 'label' && list.label.id === id);
......
...@@ -186,7 +186,7 @@ describe('BoardSettingsWipLimit', () => { ...@@ -186,7 +186,7 @@ describe('BoardSettingsWipLimit', () => {
afterEach(() => { afterEach(() => {
flash.mockReset(); flash.mockReset();
boardsStore.removeList(listId, 'label'); boardsStore.removeList(listId);
}); });
describe.each` describe.each`
......
...@@ -585,7 +585,7 @@ describe('boardsStore', () => { ...@@ -585,7 +585,7 @@ describe('boardsStore', () => {
expect(boardsStore.state.lists.length).toBe(1); expect(boardsStore.state.lists.length).toBe(1);
boardsStore.removeList(listObj.id, 'label'); boardsStore.removeList(listObj.id);
expect(boardsStore.state.lists.length).toBe(0); expect(boardsStore.state.lists.length).toBe(0);
}); });
......
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