diff --git a/app/assets/javascripts/notes/components/issue_comment_form.vue b/app/assets/javascripts/notes/components/issue_comment_form.vue index ee873ba4b77fd675fbb8b663f51528e5113d71c9..42bac8338ff2afeefa0bd29dfa58c7cdcebf1cfc 100644 --- a/app/assets/javascripts/notes/components/issue_comment_form.vue +++ b/app/assets/javascripts/notes/components/issue_comment_form.vue @@ -28,43 +28,63 @@ export default { commentButtonTitle() { return this.noteType === 'comment' ? 'Comment' : 'Start discussion'; }, + isIssueOpen() { + return this.issueState === 'opened' || this.issueState === 'reopened'; + }, issueActionButtonTitle() { if (this.note.length) { - const actionText = this.issueState === 'open' ? 'close' : 'reopen'; + const actionText = this.isIssueOpen ? 'close' : 'reopen'; return this.noteType === 'comment' ? `Comment & ${actionText} issue` : `Start discussion & ${actionText} issue`; } - return this.issueState === 'open' ? 'Close issue' : 'Reopen issue'; + return this.isIssueOpen ? 'Close issue' : 'Reopen issue'; }, }, methods: { - handleSave() { - const data = { - endpoint: this.endpoint, - noteData: { - full_data: true, - note: { - noteable_type: 'Issue', - noteable_id: window.gl.issueData.id, - note: this.note, - } - }, - }; + handleSave(withIssueAction) { + if (this.note.length) { + const data = { + endpoint: this.endpoint, + noteData: { + full_data: true, + note: { + noteable_type: 'Issue', + noteable_id: window.gl.issueData.id, + note: this.note, + }, + }, + }; - if (this.noteType === 'discussion') { - data.noteData.note.type = 'DiscussionNote'; + if (this.noteType === 'discussion') { + data.noteData.note.type = 'DiscussionNote'; + } + + this.$store.dispatch('createNewNote', data) + .then((res) => { + if (res.errors) { + this.handleError(); + } else { + this.discard(); + } + }) + .catch(this.handleError); } - this.$store.dispatch('createNewNote', data) - .then((res) => { - if (res.errors) { - return this.handleError(); - } + if (withIssueAction) { + if (this.isIssueOpen) { + gl.issueData.state = 'closed'; + this.issueState = 'closed'; + } else { + gl.issueData.state = 'reopened'; + this.issueState = 'reopened'; + } + this.isIssueOpen = !this.isIssueOpen; - this.discard(); - }) - .catch(this.handleError); + // This is out of scope for the Notes Vue component. + // It was the shortest path to update the issue state and relevant places. + $('.js-btn-issue-action:visible').trigger('click'); + } }, discard() { this.note = ''; @@ -171,6 +191,7 @@ export default { {{issueActionButtonTitle}} diff --git a/app/assets/javascripts/notes/components/issue_note.vue b/app/assets/javascripts/notes/components/issue_note.vue index 9a7ad1db7bbbd55c6b0d02eeb3bf429b28c1acca..ac906e9440e208f1c72359998f9b6b27b0ce5c9f 100644 --- a/app/assets/javascripts/notes/components/issue_note.vue +++ b/app/assets/javascripts/notes/components/issue_note.vue @@ -59,8 +59,9 @@ export default { }, formUpdateHandler(note) { const data = { - endpoint: `${this.note.path}?full_data=1`, + endpoint: this.note.path, note: { + full_data: true, target_type: 'issue', target_id: this.note.noteable_id, note, diff --git a/app/assets/javascripts/notes/components/issue_note_awards_list.vue b/app/assets/javascripts/notes/components/issue_note_awards_list.vue index 2fc50c05c7c6beb37510ec2130904b2ee13527f3..a6e441ac90c8798277b20d06fe5e27279be5a81d 100644 --- a/app/assets/javascripts/notes/components/issue_note_awards_list.vue +++ b/app/assets/javascripts/notes/components/issue_note_awards_list.vue @@ -1,8 +1,8 @@