BigW Consortium Gitlab

Commit 3343bf30 by Filipa Lacerda

[ci skip] Remove DOM querying for paths, save them in the store

parent d34c620f
<script> <script>
/* global Flash */ /* global Flash */
import { mapActions, mapGetters } from 'vuex'; import { mapActions } from 'vuex';
import userAvatarLink from '../../vue_shared/components/user_avatar/user_avatar_link.vue'; import userAvatarLink from '../../vue_shared/components/user_avatar/user_avatar_link.vue';
import markdownField from '../../vue_shared/components/markdown/field.vue'; import markdownField from '../../vue_shared/components/markdown/field.vue';
import issueNoteSignedOutWidget from './issue_note_signed_out_widget.vue'; import issueNoteSignedOutWidget from './issue_note_signed_out_widget.vue';
...@@ -10,18 +10,18 @@ ...@@ -10,18 +10,18 @@
export default { export default {
data() { data() {
const { create_note_path, state } = window.gl.issueData; const { getUserData, getIssueData } = this.$store.getters;
const { currentUserData } = window.gl;
return { return {
note: '', note: '',
markdownDocsUrl: '', markdownDocsUrl: getIssueData.markdownDocs,
quickActionsDocsUrl: null, quickActionsDocsUrl: getIssueData.quickActionsDocs,
markdownPreviewUrl: gl.issueData.preview_note_path, markdownPreviewUrl: getIssueData.preview_note_path,
noteType: constants.COMMENT, noteType: constants.COMMENT,
issueState: state, issueState: getIssueData.state,
endpoint: create_note_path, endpoint: getIssueData.create_note_path,
author: currentUserData, author: getUserData,
canUpdateIssue: getIssueData.current_user.can_update,
}; };
}, },
components: { components: {
...@@ -30,10 +30,6 @@ ...@@ -30,10 +30,6 @@
issueNoteSignedOutWidget, issueNoteSignedOutWidget,
}, },
computed: { computed: {
...mapGetters([
'getNotesDataByProp',
'getIssueDataByProp',
]),
isLoggedIn() { isLoggedIn() {
return window.gon.current_user_id; return window.gon.current_user_id;
}, },
...@@ -60,9 +56,6 @@ ...@@ -60,9 +56,6 @@
'js-note-target-reopen': !this.isIssueOpen, 'js-note-target-reopen': !this.isIssueOpen,
}; };
}, },
canUpdateIssue() {
return this.getIssueDataByProp(current_user).can_update;
},
}, },
methods: { methods: {
...mapActions([ ...mapActions([
...@@ -106,12 +99,12 @@ ...@@ -106,12 +99,12 @@
if (withIssueAction) { if (withIssueAction) {
if (this.isIssueOpen) { if (this.isIssueOpen) {
gl.issueData.state = constants.CLOSED;
this.issueState = constants.CLOSED; this.issueState = constants.CLOSED;
} else { } else {
gl.issueData.state = constants.REOPENED;
this.issueState =constants.REOPENED; this.issueState =constants.REOPENED;
} }
gl.issueData.state = this.issueState;
this.isIssueOpen = !this.isIssueOpen; this.isIssueOpen = !this.isIssueOpen;
// This is out of scope for the Notes Vue component. // This is out of scope for the Notes Vue component.
...@@ -139,7 +132,7 @@ ...@@ -139,7 +132,7 @@
editMyLastNote() { editMyLastNote() {
if (this.note === '') { if (this.note === '') {
const myLastNoteId = $('.js-my-note').last().attr('id'); const myLastNoteId = $('.js-my-note').last().attr('id');
debugger;
if (myLastNoteId) { if (myLastNoteId) {
eventHub.$emit('enterEditMode', { eventHub.$emit('enterEditMode', {
noteId: parseInt(myLastNoteId.replace('note_', ''), 10), noteId: parseInt(myLastNoteId.replace('note_', ''), 10),
...@@ -149,9 +142,6 @@ ...@@ -149,9 +142,6 @@
}, },
}, },
mounted() { mounted() {
this.markdownDocsUrl = this.getIssueDataByProp(markdownDocs);
this.quickActionsDocsUrl = this.getIssueDataByProp(quickActionsDocs);
eventHub.$on('issueStateChanged', (isClosed) => { eventHub.$on('issueStateChanged', (isClosed) => {
this.issueState = isClosed ? constants.CLOSED : constants.REOPENED; this.issueState = isClosed ? constants.CLOSED : constants.REOPENED;
}); });
......
<script> <script>
export default { export default {
data() { data() {
const { newSessionPath, registerPath } = this.$store.getters.notesData;
return { return {
signInLink: '#', signInLink: newSessionPath,
registerLink: registerPath,
}; };
}, },
mounted() {
const wrapper = document.querySelector('.js-notes-wrapper');
if (wrapper) {
this.signInLink = wrapper.dataset.newSessionPath;
}
},
}; };
</script> </script>
...@@ -20,7 +16,7 @@ ...@@ -20,7 +16,7 @@
Please Please
<a :href="signInLink">register</a> <a :href="signInLink">register</a>
or or
<a :href="signInLink">sign in</a> <a :href="registerLink">sign in</a>
to reply to reply
</div> </div>
</template> </template>
...@@ -25,6 +25,10 @@ ...@@ -25,6 +25,10 @@
type: Object, type: Object,
required: true, required: true,
}, },
userData: {
type: Object,
required: true,
},
}, },
store, store,
data() { data() {
...@@ -43,21 +47,21 @@ ...@@ -43,21 +47,21 @@
}, },
computed: { computed: {
...mapGetters([ ...mapGetters([
'notes',
'notesById',
'getNotesData',
'getNotesDataByProp', 'getNotesDataByProp',
'setLastFetchedAt',
'setTargetNoteHash',
]), ]),
}, },
methods: { methods: {
...mapGetters([
'getNotesDataByProp',
]),
...mapActions({ ...mapActions({
actionFetchNotes: 'fetchNotes', actionFetchNotes: 'fetchNotes',
poll: 'poll', poll: 'poll',
toggleAward: 'toggleAward', toggleAward: 'toggleAward',
scrollToNoteIfNeeded: 'scrollToNoteIfNeeded', scrollToNoteIfNeeded: 'scrollToNoteIfNeeded',
setNotesData: 'setNotesData' setNotesData: 'setNotesData',
setIssueData: 'setIssueData',
setUserData: 'setUserData',
}), }),
getComponentName(note) { getComponentName(note) {
if (note.isPlaceholderNote) { if (note.isPlaceholderNote) {
...@@ -75,7 +79,7 @@ ...@@ -75,7 +79,7 @@
return note.individual_note ? note.notes[0] : note; return note.individual_note ? note.notes[0] : note;
}, },
fetchNotes() { fetchNotes() {
this.actionFetchNotes(his.getNotesDataByProp('discussionsPath')) this.actionFetchNotes(this.getNotesDataByProp('discussionsPath'))
.then(() => { .then(() => {
this.isLoading = false; this.isLoading = false;
...@@ -126,6 +130,7 @@ ...@@ -126,6 +130,7 @@
created() { created() {
this.setNotesData(this.notesData); this.setNotesData(this.notesData);
this.setIssueData(this.issueData); this.setIssueData(this.issueData);
this.setUserData(this.userData)
}, },
mounted() { mounted() {
this.fetchNotes(); this.fetchNotes();
......
...@@ -15,6 +15,9 @@ document.addEventListener('DOMContentLoaded', () => new Vue({ ...@@ -15,6 +15,9 @@ document.addEventListener('DOMContentLoaded', () => new Vue({
notesData: { notesData: {
lastFetchedAt: notesDataset.lastFetchedAt, lastFetchedAt: notesDataset.lastFetchedAt,
discussionsPath: notesDataset.discussionsPath, discussionsPath: notesDataset.discussionsPath,
newSessionPath: notesDataset.newSessionPath,
registerPath: notesDataset.registerPath,
notesPath: notesDataset.notesPath,
}, },
}; };
}, },
...@@ -26,6 +29,7 @@ document.addEventListener('DOMContentLoaded', () => new Vue({ ...@@ -26,6 +29,7 @@ document.addEventListener('DOMContentLoaded', () => new Vue({
props: { props: {
issueData: this.issueData, issueData: this.issueData,
notesData: this.notesData, notesData: this.notesData,
userData: this.currentUserData,
}, },
}); });
}, },
......
export const notes = state => state.notes; export const notes = state => state.notes;
export const targetNoteHash = state => state.targetNoteHash; export const targetNoteHash = state => state.targetNoteHash;
export const getNotesData = state => state.notesData;
export const getNotesDataByProp = state => prop => state.notesData[prop]; export const getNotesDataByProp = state => prop => state.notesData[prop];
export const getIssueDataByProp = state => prop => state.notesData[prop];
export const getIssueData = state => state.issueData;
export const getIssueDataByProp = state => prop => state.issueData[prop];
export const getUserData = state => state.userData;
export const getUserDataByProp = state => prop => state.notesData[prop]; export const getUserDataByProp = state => prop => state.notesData[prop];
export const notesById = (state) => { export const notesById = (state) => {
......
...@@ -16,6 +16,7 @@ export default new Vuex.Store({ ...@@ -16,6 +16,7 @@ export default new Vuex.Store({
notesData: {}, notesData: {},
userData: {}, userData: {},
issueData: {}, issueData: {},
paths: {},
}, },
actions, actions,
getters, getters,
......
...@@ -69,7 +69,6 @@ export default { ...@@ -69,7 +69,6 @@ export default {
[types.SET_USER_DATA](state, data) { [types.SET_USER_DATA](state, data) {
state.userData = data; state.userData = data;
}, },
[types.SET_INITAL_NOTES](state, notes) { [types.SET_INITAL_NOTES](state, notes) {
state.notes = notes; state.notes = notes;
}, },
......
...@@ -5,8 +5,10 @@ ...@@ -5,8 +5,10 @@
%section %section
#js-vue-notes{ data: { discussions_path: discussions_namespace_project_issue_path(@project.namespace, @project, @issue, format: :json), #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'), new_session_path: new_session_path(:user, redirect_to_referer: 'yes'),
notes_path: '#{notes_url}?full_data=1', last_fetched_at: Time.now.to_i, notes_path: '#{notes_url}?full_data=1',
last_fetched_at: Time.now.to_i,
issue_data: serialize_issuable(@issue), issue_data: serialize_issuable(@issue),
current_user_data: UserSerializer.new.represent(current_user).to_json }} current_user_data: UserSerializer.new.represent(current_user).to_json }}
- content_for :page_specific_javascripts do - content_for :page_specific_javascripts do
......
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