Welcome to mirror list, hosted at ThFree Co, Russian Federation.

groups_list.vue « add_namespace_modal « components « subscriptions « jira_connect « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fb74306afc061e098a3951e1f735818ccdbbc25c (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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<script>
// eslint-disable-next-line no-restricted-imports
import { mapState } from 'vuex';
import { GlLoadingIcon, GlPagination, GlAlert, GlSearchBoxByType } from '@gitlab/ui';
import { fetchGroups } from '~/jira_connect/subscriptions/api';
import {
  DEFAULT_GROUPS_PER_PAGE,
  MINIMUM_SEARCH_TERM_LENGTH,
} from '~/jira_connect/subscriptions/constants';
import { ACCESS_LEVEL_MAINTAINER_INTEGER } from '~/access_level/constants';
import { parseIntPagination, normalizeHeaders } from '~/lib/utils/common_utils';
import { s__ } from '~/locale';
import GroupsListItem from './groups_list_item.vue';

export default {
  components: {
    GlLoadingIcon,
    GlPagination,
    GlAlert,
    GlSearchBoxByType,
    GroupsListItem,
  },
  inject: {
    groupsPath: {
      default: '',
    },
  },
  data() {
    return {
      groups: [],
      isLoadingInitial: true,
      isLoadingMore: false,
      page: 1,
      totalItems: 0,
      errorMessage: null,
      userSearchTerm: '',
      searchValue: '',
    };
  },
  computed: {
    ...mapState(['accessToken', 'currentUser']),
    showPagination() {
      return this.totalItems > this.$options.DEFAULT_GROUPS_PER_PAGE && this.groups.length > 0;
    },
    isAdmin() {
      return Boolean(this.currentUser.is_admin);
    },
  },
  mounted() {
    return this.loadGroups().finally(() => {
      this.isLoadingInitial = false;
    });
  },
  methods: {
    loadGroups() {
      this.isLoadingMore = true;
      return fetchGroups(
        this.groupsPath,
        {
          minAccessLevel: this.isAdmin ? undefined : ACCESS_LEVEL_MAINTAINER_INTEGER,
          page: this.page,
          perPage: this.$options.DEFAULT_GROUPS_PER_PAGE,
          search: this.searchValue,
        },
        this.accessToken,
      )
        .then((response) => {
          const { page, total } = parseIntPagination(normalizeHeaders(response.headers));
          this.page = page;
          this.totalItems = total;
          this.groups = response.data;
        })
        .catch(() => {
          this.errorMessage = s__('JiraConnect|Failed to load groups. Please try again.');
        })
        .finally(() => {
          this.isLoadingMore = false;
        });
    },
    onGroupSearch(userSearchTerm = '') {
      this.userSearchTerm = userSearchTerm;

      // fetchGroups returns no results for search terms 0 < {length} < 3.
      // The desired UX is to return the unfiltered results for searches {length} < 3.
      // Here, we set the search to an empty string '' if {length} < 3
      const newSearchValue =
        this.userSearchTerm.length < MINIMUM_SEARCH_TERM_LENGTH ? '' : this.userSearchTerm;

      // don't fetch new results if the search value didn't change.
      if (newSearchValue === this.searchValue) {
        return;
      }

      // reset the page.
      this.page = 1;
      this.searchValue = newSearchValue;
      this.loadGroups();
    },
  },
  DEFAULT_GROUPS_PER_PAGE,
};
</script>

<template>
  <div>
    <gl-alert v-if="errorMessage" class="gl-mb-5" variant="danger" @dismiss="errorMessage = null">
      {{ errorMessage }}
    </gl-alert>

    <gl-search-box-by-type
      class="gl-mb-3"
      debounce="500"
      :placeholder="__('Search groups')"
      :is-loading="isLoadingMore"
      :value="userSearchTerm"
      @input="onGroupSearch"
    />

    <p v-if="isAdmin" class="gl-mb-3">
      {{ s__('JiraConnect|Not seeing your groups? Only groups you have access to appear here.') }}
    </p>
    <p v-else class="gl-mb-3">
      {{
        s__(
          'JiraConnect|Not seeing your groups? Only groups you have at least the Maintainer role for appear here.',
        )
      }}
    </p>

    <gl-loading-icon v-if="isLoadingInitial" size="lg" />
    <div v-else-if="groups.length === 0" class="gl-text-center">
      <h5 class="gl-mt-5">{{ s__('JiraConnect|No groups found.') }}</h5>
    </div>
    <ul
      v-else
      class="gl-list-style-none gl-pl-0 gl-border-t-1 gl-border-t-solid gl-border-t-gray-100"
      :class="{ 'gl-opacity-5': isLoadingMore }"
      data-testid="groups-list"
    >
      <groups-list-item
        v-for="group in groups"
        :key="group.id"
        :group="group"
        :disabled="isLoadingMore"
        @error="errorMessage = $event"
      />
    </ul>

    <div class="gl-display-flex gl-justify-content-center gl-mt-5">
      <gl-pagination
        v-if="showPagination"
        v-model="page"
        class="gl-mb-0"
        :per-page="$options.DEFAULT_GROUPS_PER_PAGE"
        :total-items="totalItems"
        @input="loadGroups"
      />
    </div>
  </div>
</template>