summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/jira_connect/components/groups_list.vue
blob: eeddd32addcdccc9339baf978153c6b72c593113 (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
82
83
84
85
86
87
88
<script>
import { GlTabs, GlTab, GlLoadingIcon, GlPagination } from '@gitlab/ui';
import { s__ } from '~/locale';
import { parseIntPagination, normalizeHeaders } from '~/lib/utils/common_utils';
import { fetchGroups } from '~/jira_connect/api';
import { defaultPerPage } from '~/jira_connect/constants';
import GroupsListItem from './groups_list_item.vue';

export default {
  components: {
    GlTabs,
    GlTab,
    GlLoadingIcon,
    GlPagination,
    GroupsListItem,
  },
  inject: {
    groupsPath: {
      default: '',
    },
  },
  data() {
    return {
      groups: [],
      isLoading: false,
      page: 1,
      perPage: defaultPerPage,
      totalItems: 0,
    };
  },
  mounted() {
    this.loadGroups();
  },
  methods: {
    loadGroups() {
      this.isLoading = true;

      fetchGroups(this.groupsPath, {
        page: this.page,
        perPage: this.perPage,
      })
        .then((response) => {
          const { page, total } = parseIntPagination(normalizeHeaders(response.headers));
          this.page = page;
          this.totalItems = total;
          this.groups = response.data;
        })
        .catch(() => {
          // eslint-disable-next-line no-alert
          alert(s__('Integrations|Failed to load namespaces. Please try again.'));
        })
        .finally(() => {
          this.isLoading = false;
        });
    },
  },
};
</script>

<template>
  <gl-tabs>
    <gl-tab :title="__('Groups and subgroups')" class="gl-pt-3">
      <gl-loading-icon v-if="isLoading" size="md" />
      <div v-else-if="groups.length === 0" class="gl-text-center">
        <h5>{{ s__('Integrations|No available namespaces.') }}</h5>
        <p class="gl-mt-5">
          {{
            s__('Integrations|You must have owner or maintainer permissions to link namespaces.')
          }}
        </p>
      </div>
      <ul v-else class="gl-list-style-none gl-pl-0">
        <groups-list-item v-for="group in groups" :key="group.id" :group="group" />
      </ul>

      <div class="gl-display-flex gl-justify-content-center gl-mt-5">
        <gl-pagination
          v-if="totalItems > perPage && groups.length > 0"
          v-model="page"
          class="gl-mb-0"
          :per-page="perPage"
          :total-items="totalItems"
          @input="loadGroups"
        />
      </div>
    </gl-tab>
  </gl-tabs>
</template>