From 17d67a989bb1a87df17583e96b387aa3fa3a9f56 Mon Sep 17 00:00:00 2001 From: Fatih Acet Date: Thu, 29 Jun 2017 14:47:59 +0300 Subject: [PATCH] IssueNotesRefactor: Implement close/reopen issue actions. --- .../notes/components/issue_comment_form.vue | 69 ++++++++++++------- .../notes/components/issue_note.vue | 3 +- .../components/issue_note_awards_list.vue | 2 +- .../notes/services/issue_notes_service.js | 2 +- .../notes/stores/issue_notes_store.js | 2 +- app/views/projects/issues/show.html.haml | 4 +- 6 files changed, 52 insertions(+), 30 deletions(-) diff --git a/app/assets/javascripts/notes/components/issue_comment_form.vue b/app/assets/javascripts/notes/components/issue_comment_form.vue index ee873ba4b77..42bac8338ff 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 9a7ad1db7bb..ac906e9440e 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 2fc50c05c7c..a6e441ac90c 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 @@