summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Schatz <jschatz@gitlab.com>2017-09-22 02:25:43 +0000
committerJacob Schatz <jschatz@gitlab.com>2017-09-22 02:25:43 +0000
commit9e46a897f230fd51c8c5788ee45cd1fc80e76792 (patch)
tree2b993e9ed29c3ae5d2cf1dc5f623d50e65ea3576
parentbc33774f5227c2a8ca7dbc04c5a6a88bd5abdbc9 (diff)
parentf22f75b752f741969484f4e2a49a7087b57b2df6 (diff)
downloadgitlab-ce-9e46a897f230fd51c8c5788ee45cd1fc80e76792.tar.gz
Merge branch 'acet-fix-double-note-render' into 'master'
Fix rendering double note issue Closes #38139 See merge request gitlab-org/gitlab-ce!14429
-rw-r--r--app/assets/javascripts/notes/components/issue_comment_form.vue5
-rw-r--r--app/assets/javascripts/notes/stores/actions.js8
-rw-r--r--app/assets/javascripts/notes/stores/mutations.js22
-rw-r--r--spec/javascripts/notes/stores/actions_spec.js1
-rw-r--r--spec/javascripts/notes/stores/mutation_spec.js30
5 files changed, 47 insertions, 19 deletions
diff --git a/app/assets/javascripts/notes/components/issue_comment_form.vue b/app/assets/javascripts/notes/components/issue_comment_form.vue
index 8a485a54271..fa7ac994058 100644
--- a/app/assets/javascripts/notes/components/issue_comment_form.vue
+++ b/app/assets/javascripts/notes/components/issue_comment_form.vue
@@ -97,6 +97,8 @@
methods: {
...mapActions([
'saveNote',
+ 'stopPolling',
+ 'restartPolling',
'removePlaceholderNotes',
]),
setIsSubmitButtonDisabled(note, isSubmitting) {
@@ -126,10 +128,13 @@
this.isSubmitting = true;
this.note = ''; // Empty textarea while being requested. Repopulate in catch
this.resizeTextarea();
+ this.stopPolling();
this.saveNote(noteData)
.then((res) => {
this.isSubmitting = false;
+ this.restartPolling();
+
if (res.errors) {
if (res.errors.commands_only) {
this.discard();
diff --git a/app/assets/javascripts/notes/stores/actions.js b/app/assets/javascripts/notes/stores/actions.js
index 923611bda9a..1a791039909 100644
--- a/app/assets/javascripts/notes/stores/actions.js
+++ b/app/assets/javascripts/notes/stores/actions.js
@@ -187,6 +187,14 @@ export const poll = ({ commit, state, getters }) => {
});
};
+export const stopPolling = () => {
+ eTagPoll.stop();
+};
+
+export const restartPolling = () => {
+ eTagPoll.restart();
+};
+
export const fetchData = ({ commit, state, getters }) => {
const requestData = { endpoint: state.notesData.notesPath, lastFetchedAt: state.lastFetchedAt };
diff --git a/app/assets/javascripts/notes/stores/mutations.js b/app/assets/javascripts/notes/stores/mutations.js
index 3b2b2089d6e..c2a08f3d6fe 100644
--- a/app/assets/javascripts/notes/stores/mutations.js
+++ b/app/assets/javascripts/notes/stores/mutations.js
@@ -5,15 +5,19 @@ import * as constants from '../constants';
export default {
[types.ADD_NEW_NOTE](state, note) {
const { discussion_id, type } = note;
- const noteData = {
- expanded: true,
- id: discussion_id,
- individual_note: !(type === constants.DISCUSSION_NOTE),
- notes: [note],
- reply_id: discussion_id,
- };
-
- state.notes.push(noteData);
+ const [exists] = state.notes.filter(n => n.id === note.discussion_id);
+
+ if (!exists) {
+ const noteData = {
+ expanded: true,
+ id: discussion_id,
+ individual_note: !(type === constants.DISCUSSION_NOTE),
+ notes: [note],
+ reply_id: discussion_id,
+ };
+
+ state.notes.push(noteData);
+ }
},
[types.ADD_NEW_REPLY_TO_DISCUSSION](state, note) {
diff --git a/spec/javascripts/notes/stores/actions_spec.js b/spec/javascripts/notes/stores/actions_spec.js
index 72d362acb2f..2b2219dcf0c 100644
--- a/spec/javascripts/notes/stores/actions_spec.js
+++ b/spec/javascripts/notes/stores/actions_spec.js
@@ -1,4 +1,3 @@
-
import * as actions from '~/notes/stores/actions';
import testAction from './helpers';
import { discussionMock, notesDataMock, userDataMock, issueDataMock, individualNote } from '../mock_data';
diff --git a/spec/javascripts/notes/stores/mutation_spec.js b/spec/javascripts/notes/stores/mutation_spec.js
index a38f29c1e39..1e22e03e178 100644
--- a/spec/javascripts/notes/stores/mutation_spec.js
+++ b/spec/javascripts/notes/stores/mutation_spec.js
@@ -3,19 +3,31 @@ import { note, discussionMock, notesDataMock, userDataMock, issueDataMock, indiv
describe('Mutation Notes Store', () => {
describe('ADD_NEW_NOTE', () => {
- it('should add a new note to an array of notes', () => {
- const state = { notes: [] };
+ let state;
+ let noteData;
+
+ beforeEach(() => {
+ state = { notes: [] };
+ noteData = {
+ expanded: true,
+ id: note.discussion_id,
+ individual_note: true,
+ notes: [note],
+ reply_id: note.discussion_id,
+ };
mutations.ADD_NEW_NOTE(state, note);
+ });
+ it('should add a new note to an array of notes', () => {
expect(state).toEqual({
- notes: [{
- expanded: true,
- id: note.discussion_id,
- individual_note: true,
- notes: [note],
- reply_id: note.discussion_id,
- }],
+ notes: [noteData],
});
+ expect(state.notes.length).toBe(1);
+ });
+
+ it('should not add the same note to the notes array', () => {
+ mutations.ADD_NEW_NOTE(state, note);
+ expect(state.notes.length).toBe(1);
});
});