Skip to content
Snippets Groups Projects
Commit 7a251207 authored by Filipa Lacerda's avatar Filipa Lacerda
Browse files

[ci skip] Emit events up to prevent accessing refs of refs

parent b45b604d
No related branches found
No related tags found
No related merge requests found
Showing
with 63 additions and 71 deletions
Loading
Loading
@@ -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,
Loading
Loading
@@ -89,7 +89,7 @@
this.handleError();
}
} else {
this.discard();
return Flash('Something went wrong while adding your comment. Please try again.');
}
})
.catch(() => {
Loading
Loading
@@ -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');
Loading
Loading
Loading
Loading
@@ -19,6 +19,7 @@
return {
isEditing: false,
isDeleting: false,
currentUserId: window.gon.current_user_id,
};
},
components: {
Loading
Loading
@@ -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}`;
Loading
Loading
@@ -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;
Loading
Loading
@@ -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;
Loading
Loading
@@ -135,7 +134,7 @@
:author="author"
:created-at="note.created_at"
:note-id="note.id"
actionText="commented"
action-text="commented"
/>
<issue-note-actions
:author-id="author.id"
Loading
Loading
@@ -153,8 +152,8 @@
:note="note"
:can-edit="note.current_user.can_edit"
:is-editing="isEditing"
:form-update-handler="formUpdateHandler"
:form-cancel-handler="formCancelHandler"
@handleFormUpdate="formUpdateHandler"
@cancelFormEdition="formCancelHandler"
ref="noteBody"
/>
</div>
Loading
Loading
Loading
Loading
@@ -53,6 +53,7 @@
emojiSmiling,
emojiSmile,
emojiSmiley,
currentUserId: window.gon.current_user_id,
};
},
components: {
Loading
Loading
@@ -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
},
},
};
Loading
Loading
@@ -82,7 +83,7 @@
<a
v-tooltip
v-if="canAddAwardEmoji"
:class="{ 'js-user-authored': isAuthoredByMe }"
:class="{ 'js-user-authored': isAuthoredByCurrentUser }"
class="note-action-button note-emoji-button js-add-award js-note-emoji"
data-position="right"
href="#"
Loading
Loading
Loading
Loading
@@ -91,7 +91,7 @@
},
getAwardClassBindings(awardList, awardName) {
return {
active: this.amIAwarded(awardList),
active: this.hasReactionByCurrentUser(awardList),
disabled: !this.canInteractWithEmoji(awardList, awardName),
};
},
Loading
Loading
@@ -107,18 +107,16 @@
 
return this.canAward && isAllowed;
},
amIAwarded(awardList) {
const isAwarded = awardList.filter(award => 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);
}
 
Loading
Loading
@@ -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');
}
 
Loading
Loading
Loading
Loading
@@ -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();
Loading
Loading
@@ -78,10 +79,11 @@
<issue-note-form
v-if="isEditing"
ref="noteForm"
:update-handler="handleFormUpdate"
:cancel-handler="formCancelHandler"
@handleFormUpdate="handleFormUpdate"
@cancelFormEdition="formCancelHandler"
:note-body="noteBody"
:note-id="note.id" />
:note-id="note.id"
/>
<textarea
v-if="canEdit"
v-model="note.note"
Loading
Loading
@@ -91,12 +93,14 @@
v-if="note.last_edited_by"
:edited-at="note.last_edited_at"
:edited-by="note.last_edited_by"
actionText="Edited" />
actionText="Edited"
/>
<issue-note-awards-list
v-if="note.award_emoji.length"
:note-id="note.id"
:note-author-id="note.author.id"
:awards="note.award_emoji"
:toggle-award-path="note.toggle_award_path" />
:toggle-award-path="note.toggle_award_path"
/>
</div>
</template>
Loading
Loading
@@ -13,14 +13,6 @@
type: Number,
required: false,
},
updateHandler: {
type: Function,
required: true,
},
cancelHandler: {
type: Function,
required: true,
},
saveButtonTitle: {
type: String,
required: false,
Loading
Loading
@@ -42,18 +34,13 @@
markdownField,
},
computed: {
isDirty() {
return this.initialNote !== this.note;
},
noteHash() {
return `#note_${this.noteId}`;
},
},
methods: {
handleUpdate() {
this.updateHandler({
note: this.note,
});
this.$emit('handleFormUpdate', note);
},
editMyLastNote() {
if (this.note === '') {
Loading
Loading
@@ -67,6 +54,10 @@
}
}
},
cancelHandler(shouldConfirm = false) {
// Sends information about confirm message and if the textarea has changed
this.$emit('cancelFormEdition', shouldConfirm, this.initialNote !== this.note);
}
},
mounted() {
this.$refs.textarea.focus();
Loading
Loading
@@ -95,7 +86,9 @@
rel="noopener noreferrer">updated comment</a>
to ensure information is not lost.
</div>
<form class="edit-note common-note-form">
<form
@submit="handleUpdate"
class="edit-note common-note-form">
<markdown-field
:markdown-preview-url="markdownPreviewUrl"
:markdown-docs="markdownDocsUrl"
Loading
Loading
@@ -118,8 +111,7 @@
</markdown-field>
<div class="note-form-actions clearfix">
<button
@click="handleUpdate"
type="button"
type="submit"
class="btn btn-nr btn-save">
{{saveButtonTitle}}
</button>
Loading
Loading
Loading
Loading
@@ -93,7 +93,7 @@
@click="updateTargetNoteHash">
<time-ago-tooltip
:time="createdAt"
tooltipPlacement="bottom"
tooltip-placement="bottom"
/>
</a>
</span>
Loading
Loading
Loading
Loading
@@ -47,13 +47,11 @@
},
computed: {
...mapGetters([
'notes',
'getNotesDataByProp',
]),
},
methods: {
...mapGetters([
'getNotesDataByProp',
]),
...mapActions({
actionFetchNotes: 'fetchNotes',
poll: 'poll',
Loading
Loading
Loading
Loading
@@ -14,7 +14,7 @@
<li class="note system-note timeline-entry being-posted fade-in-half">
<div class="timeline-entry-inner">
<div class="timeline-content">
<i>{{note.body}}</i>
<em>{{note.body}}</em>
</div>
</div>
</li>
Loading
Loading
Loading
Loading
@@ -18,6 +18,8 @@ document.addEventListener('DOMContentLoaded', () => new Vue({
newSessionPath: notesDataset.newSessionPath,
registerPath: notesDataset.registerPath,
notesPath: notesDataset.notesPath,
markdownDocs: notesDataset.markdownDocs,
quickActionsDocs: notesDataset.quickActionsDocs,
},
};
},
Loading
Loading
Loading
Loading
@@ -175,17 +175,17 @@ export const toggleAward = ({ commit, getters, dispatch }, data) => {
constants.EMOJI_THUMBSUP;
 
const targetNote = getters.notesById[noteId];
let noteHasAward = false;
let noteHasAwardByCurrentUser = false;
 
targetNote.award_emoji.forEach((a) => {
if (a.name === counterAward && a.user.id === window.gon.current_user_id) {
noteHasAward = true;
noteHasAwardByCurrentUser = true;
}
});
 
if (noteHasAward) {
if (noteHasAwardByCurrentUser) {
Object.assign(data, { awardName: counterAward });
Object.assign(data, { kipMutalityCheck: true });
Object.assign(data, { skipMutalityCheck: true });
 
dispatch(types.TOGGLE_AWARD, data);
}
Loading
Loading
Loading
Loading
@@ -214,7 +214,6 @@ module IssuablesHelper
initialDescriptionHtml: markdown_field(issuable, :description),
initialDescriptionText: issuable.description,
initialTaskStatus: issuable.task_status,
quickActionsDocs: help_page_path('user/project/quick_actions'),
}
 
data.merge!(updated_at_by(issuable))
Loading
Loading
Loading
Loading
@@ -7,6 +7,8 @@
#js-vue-notes{ data: { discussions_path: discussions_namespace_project_issue_path(@project.namespace, @project, @issue, format: :json),
register_path: "#{new_session_path(:user, redirect_to_referer: 'yes')}#register-pane",
new_session_path: new_session_path(:user, redirect_to_referer: 'yes'),
markdown_docs: help_page_path('user/markdown'),
quick_actions_docs: help_page_path('user/project/quick_actions'),
notes_path: '#{notes_url}?full_data=1',
last_fetched_at: Time.now.to_i,
issue_data: serialize_issuable(@issue),
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment