Commit e28099b0 authored by Kushal Pandya's avatar Kushal Pandya

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

Remove getIssue function logic from list model

See merge request gitlab-org/gitlab!21400
parents 0138be44 5c05f3bb
/* eslint-disable no-underscore-dangle, class-methods-use-this, consistent-return, no-shadow */
/* eslint-disable no-underscore-dangle, class-methods-use-this, consistent-return */
import ListIssue from 'ee_else_ce/boards/models/issue';
import { __ } from '~/locale';
import ListLabel from './label';
import ListAssignee from './assignee';
import { urlParamsToObject } from '~/lib/utils/common_utils';
import flash from '~/flash';
import boardsStore from '../stores/boards_store';
import ListMilestone from './milestone';
......@@ -113,34 +112,7 @@ class List {
}
getIssues(emptyIssues = true) {
const data = {
...urlParamsToObject(boardsStore.filter.path),
page: this.page,
};
if (this.label && data.label_name) {
data.label_name = data.label_name.filter(label => label !== this.label.title);
}
if (emptyIssues) {
this.loading = true;
}
return boardsStore
.getIssuesForList(this.id, data)
.then(res => res.data)
.then(data => {
this.loading = false;
this.issuesSize = data.size;
if (emptyIssues) {
this.issues = [];
}
this.createIssues(data.issues);
return data;
});
return boardsStore.getListIssues(this, emptyIssues);
}
newIssue(issue) {
......
......@@ -7,6 +7,7 @@ import Vue from 'vue';
import Cookies from 'js-cookie';
import BoardsStoreEE from 'ee_else_ce/boards/stores/boards_store_ee';
import {
urlParamsToObject,
getUrlParamsArray,
parseBoolean,
convertObjectPropsToCamelCase,
......@@ -535,6 +536,36 @@ const boardsStore = {
});
},
getListIssues(list, emptyIssues = true) {
const data = {
...urlParamsToObject(this.filter.path),
page: list.page,
};
if (list.label && data.label_name) {
data.label_name = data.label_name.filter(label => label !== list.label.title);
}
if (emptyIssues) {
list.loading = true;
}
return this.getIssuesForList(list.id, data)
.then(res => res.data)
.then(data => {
list.loading = false;
list.issuesSize = data.size;
if (emptyIssues) {
list.issues = [];
}
list.createIssues(data.issues);
return data;
});
},
getIssuesForList(id, filter = {}) {
const data = { id };
Object.keys(filter).forEach(key => {
......
---
title: removes store logic from issue board models
merge_request: 21400
author: nuwe1
type: other
......@@ -214,6 +214,22 @@ describe('boardsStore', () => {
});
});
describe('getListIssues', () => {
let list;
beforeEach(() => {
list = new List(listObj);
setupDefaultResponses();
});
it('makes a request to get issues', () => {
const expectedResponse = expect.objectContaining({ issues: [createTestIssue()] });
expect(list.issues).toEqual([]);
return expect(boardsStore.getListIssues(list, true)).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