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 {
let toList;
if (to) {
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 = {
},
new(listObj) {
const list = this.addList(listObj);
const backlogList = this.findList('type', 'backlog', 'backlog');
const backlogList = this.findList('type', 'backlog');
list
.save()
......@@ -185,8 +185,8 @@ const boardsStore = {
return list.issues.find((issue) => issue.id === id);
},
removeList(id, type = 'blank') {
const list = this.findList('id', id, type);
removeList(id) {
const list = this.findList('id', id);
if (!list) return;
......@@ -461,15 +461,8 @@ const boardsStore = {
moveAfterId: afterId,
});
},
findList(key, val, type = 'label') {
const filteredList = this.state.lists.filter((list) => {
const byType = type
? list.type === type || list.type === 'assignee' || list.type === 'milestone'
: true;
return list[key] === val && byType;
});
return filteredList[0];
findList(key, val) {
return this.state.lists.find((list) => list[key] === val);
},
findListByLabelId(id) {
return this.state.lists.find((list) => list.type === 'label' && list.label.id === id);
......
......@@ -186,7 +186,7 @@ describe('BoardSettingsWipLimit', () => {
afterEach(() => {
flash.mockReset();
boardsStore.removeList(listId, 'label');
boardsStore.removeList(listId);
});
describe.each`
......
......@@ -585,7 +585,7 @@ describe('boardsStore', () => {
expect(boardsStore.state.lists.length).toBe(1);
boardsStore.removeList(listObj.id, 'label');
boardsStore.removeList(listObj.id);
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