2019-07-07 11:18:12 +05:30
|
|
|
import $ from 'jquery';
|
|
|
|
import Vue from 'vue';
|
|
|
|
import { mapActions, mapState, mapGetters } from 'vuex';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { parseBoolean } from '~/lib/utils/common_utils';
|
2020-06-23 00:09:42 +05:30
|
|
|
import store from '~/mr_notes/stores';
|
2020-10-24 23:57:45 +05:30
|
|
|
import discussionNavigator from '../notes/components/discussion_navigator.vue';
|
2021-03-11 19:13:27 +05:30
|
|
|
import notesApp from '../notes/components/notes_app.vue';
|
2020-03-13 15:44:24 +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;
|
2020-10-24 23:57:45 +05:30
|
|
|
noteableData.discussion_locked = parseBoolean(notesDataset.isLocked);
|
2019-07-07 11:18:12 +05:30
|
|
|
|
|
|
|
return {
|
|
|
|
noteableData,
|
2021-04-29 21:17:54 +05:30
|
|
|
endpoints: {
|
|
|
|
metadata: notesDataset.endpointMetadata,
|
|
|
|
},
|
2019-07-07 11:18:12 +05:30
|
|
|
currentUserData: JSON.parse(notesDataset.currentUserData),
|
|
|
|
notesData: JSON.parse(notesDataset.notesData),
|
|
|
|
helpPagePath: notesDataset.helpPagePath,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
...mapGetters(['discussionTabCounter']),
|
|
|
|
...mapState({
|
2021-03-08 18:12:59 +05:30
|
|
|
activeTab: (state) => state.page.activeTab,
|
2019-07-07 11:18:12 +05:30
|
|
|
}),
|
2020-03-13 15:44:24 +05:30
|
|
|
isShowTabActive() {
|
|
|
|
return this.activeTab === 'show';
|
|
|
|
},
|
2019-07-07 11:18:12 +05:30
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
discussionTabCounter() {
|
2022-08-27 11:52:29 +05:30
|
|
|
if (window.gon?.features?.paginatedMrDiscussions) {
|
|
|
|
if (this.$store.state.notes.doneFetchingBatchDiscussions) {
|
|
|
|
this.updateDiscussionTabCounter();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.updateDiscussionTabCounter();
|
|
|
|
}
|
2019-07-07 11:18:12 +05:30
|
|
|
},
|
2020-03-13 15:44:24 +05:30
|
|
|
isShowTabActive: {
|
|
|
|
handler(newVal) {
|
|
|
|
if (newVal) {
|
|
|
|
initWidget();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
immediate: true,
|
|
|
|
},
|
2019-07-07 11:18:12 +05:30
|
|
|
},
|
|
|
|
created() {
|
|
|
|
this.setActiveTab(window.mrTabs.getCurrentAction());
|
2021-04-29 21:17:54 +05:30
|
|
|
this.setEndpoints(this.endpoints);
|
|
|
|
|
|
|
|
this.fetchMrMetadata();
|
2019-07-07 11:18:12 +05:30
|
|
|
},
|
|
|
|
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: {
|
2021-04-29 21:17:54 +05:30
|
|
|
...mapActions(['setActiveTab', 'setEndpoints', 'fetchMrMetadata']),
|
2019-07-07 11:18:12 +05:30
|
|
|
updateDiscussionTabCounter() {
|
|
|
|
this.notesCountBadge.text(this.discussionTabCounter);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
render(createElement) {
|
2020-10-24 23:57:45 +05:30
|
|
|
// NOTE: Even though `discussionNavigator` is added to the `notes-app`,
|
2019-10-12 21:52:04 +05:30
|
|
|
// 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-10-24 23:57:45 +05:30
|
|
|
return createElement(discussionNavigator, [
|
2019-10-12 21:52:04 +05:30
|
|
|
createElement('notes-app', {
|
|
|
|
props: {
|
|
|
|
noteableData: this.noteableData,
|
|
|
|
notesData: this.notesData,
|
|
|
|
userData: this.currentUserData,
|
2020-03-13 15:44:24 +05:30
|
|
|
shouldShow: this.isShowTabActive,
|
2019-10-12 21:52:04 +05:30
|
|
|
helpPagePath: this.helpPagePath,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
]);
|
2019-07-07 11:18:12 +05:30
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|