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
|
<script>
import {
GlButton,
GlDropdown,
GlDropdownItem,
GlDropdownSectionHeader,
GlDropdownDivider,
GlTooltipDirective,
} from '@gitlab/ui';
import { convertArrayToCamelCase } from '~/lib/utils/common_utils';
import { capitalizeFirstCharacter } from '~/lib/utils/text_utility';
import { parseUserDeletionObstacles } from '~/vue_shared/components/user_deletion_obstacles/utils';
import { I18N_USER_ACTIONS } from '../constants';
import { generateUserPaths } from '../utils';
import Actions from './actions';
export default {
components: {
GlButton,
GlDropdown,
GlDropdownItem,
GlDropdownSectionHeader,
GlDropdownDivider,
...Actions,
},
directives: {
GlTooltip: GlTooltipDirective,
},
props: {
user: {
type: Object,
required: true,
},
paths: {
type: Object,
required: true,
},
showButtonLabels: {
type: Boolean,
required: false,
default: false,
},
},
computed: {
userActions() {
return convertArrayToCamelCase(this.user.actions);
},
dropdownActions() {
return this.userActions.filter((a) => a !== 'edit');
},
dropdownDeleteActions() {
return this.dropdownActions.filter((a) => a.includes('delete'));
},
dropdownSafeActions() {
return this.dropdownActions.filter((a) => !this.dropdownDeleteActions.includes(a));
},
hasDropdownActions() {
return this.dropdownActions.length > 0;
},
hasDeleteActions() {
return this.dropdownDeleteActions.length > 0;
},
hasEditAction() {
return this.userActions.includes('edit');
},
userPaths() {
return generateUserPaths(this.paths, this.user.username);
},
editButtonAttrs() {
return {
'data-testid': 'edit',
icon: 'pencil-square',
href: this.userPaths.edit,
};
},
obstaclesForUserDeletion() {
return parseUserDeletionObstacles(this.user);
},
},
methods: {
isLdapAction(action) {
return action === 'ldapBlocked';
},
getActionComponent(action) {
return Actions[capitalizeFirstCharacter(action)];
},
},
i18n: I18N_USER_ACTIONS,
};
</script>
<template>
<div
class="gl-display-flex gl-justify-content-end gl-my-n2 gl-mx-n2"
:data-testid="`user-actions-${user.id}`"
>
<div v-if="hasEditAction" class="gl-p-2">
<gl-button v-if="showButtonLabels" v-bind="editButtonAttrs">{{
$options.i18n.edit
}}</gl-button>
<gl-button
v-else
v-gl-tooltip="$options.i18n.edit"
v-bind="editButtonAttrs"
:aria-label="$options.i18n.edit"
/>
</div>
<div v-if="hasDropdownActions" class="gl-p-2">
<gl-dropdown
data-testid="dropdown-toggle"
right
:text="$options.i18n.userAdministration"
:text-sr-only="!showButtonLabels"
icon="settings"
data-qa-selector="user_actions_dropdown_toggle"
:data-qa-username="user.username"
>
<gl-dropdown-section-header>{{
$options.i18n.userAdministration
}}</gl-dropdown-section-header>
<template v-for="action in dropdownSafeActions">
<component
:is="getActionComponent(action)"
v-if="getActionComponent(action)"
:key="action"
:path="userPaths[action]"
:username="user.name"
:data-testid="action"
>
{{ $options.i18n[action] }}
</component>
<gl-dropdown-item v-else-if="isLdapAction(action)" :key="action" :data-testid="action">
{{ $options.i18n[action] }}
</gl-dropdown-item>
</template>
<gl-dropdown-divider v-if="hasDeleteActions" />
<template v-for="action in dropdownDeleteActions">
<component
:is="getActionComponent(action)"
v-if="getActionComponent(action)"
:key="action"
:paths="userPaths"
:username="user.name"
:user-deletion-obstacles="obstaclesForUserDeletion"
:data-testid="`delete-${action}`"
>
{{ $options.i18n[action] }}
</component>
</template>
</gl-dropdown>
</div>
</div>
</template>
|