From 7a251207e1b6f2b4c709d319d870694ace620e0c Mon Sep 17 00:00:00 2001 From: Filipa Lacerda Date: Fri, 28 Jul 2017 12:53:51 +0100 Subject: [PATCH] [ci skip] Emit events up to prevent accessing refs of refs --- .../notes/components/issue_comment_form.vue | 11 +++----- .../notes/components/issue_note.vue | 27 +++++++++---------- .../notes/components/issue_note_actions.vue | 11 ++++---- .../components/issue_note_awards_list.vue | 16 +++++------ .../notes/components/issue_note_body.vue | 22 ++++++++------- .../notes/components/issue_note_form.vue | 26 +++++++----------- .../notes/components/issue_note_header.vue | 2 +- .../notes/components/issue_notes_app.vue | 4 +-- .../issue_placeholder_system_note.vue | 2 +- app/assets/javascripts/notes/index.js | 2 ++ .../javascripts/notes/stores/actions.js | 8 +++--- app/helpers/issuables_helper.rb | 1 - .../projects/issues/_discussion.html.haml | 2 ++ 13 files changed, 63 insertions(+), 71 deletions(-) diff --git a/app/assets/javascripts/notes/components/issue_comment_form.vue b/app/assets/javascripts/notes/components/issue_comment_form.vue index 6761f15becc..5b8b7a67fa8 100644 --- a/app/assets/javascripts/notes/components/issue_comment_form.vue +++ b/app/assets/javascripts/notes/components/issue_comment_form.vue @@ -10,12 +10,12 @@ export default { data() { - const { getUserData, getIssueData } = this.$store.getters; + const { getUserData, getIssueData, getNotesData } = this.$store.getters; return { note: '', - markdownDocsUrl: getIssueData.markdownDocs, - quickActionsDocsUrl: getIssueData.quickActionsDocs, + markdownDocsUrl: getNotesData.markdownDocs, + quickActionsDocsUrl: getNotesData.quickActionsDocs, markdownPreviewUrl: getIssueData.preview_note_path, noteType: constants.COMMENT, issueState: getIssueData.state, @@ -89,7 +89,7 @@ this.handleError(); } } else { - this.discard(); + return Flash('Something went wrong while adding your comment. Please try again.'); } }) .catch(() => { @@ -126,9 +126,6 @@ setNoteType(type) { this.noteType = type; }, - handleError() { - Flash('Something went wrong while adding your comment. Please try again.'); - }, editMyLastNote() { if (this.note === '') { const myLastNoteId = $('.js-my-note').last().attr('id'); diff --git a/app/assets/javascripts/notes/components/issue_note.vue b/app/assets/javascripts/notes/components/issue_note.vue index d490578ce6f..49edac407dd 100644 --- a/app/assets/javascripts/notes/components/issue_note.vue +++ b/app/assets/javascripts/notes/components/issue_note.vue @@ -19,6 +19,7 @@ return { isEditing: false, isDeleting: false, + currentUserId: window.gon.current_user_id, }; }, components: { @@ -38,12 +39,12 @@ return { 'is-editing': this.isEditing, 'disabled-content': this.isDeleting, - 'js-my-note': this.author.id === window.gon.current_user_id, + 'js-my-note': this.author.id === this.currentUserId, target: this.targetNoteHash === this.noteAnchorId, }; }, canReportAsAbuse() { - return this.note.report_abuse_path && this.author.id !== window.gon.current_user_id; + return this.note.report_abuse_path && this.author.id !== this.currentUserId; }, noteAnchorId() { return `note_${this.note.id}`; @@ -59,8 +60,8 @@ this.isEditing = true; }, deleteHandler() { - const msg = 'Are you sure you want to delete this list?'; - const isConfirmed = confirm(msg); // eslint-disable-line + // eslint-disable-next-line no-alert + const isConfirmed = confirm('Are you sure you want to delete this list?'); if (isConfirmed) { this.isDeleting = true; @@ -88,17 +89,15 @@ this.updateNote(data) .then(() => { this.isEditing = false; + // TODO: this could be moved down, by setting a prop $(this.$refs.noteBody.$el).renderGFM(); }) .catch(() => Flash('Something went wrong while editing your comment. Please try again.')); }, - formCancelHandler(shouldConfirm) { - if (shouldConfirm && this.$refs.noteBody.$refs.noteForm.isDirty) { - const msg = 'Are you sure you want to cancel editing this comment?'; - const isConfirmed = confirm(msg); // eslint-disable-line - if (!isConfirmed) { - return; - } + formCancelHandler(shouldConfirm, isDirty) { + if (shouldConfirm && isDirty) { + // eslint-disable-next-line no-alert + if (!confirm('Are you sure you want to cancel editing this comment?')) return; } this.isEditing = false; @@ -135,7 +134,7 @@ :author="author" :created-at="note.created_at" :note-id="note.id" - actionText="commented" + action-text="commented" /> diff --git a/app/assets/javascripts/notes/components/issue_note_actions.vue b/app/assets/javascripts/notes/components/issue_note_actions.vue index f08081e3577..dd2c55073b4 100644 --- a/app/assets/javascripts/notes/components/issue_note_actions.vue +++ b/app/assets/javascripts/notes/components/issue_note_actions.vue @@ -53,6 +53,7 @@ emojiSmiling, emojiSmile, emojiSmiley, + currentUserId: window.gon.current_user_id, }; }, components: { @@ -60,13 +61,13 @@ }, computed: { shouldShowActionsDropdown() { - return window.gon.current_user_id && (this.canEdit || this.canReportAsAbuse); + return this.currentUserId && (this.canEdit || this.canReportAsAbuse); }, canAddAwardEmoji() { - return window.gon.current_user_id; + return this.currentUserId; }, - isAuthoredByMe() { - return this.authorId === window.gon.current_user_id; + isAuthoredByCurrentUser() { + return this.authorId === this.currentUserId }, }, }; @@ -82,7 +83,7 @@ award.user.id === this.myUserId); - - return isAwarded.length; + hasReactionByCurrentUser(awardList) { + return awardList.filter(award => award.user.id === this.myUserId).length; }, awardTitle(awardsList) { - const amIAwarded = this.amIAwarded(awardsList); - const TOOLTIP_NAME_COUNT = amIAwarded ? 9 : 10; + const hasReactionByCurrentUser = this.hasReactionByCurrentUser(awardsList); + const TOOLTIP_NAME_COUNT = hasReactionByCurrentUser ? 9 : 10; let awardList = awardsList; // Filter myself from list if I am awarded. - if (amIAwarded) { + if (hasReactionByCurrentUser) { awardList = awardList.filter(award => award.user.id !== this.myUserId); } @@ -129,7 +127,7 @@ const remainingAwardList = awardList.slice(TOOLTIP_NAME_COUNT, awardList.length); // Add myself to the begining of the list so title will start with You. - if (amIAwarded) { + if (hasReactionByCurrentUser) { namesToShow.unshift('You'); } diff --git a/app/assets/javascripts/notes/components/issue_note_body.vue b/app/assets/javascripts/notes/components/issue_note_body.vue index dee8bb0c7f9..c7dc146985b 100644 --- a/app/assets/javascripts/notes/components/issue_note_body.vue +++ b/app/assets/javascripts/notes/components/issue_note_body.vue @@ -51,11 +51,12 @@ }); } }, - handleFormUpdate() { - this.formUpdateHandler({ - note: this.$refs.noteForm.note, - }); + handleFormUpdate(note) { + this.$emit('handleFormUpdate', note); }, + formCancelHandler(shouldConfirm, isDirty) { + this.$emit('cancelFormEdition', shouldConfirm, isDirty); + } }, mounted() { this.renderGFM(); @@ -78,10 +79,11 @@ + :note-id="note.id" + />