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

app.vue « components « users « admin « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b0caffb6ca651d2064cb76d0c49c0903ca53e9f0 (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
<script>
import { createAlert } from '~/alert';
import { s__ } from '~/locale';
import { convertNodeIdsFromGraphQLIds } from '~/graphql_shared/utils';
import UsersTable from '~/vue_shared/components/users_table/users_table.vue';
import getUsersGroupCountsQuery from '../graphql/queries/get_users_group_counts.query.graphql';
import UserActions from './user_actions.vue';

export default {
  components: {
    UsersTable,
    UserActions,
  },
  props: {
    users: {
      type: Array,
      required: false,
      default: () => [],
    },
    paths: {
      type: Object,
      required: true,
    },
  },
  data() {
    return {
      groupCounts: {},
    };
  },
  apollo: {
    groupCounts: {
      query: getUsersGroupCountsQuery,
      variables() {
        return {
          usernames: this.users.map((user) => user.username),
        };
      },
      update(data) {
        const nodes = data?.users?.nodes || [];
        const parsedIds = convertNodeIdsFromGraphQLIds(nodes);

        return parsedIds.reduce((acc, { id, groupCount }) => {
          acc[id] = groupCount || 0;
          return acc;
        }, {});
      },
      error(error) {
        createAlert({
          message: this.$options.i18n.groupCountFetchError,
          captureError: true,
          error,
        });
      },
      skip() {
        return !this.users.length;
      },
    },
  },
  computed: {
    groupCountsLoading() {
      return this.$apollo.queries.groupCounts.loading;
    },
  },
  i18n: {
    groupCountFetchError: s__(
      'AdminUsers|Could not load user group counts. Please refresh the page to try again.',
    ),
  },
};
</script>

<template>
  <div>
    <users-table
      :users="users"
      :admin-user-path="paths.adminUser"
      :group-counts="groupCounts"
      :group-counts-loading="groupCountsLoading"
    >
      <template #user-actions="{ user }">
        <user-actions :user="user" :paths="paths" :show-button-labels="true" />
      </template>
    </users-table>
  </div>
</template>