summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/mr_notes/index.js
blob: d690e9ccd508dc9725c06cf20d4d515199cb03b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import Vue from 'vue';
import Vuex, { mapActions, mapGetters } from 'vuex';
import notesApp from '../notes/components/notes_app.vue';
import diffsApp from '../diffs/components/app.vue';
import discussionCounter from '../notes/components/discussion_counter.vue';
import notesStoreConfig from '../notes/stores';
import diffsStoreConfig from '../diffs/store';
import mrPageStoreConfig from './stores';
import MergeRequest from '../merge_request';

Vue.use(Vuex);

const store = new Vuex.Store({
  modules: {
    page: mrPageStoreConfig,
    notes: notesStoreConfig,
  },
});

export default function initMrNotes() {
  const mrShowNode = document.querySelector('.merge-request');
  window.mergeRequest = new MergeRequest({
    action: mrShowNode.dataset.mrAction,
  });

  // 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;

      return {
        noteableData: JSON.parse(notesDataset.noteableData),
        currentUserData: JSON.parse(notesDataset.currentUserData),
        notesData: JSON.parse(notesDataset.notesData),
      };
    },
    computed: {
      ...mapGetters(['activeTab']),
    },
    mounted() {
      this.setActiveTab(window.mrTabs.getCurrentAction());

      window.mrTabs.eventHub.$on('MergeRequestTabChange', tab => {
        this.setActiveTab(tab);
      });
    },
    methods: {
      ...mapActions(['setActiveTab']),
    },
    render(createElement) {
      return createElement('notes-app', {
        props: {
          noteableData: this.noteableData,
          notesData: this.notesData,
          userData: this.currentUserData,
          shouldShow: this.activeTab === 'show',
        },
      });
    },
  });

  // eslint-disable-next-line no-new
  new Vue({
    el: '#js-vue-discussion-counter',
    name: 'DiscussionCounter',
    components: {
      discussionCounter,
    },
    store,
    render(createElement) {
      return createElement('discussion-counter');
    },
  });
}