提交 8ab8bc34 编写于 作者: S Stan Hu

Backport new issue update changes from EE

https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/16299 fixes a bug
where a new issue in an issue board would not be properly updated with
all the right data. We now centralize the refreshing of data in a single
method to avoid this from happening again.
上级 cbb35ea8
......@@ -11,12 +11,21 @@ import boardsStore from '../stores/boards_store';
class ListIssue {
constructor(obj, defaultAvatar) {
this.refreshData(obj, defaultAvatar);
}
refreshData(obj, defaultAvatar) {
this.id = obj.id;
this.iid = obj.iid;
this.title = obj.title;
this.confidential = obj.confidential;
this.dueDate = obj.due_date;
this.subscribed = obj.subscribed;
// PUT /boards/:id/issues/:iid may not return a definition here
if (obj.subscribed !== null) {
this.subscribed = obj.subscribed;
}
this.labels = [];
this.assignees = [];
this.selected = false;
......@@ -42,11 +51,15 @@ class ListIssue {
this.milestone_id = obj.milestone.id;
}
obj.labels.forEach(label => {
this.labels.push(new ListLabel(label));
});
if (obj.labels) {
obj.labels.forEach(label => {
this.labels.push(new ListLabel(label));
});
}
this.assignees = obj.assignees.map(a => new ListAssignee(a, defaultAvatar));
if (obj.assignees) {
this.assignees = obj.assignees.map(a => new ListAssignee(a, defaultAvatar));
}
}
addLabel(label) {
......
/* eslint-disable no-underscore-dangle, class-methods-use-this, consistent-return, no-shadow, no-param-reassign */
/* eslint-disable no-underscore-dangle, class-methods-use-this, consistent-return, no-shadow */
/* global ListIssue */
import { __ } from '~/locale';
......@@ -259,12 +259,7 @@ class List {
}
onNewIssueResponse(issue, data) {
issue.id = data.id;
issue.iid = data.iid;
issue.project = data.project;
issue.path = data.real_path;
issue.referencePath = data.reference_path;
issue.assignableLabelsEndpoint = data.assignable_labels_endpoint;
issue.refreshData(data);
if (this.issuesSize > 1) {
const moveBeforeId = this.issues[1].id;
......
......@@ -174,6 +174,9 @@ describe('List model', () => {
Promise.resolve({
data: {
id: 42,
subscribed: false,
assignable_labels_endpoint: '/issue/42/labels',
toggle_subscription_endpoint: '/issue/42/subscriptions',
},
}),
);
......@@ -195,6 +198,9 @@ describe('List model', () => {
confidential: false,
labels: [list.label],
assignees: [],
subscribed: false,
assignable_labels_endpoint: '/issue/42/labels',
toggle_subscription_endpoint: '/issue/42/subscriptions',
});
list
......@@ -202,6 +208,9 @@ describe('List model', () => {
.then(() => {
expect(list.issues.length).toBe(2);
expect(list.issues[0]).toBe(dummyIssue);
expect(list.issues[0].subscribed).toBe(false);
expect(list.issues[0].assignableLabelsEndpoint).toBe('/issue/42/labels');
expect(list.issues[0].toggleSubscriptionEndpoint).toBe('/issue/42/subscriptions');
})
.then(done)
.catch(done.fail);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册