Commit f67ff8e2 authored by Filipa Lacerda's avatar Filipa Lacerda

[ci skip] Removes use of window object in all components

Improves performance by removing emojis from data object
parent f62939e7
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
return { return {
isEditing: false, isEditing: false,
isDeleting: false, isDeleting: false,
currentUserId: window.gon.current_user_id,
}; };
}, },
components: { components: {
...@@ -31,6 +30,7 @@ ...@@ -31,6 +30,7 @@
computed: { computed: {
...mapGetters([ ...mapGetters([
'targetNoteHash', 'targetNoteHash',
'getUserData',
]), ]),
author() { author() {
return this.note.author; return this.note.author;
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
}; };
}, },
canReportAsAbuse() { canReportAsAbuse() {
return this.note.report_abuse_path && this.author.id !== this.currentUserId; return this.note.report_abuse_path && this.author.id !== this.getUserData.id;
}, },
noteAnchorId() { noteAnchorId() {
return `note_${this.note.id}`; return `note_${this.note.id}`;
......
<script> <script>
/* global Flash */ /* global Flash */
import { mapActions } from 'vuex'; import { mapActions, mapGetters } from 'vuex';
import emojiSmiling from 'icons/_emoji_slightly_smiling_face.svg'; import emojiSmiling from 'icons/_emoji_slightly_smiling_face.svg';
import emojiSmile from 'icons/_emoji_smile.svg'; import emojiSmile from 'icons/_emoji_smile.svg';
import emojiSmiley from 'icons/_emoji_smiley.svg'; import emojiSmiley from 'icons/_emoji_smiley.svg';
...@@ -30,18 +30,10 @@ ...@@ -30,18 +30,10 @@
directives: { directives: {
tooltip, tooltip,
}, },
data() {
const userId = window.gon.current_user_id;
return {
emojiSmiling,
emojiSmile,
emojiSmiley,
canAward: !!userId,
myUserId: userId,
};
},
computed: { computed: {
...mapGetters([
'getUserData',
]),
// `this.awards` is an array with emojis but they are not grouped by emoji name. See below. // `this.awards` is an array with emojis but they are not grouped by emoji name. See below.
// [ { name: foo, user: user1 }, { name: bar, user: user1 }, { name: foo, user: user2 } ] // [ { name: foo, user: user1 }, { name: bar, user: user1 }, { name: foo, user: user2 } ]
// This method will group emojis by their name as an Object. See below. // This method will group emojis by their name as an Object. See below.
...@@ -76,7 +68,10 @@ ...@@ -76,7 +68,10 @@
return Object.assign({}, orderedAwards, awards); return Object.assign({}, orderedAwards, awards);
}, },
isAuthoredByMe() { isAuthoredByMe() {
return this.noteAuthorId === window.gon.current_user_id; return this.noteAuthorId === this.getUserData.id;
},
isLoggedIn() {
return this.getUserData.id;
}, },
}, },
methods: { methods: {
...@@ -95,17 +90,16 @@ ...@@ -95,17 +90,16 @@
canInteractWithEmoji(awardList, awardName) { canInteractWithEmoji(awardList, awardName) {
let isAllowed = true; let isAllowed = true;
const restrictedEmojis = ['thumbsup', 'thumbsdown']; const restrictedEmojis = ['thumbsup', 'thumbsdown'];
const { myUserId, noteAuthorId } = this;
// Users can not add :+1: and :-1: to their own notes // Users can not add :+1: and :-1: to their own notes
if (myUserId === noteAuthorId && restrictedEmojis.indexOf(awardName) > -1) { if (this.getUserData.id === this.noteAuthorId && restrictedEmojis.indexOf(awardName) > -1) {
isAllowed = false; isAllowed = false;
} }
return this.canAward && isAllowed; return this.getUserData.id && isAllowed;
}, },
hasReactionByCurrentUser(awardList) { hasReactionByCurrentUser(awardList) {
return awardList.filter(award => award.user.id === this.myUserId).length; return awardList.filter(award => award.user.id === this.getUserData.id).length;
}, },
awardTitle(awardsList) { awardTitle(awardsList) {
const hasReactionByCurrentUser = this.hasReactionByCurrentUser(awardsList); const hasReactionByCurrentUser = this.hasReactionByCurrentUser(awardsList);
...@@ -114,7 +108,7 @@ ...@@ -114,7 +108,7 @@
// Filter myself from list if I am awarded. // Filter myself from list if I am awarded.
if (hasReactionByCurrentUser) { if (hasReactionByCurrentUser) {
awardList = awardList.filter(award => award.user.id !== this.myUserId); awardList = awardList.filter(award => award.user.id !== this.getUserData.id);
} }
// Get only 9-10 usernames to show in tooltip text. // Get only 9-10 usernames to show in tooltip text.
...@@ -157,6 +151,11 @@ ...@@ -157,6 +151,11 @@
.catch(() => Flash('Something went wrong on our end.')); .catch(() => Flash('Something went wrong on our end.'));
}, },
}, },
created() {
this.emojiSmiling = emojiSmiling;
this.emojiSmile = this.emojiSmile;
this.emojiSmiley = this.emojiSmiley;
},
}; };
</script> </script>
...@@ -179,7 +178,7 @@ ...@@ -179,7 +178,7 @@
</span> </span>
</button> </button>
<div <div
v-if="canAward" v-if="isLoggedIn"
class="award-menu-holder"> class="award-menu-holder">
<button <button
v-tooltip v-tooltip
......
import Vue from 'vue'; import Vue from 'vue';
import issueNotesApp from './components/issue_notes_app.vue'; import issueNotesApp from './components/issue_notes_app.vue';
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => new Vue({
const vm = new Vue({ el: '#js-vue-notes',
el: '#js-vue-notes', components: {
components: { issueNotesApp,
issueNotesApp, },
}, data() {
data() { const notesDataset = document.getElementById('js-vue-notes').dataset;
const notesDataset = document.getElementById('js-vue-notes').dataset;
return {
issueData: JSON.parse(notesDataset.issueData),
currentUserData: JSON.parse(notesDataset.currentUserData),
notesData: {
lastFetchedAt: notesDataset.lastFetchedAt,
discussionsPath: notesDataset.discussionsPath,
newSessionPath: notesDataset.newSessionPath,
registerPath: notesDataset.registerPath,
notesPath: notesDataset.notesPath,
markdownDocs: notesDataset.markdownDocs,
quickActionsDocs: notesDataset.quickActionsDocs,
},
};
},
render(createElement) {
return createElement('issue-notes-app', {
attrs: {
ref: 'notes',
},
props: {
issueData: this.issueData,
notesData: this.notesData,
userData: this.currentUserData,
},
});
},
});
// This is used in note_polling_spec
window.issueNotes = {
refresh() {
vm.$refs.notes.$store.dispatch('poll');
},
};
});
return {
issueData: JSON.parse(notesDataset.issueData),
currentUserData: JSON.parse(notesDataset.currentUserData),
notesData: {
lastFetchedAt: notesDataset.lastFetchedAt,
discussionsPath: notesDataset.discussionsPath,
newSessionPath: notesDataset.newSessionPath,
registerPath: notesDataset.registerPath,
notesPath: notesDataset.notesPath,
markdownDocs: notesDataset.markdownDocs,
quickActionsDocs: notesDataset.quickActionsDocs,
},
};
},
render(createElement) {
return createElement('issue-notes-app', {
attrs: {
ref: 'notes',
},
props: {
issueData: this.issueData,
notesData: this.notesData,
userData: this.currentUserData,
},
});
},
}));
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