2019-07-07 11:18:12 +05:30
|
|
|
import Vue from 'vue';
|
2023-05-27 22:25:52 +05:30
|
|
|
import VueApollo from 'vue-apollo';
|
2019-07-07 11:18:12 +05:30
|
|
|
import { mapActions, mapState, mapGetters } from 'vuex';
|
2023-05-27 22:25:52 +05:30
|
|
|
import { apolloProvider } from '~/graphql_shared/issuable_client';
|
|
|
|
|
2023-03-17 16:20:25 +05:30
|
|
|
import { renderGFM } from '~/behaviors/markdown/render_gfm';
|
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';
|
2023-03-04 22:38:38 +05:30
|
|
|
import notesEventHub from '~/notes/event_hub';
|
2020-10-24 23:57:45 +05:30
|
|
|
import discussionNavigator from '../notes/components/discussion_navigator.vue';
|
2022-10-11 01:57:18 +05:30
|
|
|
import NotesApp from '../notes/components/notes_app.vue';
|
2022-11-25 23:54:43 +05:30
|
|
|
import { getNotesFilterData } from '../notes/utils/get_notes_filter_data';
|
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 () => {
|
2023-03-17 16:20:25 +05:30
|
|
|
requestIdleCallback(
|
|
|
|
() => {
|
|
|
|
renderGFM(document.getElementById('diff-notes-app'));
|
|
|
|
},
|
|
|
|
{ timeout: 500 },
|
|
|
|
);
|
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
const el = document.getElementById('js-vue-mr-discussions');
|
|
|
|
if (!el) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
Vue.use(VueApollo);
|
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
const notesFilterProps = getNotesFilterData(el);
|
2023-04-23 21:23:45 +05:30
|
|
|
const notesDataset = el.dataset;
|
2022-11-25 23:54:43 +05:30
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
// eslint-disable-next-line no-new
|
|
|
|
new Vue({
|
2022-11-25 23:54:43 +05:30
|
|
|
el,
|
2019-07-07 11:18:12 +05:30
|
|
|
name: 'MergeRequestDiscussions',
|
|
|
|
components: {
|
2022-10-11 01:57:18 +05:30
|
|
|
NotesApp,
|
2019-07-07 11:18:12 +05:30
|
|
|
},
|
|
|
|
store,
|
2023-05-27 22:25:52 +05:30
|
|
|
apolloProvider,
|
2023-04-23 21:23:45 +05:30
|
|
|
provide: {
|
|
|
|
reportAbusePath: notesDataset.reportAbusePath,
|
2023-06-20 00:43:36 +05:30
|
|
|
newCommentTemplatePath: notesDataset.newCommentTemplatePath,
|
2023-04-23 21:23:45 +05:30
|
|
|
},
|
2019-07-07 11:18:12 +05:30
|
|
|
data() {
|
|
|
|
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
|
|
|
notesData: JSON.parse(notesDataset.notesData),
|
|
|
|
helpPagePath: notesDataset.helpPagePath,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
2023-03-04 22:38:38 +05:30
|
|
|
...mapGetters(['isNotesFetched']),
|
2019-07-07 11:18:12 +05:30
|
|
|
...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: {
|
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() {
|
2021-04-29 21:17:54 +05:30
|
|
|
this.setEndpoints(this.endpoints);
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
if (!this.isNotesFetched) {
|
|
|
|
notesEventHub.$emit('fetchNotesData');
|
|
|
|
}
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
this.fetchMrMetadata();
|
2019-07-07 11:18:12 +05:30
|
|
|
},
|
|
|
|
methods: {
|
2023-03-04 22:38:38 +05:30
|
|
|
...mapActions(['setEndpoints', 'fetchMrMetadata']),
|
2019-07-07 11:18:12 +05:30
|
|
|
},
|
|
|
|
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,
|
2022-11-25 23:54:43 +05:30
|
|
|
...notesFilterProps,
|
2019-10-12 21:52:04 +05:30
|
|
|
},
|
|
|
|
}),
|
|
|
|
]);
|
2019-07-07 11:18:12 +05:30
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|