Commit 4b8834ea authored by Martin Wortschack's avatar Martin Wortschack

Merge branch 'Remove-save-function-logic-from-list.js' into 'master'

Remove save function logic from list.js

See merge request gitlab-org/gitlab!21391
parents 0ac0bd8e 6189043b
......@@ -83,27 +83,7 @@ class List {
}
save() {
const entity = this.label || this.assignee || this.milestone;
let entityType = '';
if (this.label) {
entityType = 'label_id';
} else if (this.assignee) {
entityType = 'assignee_id';
} else if (IS_EE && this.milestone) {
entityType = 'milestone_id';
}
return boardsStore
.createList(entity.id, entityType)
.then(res => res.data)
.then(data => {
this.id = data.id;
this.type = data.list_type;
this.position = data.position;
this.label = data.label;
return this.getIssues();
});
return boardsStore.saveList(this);
}
destroy() {
......
/* eslint-disable no-shadow */
/* eslint-disable no-shadow, no-param-reassign */
/* global List */
import $ from 'jquery';
......@@ -408,6 +408,29 @@ const boardsStore = {
return axios.delete(`${this.state.endpoints.listsEndpoint}/${id}`);
},
saveList(list) {
const entity = list.label || list.assignee || list.milestone;
let entityType = '';
if (list.label) {
entityType = 'label_id';
} else if (list.assignee) {
entityType = 'assignee_id';
} else if (IS_EE && list.milestone) {
entityType = 'milestone_id';
}
return this.createList(entity.id, entityType)
.then(res => res.data)
.then(data => {
list.id = data.id;
list.type = data.list_type;
list.position = data.position;
list.label = data.label;
return list.getIssues();
});
},
getIssuesForList(id, filter = {}) {
const data = { id };
Object.keys(filter).forEach(key => {
......
---
title: removes store logic from issue board models
merge_request: 21391
author: nuwe1
type: other
......@@ -6,7 +6,7 @@ import eventHub from '~/boards/eventhub';
import { listObj, listObjDuplicate } from './mock_data';
import ListIssue from '~/boards/models/issue';
import '~/boards/models/list';
import List from '~/boards/models/list';
jest.mock('js-cookie');
......@@ -190,6 +190,30 @@ describe('boardsStore', () => {
});
});
describe('saveList', () => {
let list;
beforeEach(() => {
list = new List(listObj);
setupDefaultResponses();
});
it('makes a request to save a list', () => {
const expectedResponse = expect.objectContaining({ issues: [createTestIssue()] });
const expectedListValue = {
id: listObj.id,
position: listObj.position,
type: listObj.list_type,
label: listObj.label,
};
expect(list.id).toBe(listObj.id);
expect(list.position).toBe(listObj.position);
expect(list).toMatchObject(expectedListValue);
return expect(boardsStore.saveList(list)).resolves.toEqual(expectedResponse);
});
});
describe('getIssuesForList', () => {
const id = 'TOO-MUCH';
const url = `${endpoints.listsEndpoint}/${id}/issues?id=${id}`;
......
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