debian-mirror-gitlab/app/assets/javascripts/mr_notes/init_notes.js

90 lines
2.9 KiB
JavaScript
Raw Normal View History

2019-07-07 11:18:12 +05:30
import $ from 'jquery';
import Vue from 'vue';
import { mapActions, mapState, mapGetters } from 'vuex';
import store from 'ee_else_ce/mr_notes/stores';
import notesApp from '../notes/components/notes_app.vue';
2019-10-12 21:52:04 +05:30
import discussionKeyboardNavigator from '../notes/components/discussion_keyboard_navigator.vue';
2020-03-09 13:42:32 +05:30
import initWidget from '../vue_merge_request_widget';
2019-07-07 11:18:12 +05:30
export default () => {
// eslint-disable-next-line no-new
new Vue({
el: '#js-vue-mr-discussions',
name: 'MergeRequestDiscussions',
components: {
notesApp,
},
store,
data() {
const notesDataset = document.getElementById('js-vue-mr-discussions').dataset;
const noteableData = JSON.parse(notesDataset.noteableData);
noteableData.noteableType = notesDataset.noteableType;
noteableData.targetType = notesDataset.targetType;
return {
noteableData,
currentUserData: JSON.parse(notesDataset.currentUserData),
notesData: JSON.parse(notesDataset.notesData),
helpPagePath: notesDataset.helpPagePath,
};
},
computed: {
...mapGetters(['discussionTabCounter']),
...mapState({
activeTab: state => state.page.activeTab,
}),
2020-03-09 13:42:32 +05:30
isShowTabActive() {
return this.activeTab === 'show';
},
2019-07-07 11:18:12 +05:30
},
watch: {
discussionTabCounter() {
this.updateDiscussionTabCounter();
},
2020-03-09 13:42:32 +05:30
isShowTabActive: {
handler(newVal) {
if (newVal) {
initWidget();
}
},
immediate: true,
},
2019-07-07 11:18:12 +05:30
},
created() {
this.setActiveTab(window.mrTabs.getCurrentAction());
},
mounted() {
this.notesCountBadge = $('.issuable-details').find('.notes-tab .badge');
$(document).on('visibilitychange', this.updateDiscussionTabCounter);
window.mrTabs.eventHub.$on('MergeRequestTabChange', this.setActiveTab);
},
beforeDestroy() {
$(document).off('visibilitychange', this.updateDiscussionTabCounter);
window.mrTabs.eventHub.$off('MergeRequestTabChange', this.setActiveTab);
},
methods: {
...mapActions(['setActiveTab']),
updateDiscussionTabCounter() {
this.notesCountBadge.text(this.discussionTabCounter);
},
},
render(createElement) {
2019-10-12 21:52:04 +05:30
// NOTE: Even though `discussionKeyboardNavigator` is added to the `notes-app`,
// it adds a global key listener so it works on the diffs tab as well.
// If we create a single Vue app for all of the MR tabs, we should move this
// up the tree, to the root.
2020-03-09 13:42:32 +05:30
return createElement(discussionKeyboardNavigator, [
2019-10-12 21:52:04 +05:30
createElement('notes-app', {
props: {
noteableData: this.noteableData,
notesData: this.notesData,
userData: this.currentUserData,
2020-03-09 13:42:32 +05:30
shouldShow: this.isShowTabActive,
2019-10-12 21:52:04 +05:30
helpPagePath: this.helpPagePath,
},
}),
]);
2019-07-07 11:18:12 +05:30
},
});
};