summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2019-09-08 22:31:26 -0700
committerStan Hu <stanhu@gmail.com>2019-09-09 13:33:34 -0700
commit8ab8bc34b0012a76b1cf7df24e7a364122091b19 (patch)
tree1528b35b00eed833779e278397129f74a91df729
parentcbb35ea882cdc40c09f7f6cd44bca8d72e506092 (diff)
downloadgitlab-ce-sh-fix-boards-new-issue-weight-ce.tar.gz
Backport new issue update changes from EEsh-fix-boards-new-issue-weight-ce
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.
-rw-r--r--app/assets/javascripts/boards/models/issue.js23
-rw-r--r--app/assets/javascripts/boards/models/list.js9
-rw-r--r--spec/javascripts/boards/list_spec.js9
3 files changed, 29 insertions, 12 deletions
diff --git a/app/assets/javascripts/boards/models/issue.js b/app/assets/javascripts/boards/models/issue.js
index 086340105b7..c92f7fbfffd 100644
--- a/app/assets/javascripts/boards/models/issue.js
+++ b/app/assets/javascripts/boards/models/issue.js
@@ -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) {
diff --git a/app/assets/javascripts/boards/models/list.js b/app/assets/javascripts/boards/models/list.js
index 7e0ccb9bd2a..c1d7807f92f 100644
--- a/app/assets/javascripts/boards/models/list.js
+++ b/app/assets/javascripts/boards/models/list.js
@@ -1,4 +1,4 @@
-/* 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;
diff --git a/spec/javascripts/boards/list_spec.js b/spec/javascripts/boards/list_spec.js
index 15c9ff6dfb4..c73851cb49b 100644
--- a/spec/javascripts/boards/list_spec.js
+++ b/spec/javascripts/boards/list_spec.js
@@ -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);