2021-02-22 17:27:13 +05:30
|
|
|
<script>
|
2021-06-08 01:23:25 +05:30
|
|
|
import { GlSkeletonLoader, GlTable } from '@gitlab/ui';
|
|
|
|
import createFlash from '~/flash';
|
|
|
|
import { convertNodeIdsFromGraphQLIds } from '~/graphql_shared/utils';
|
2022-07-23 23:45:48 +05:30
|
|
|
import { thWidthPercent } from '~/lib/utils/table_utility';
|
2021-06-08 01:23:25 +05:30
|
|
|
import { s__, __ } from '~/locale';
|
2021-04-29 21:17:54 +05:30
|
|
|
import UserDate from '~/vue_shared/components/user_date.vue';
|
2021-06-08 01:23:25 +05:30
|
|
|
import getUsersGroupCountsQuery from '../graphql/queries/get_users_group_counts.query.graphql';
|
2021-03-11 19:13:27 +05:30
|
|
|
import UserActions from './user_actions.vue';
|
2021-03-08 18:12:59 +05:30
|
|
|
import UserAvatar from './user_avatar.vue';
|
2021-02-22 17:27:13 +05:30
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
2021-06-08 01:23:25 +05:30
|
|
|
GlSkeletonLoader,
|
2021-02-22 17:27:13 +05:30
|
|
|
GlTable,
|
2021-03-08 18:12:59 +05:30
|
|
|
UserAvatar,
|
2021-03-11 19:13:27 +05:30
|
|
|
UserActions,
|
|
|
|
UserDate,
|
2021-02-22 17:27:13 +05:30
|
|
|
},
|
|
|
|
props: {
|
|
|
|
users: {
|
|
|
|
type: Array,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
paths: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
2021-06-08 01:23:25 +05:30
|
|
|
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) {
|
|
|
|
createFlash({
|
|
|
|
message: this.$options.i18n.groupCountFetchError,
|
|
|
|
captureError: true,
|
|
|
|
error,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
skip() {
|
|
|
|
return !this.users.length;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
i18n: {
|
|
|
|
groupCountFetchError: s__(
|
|
|
|
'AdminUsers|Could not load user group counts. Please refresh the page to try again.',
|
|
|
|
),
|
|
|
|
},
|
2021-02-22 17:27:13 +05:30
|
|
|
fields: [
|
|
|
|
{
|
|
|
|
key: 'name',
|
|
|
|
label: __('Name'),
|
2022-07-23 23:45:48 +05:30
|
|
|
thClass: thWidthPercent(40),
|
2021-02-22 17:27:13 +05:30
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'projectsCount',
|
|
|
|
label: __('Projects'),
|
2022-07-23 23:45:48 +05:30
|
|
|
thClass: thWidthPercent(10),
|
2021-02-22 17:27:13 +05:30
|
|
|
},
|
2021-06-08 01:23:25 +05:30
|
|
|
{
|
|
|
|
key: 'groupCount',
|
|
|
|
label: __('Groups'),
|
2022-07-23 23:45:48 +05:30
|
|
|
thClass: thWidthPercent(10),
|
2021-06-08 01:23:25 +05:30
|
|
|
},
|
2021-02-22 17:27:13 +05:30
|
|
|
{
|
|
|
|
key: 'createdAt',
|
|
|
|
label: __('Created on'),
|
2022-07-23 23:45:48 +05:30
|
|
|
thClass: thWidthPercent(15),
|
2021-02-22 17:27:13 +05:30
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'lastActivityOn',
|
|
|
|
label: __('Last activity'),
|
2022-07-23 23:45:48 +05:30
|
|
|
thClass: thWidthPercent(15),
|
2021-02-22 17:27:13 +05:30
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'settings',
|
|
|
|
label: '',
|
2022-07-23 23:45:48 +05:30
|
|
|
thClass: thWidthPercent(10),
|
2021-02-22 17:27:13 +05:30
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
<gl-table
|
|
|
|
:items="users"
|
|
|
|
:fields="$options.fields"
|
|
|
|
:empty-text="s__('AdminUsers|No users found')"
|
|
|
|
show-empty
|
|
|
|
stacked="md"
|
2021-09-04 01:27:46 +05:30
|
|
|
:tbody-tr-attr="{ 'data-qa-selector': 'user_row_content' }"
|
2021-03-08 18:12:59 +05:30
|
|
|
>
|
|
|
|
<template #cell(name)="{ item: user }">
|
2021-03-11 19:13:27 +05:30
|
|
|
<user-avatar :user="user" :admin-user-path="paths.adminUser" />
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<template #cell(createdAt)="{ item: { createdAt } }">
|
|
|
|
<user-date :date="createdAt" />
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<template #cell(lastActivityOn)="{ item: { lastActivityOn } }">
|
|
|
|
<user-date :date="lastActivityOn" show-never />
|
|
|
|
</template>
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
<template #cell(groupCount)="{ item: { id } }">
|
|
|
|
<div :data-testid="`user-group-count-${id}`">
|
|
|
|
<gl-skeleton-loader v-if="$apollo.loading" :width="40" :lines="1" />
|
|
|
|
<span v-else>{{ groupCounts[id] }}</span>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<template #cell(projectsCount)="{ item: { id, projectsCount } }">
|
|
|
|
<div :data-testid="`user-project-count-${id}`">{{ projectsCount }}</div>
|
|
|
|
</template>
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
<template #cell(settings)="{ item: user }">
|
|
|
|
<user-actions :user="user" :paths="paths" />
|
2021-03-08 18:12:59 +05:30
|
|
|
</template>
|
|
|
|
</gl-table>
|
2021-02-22 17:27:13 +05:30
|
|
|
</div>
|
|
|
|
</template>
|