Commit 7f2fdfaa authored by Lukas 'Eipi' Eipert's avatar Lukas 'Eipi' Eipert Committed by Jose Ivan Vargas

Fix deletion of deprecated notes

Notes in Snippets / Commits are deleted from the DOM even before the
user confirmed the deletion. With `bootstrap_confirmation_modals`
enabled this actually caused a bug, because the element is
progamatically clicked after confirmation. But as the element is removed
from the DOM already, Rails/UJS didn't intercept the click properly.

If we switch from a click handler to an ajax:success handler _and_
remove the note from the DOM after a successful deletion, this problem
is resolved.
parent ce45fe71
......@@ -143,7 +143,7 @@ export default class Notes {
// resolve a discussion
this.$wrapperEl.on('click', '.js-comment-resolve-button', this.postComment);
// remove a note (in general)
this.$wrapperEl.on('click', '.js-note-delete', this.removeNote);
this.$wrapperEl.on('ajax:success', '.js-note-delete', this.removeNote);
// delete note attachment
this.$wrapperEl.on('click', '.js-note-attachment-delete', this.removeAttachment);
// update the file name when an attachment is selected
......@@ -188,7 +188,7 @@ export default class Notes {
cleanBinding() {
this.$wrapperEl.off('click', '.js-note-edit');
this.$wrapperEl.off('click', '.note-edit-cancel');
this.$wrapperEl.off('click', '.js-note-delete');
this.$wrapperEl.off('ajax:success', '.js-note-delete');
this.$wrapperEl.off('click', '.js-note-attachment-delete');
this.$wrapperEl.off('click', '.js-discussion-reply-button');
this.$wrapperEl.off('click', '.js-add-diff-note-button');
......@@ -827,6 +827,8 @@ export default class Notes {
*/
removeNote(e) {
const $note = $(e.currentTarget).closest('.note');
$note.one('ajax:complete', () => {
const noteElId = $note.attr('id');
$(`.note[id="${noteElId}"]`).each((i, el) => {
// A same note appears in the "Discussion" and in the "Changes" tab, we have
......@@ -871,6 +873,7 @@ export default class Notes {
Notes.checkMergeRequestStatus();
return this.updateNotesCount(-1);
});
}
/**
......
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