summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/ide/components/merge_requests/dropdown.vue
blob: 1bcd550c7130aaaa655735301195c3a450bbdd60 (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
<script>
import { mapActions, mapState } from 'vuex';
import Tabs from '../../../vue_shared/components/tabs/tabs';
import Tab from '../../../vue_shared/components/tabs/tab.vue';
import List from './list.vue';
import { scopes } from '../../stores/modules/merge_requests/constants';

export default {
  components: {
    Tabs,
    Tab,
    List,
  },
  data() {
    return {
      activeTabIndex: 0,
    };
  },
  computed: {
    ...mapState('mergeRequests', ['isLoading', 'mergeRequests']),
    ...mapState(['currentMergeRequestId']),
    tabScope() {
      return this.activeTabIndex === 0 ? scopes.createdByMe : scopes.assignedToMe;
    },
  },
  mounted() {
    this.fetchMergeRequests();
  },
  methods: {
    ...mapActions('mergeRequests', ['fetchMergeRequests', 'setScope']),
    updateActiveTab(index) {
      this.activeTabIndex = index;

      this.setScope(this.tabScope);
      this.fetchMergeRequests();
    },
  },
};
</script>

<template>
  <div class="dropdown-menu ide-merge-requests-dropdown">
    <tabs
      stop-propagation
      @changed="updateActiveTab"
    >
      <tab
        :title="__('Created by me')"
        active
      >
        <list
          v-if="activeTabIndex === 0"
          :is-loading="isLoading"
          :items="mergeRequests"
          :current-id="currentMergeRequestId"
          :empty-text="__('You have not created any merge requests')"
          @search="fetchMergeRequests"
        />
      </tab>
      <tab :title="__('Assigned to me')">
        <list
          v-if="activeTabIndex === 1"
          :is-loading="isLoading"
          :items="mergeRequests"
          :current-id="currentMergeRequestId"
          :empty-text="__('You do not have any assigned merge requests')"
          @search="fetchMergeRequests"
        />
      </tab>
    </tabs>
  </div>
</template>

<style scoped>
.dropdown-menu {
  width: 350px;
  padding: 0;
  max-height: initial !important;
}
</style>