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

user_list.vue « components « user_lists « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d4601d1f73690abd3145fd7eadeb7210e76d7086 (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
<script>
import {
  GlAlert,
  GlButton,
  GlEmptyState,
  GlLoadingIcon,
  GlModalDirective as GlModal,
} from '@gitlab/ui';
// eslint-disable-next-line no-restricted-imports
import { mapActions, mapState } from 'vuex';
import { s__, __ } from '~/locale';
import { states, ADD_USER_MODAL_ID } from '../constants/show';
import AddUserModal from './add_user_modal.vue';

const commonTableClasses = ['gl-py-5', 'gl-border-b-1', 'gl-border-b-solid', 'gl-border-gray-100'];

export default {
  components: {
    GlAlert,
    GlButton,
    GlEmptyState,
    GlLoadingIcon,
    AddUserModal,
  },
  directives: {
    GlModal,
  },
  props: {
    emptyStatePath: {
      required: true,
      type: String,
    },
  },
  translations: {
    addUserButtonLabel: s__('UserLists|Add Users'),
    emptyStateTitle: s__('UserLists|There are no users'),
    emptyStateDescription: s__(
      'UserLists|Define a set of users to be used within feature flag strategies',
    ),
    userIdLabel: s__('UserLists|User IDs'),
    userIdColumnHeader: s__('UserLists|User ID'),
    errorMessage: __('Unable to load user list. Reload the page and try again.'),
    editButtonLabel: s__('UserLists|Edit'),
  },
  classes: {
    headerClasses: [
      'gl-display-flex',
      'gl-justify-content-space-between',
      'gl-pb-5',
      'gl-border-b-1',
      'gl-border-b-solid',
      'gl-border-gray-100',
    ].join(' '),
    tableHeaderClasses: commonTableClasses.join(' '),
    tableRowClasses: [
      ...commonTableClasses,
      'gl-display-flex',
      'gl-justify-content-space-between',
      'gl-align-items-center',
    ].join(' '),
  },
  ADD_USER_MODAL_ID,
  computed: {
    ...mapState(['userList', 'userIds', 'state']),
    name() {
      return this.userList?.name ?? '';
    },
    hasUserIds() {
      return this.userIds.length > 0;
    },
    isLoading() {
      return this.state === states.LOADING;
    },
    hasError() {
      return this.state === states.ERROR;
    },
    editPath() {
      return this.userList?.edit_path;
    },
  },
  mounted() {
    this.fetchUserList();
  },
  methods: {
    ...mapActions(['fetchUserList', 'dismissErrorAlert', 'removeUserId', 'addUserIds']),
  },
};
</script>
<template>
  <div>
    <gl-alert v-if="hasError" variant="danger" @dismiss="dismissErrorAlert">
      {{ $options.translations.errorMessage }}
    </gl-alert>
    <gl-loading-icon v-if="isLoading" size="xl" class="gl-mt-6" />
    <div v-else>
      <add-user-modal @addUsers="addUserIds" />
      <div :class="$options.classes.headerClasses">
        <div>
          <h3>{{ name }}</h3>
          <h4 class="gl-text-gray-500">{{ $options.translations.userIdLabel }}</h4>
        </div>
        <div class="gl-mt-6">
          <gl-button v-if="editPath" :href="editPath" data-testid="edit-user-list" class="gl-mr-3">
            {{ $options.translations.editButtonLabel }}
          </gl-button>
          <gl-button
            v-gl-modal="$options.ADD_USER_MODAL_ID"
            data-testid="add-users"
            variant="confirm"
          >
            {{ $options.translations.addUserButtonLabel }}
          </gl-button>
        </div>
      </div>
      <div v-if="hasUserIds">
        <div :class="$options.classes.tableHeaderClasses">
          {{ $options.translations.userIdColumnHeader }}
        </div>
        <div
          v-for="id in userIds"
          :key="id"
          data-testid="user-id-row"
          :class="$options.classes.tableRowClasses"
        >
          <span data-testid="user-id">{{ id }}</span>
          <gl-button
            category="secondary"
            variant="danger"
            icon="remove"
            :aria-label="__('Remove user')"
            data-testid="delete-user-id"
            @click="removeUserId(id)"
          />
        </div>
      </div>
      <gl-empty-state
        v-else
        :title="$options.translations.emptyStateTitle"
        :description="$options.translations.emptyStateDescription"
        :svg-path="emptyStatePath"
        :svg-height="150"
      />
    </div>
  </div>
</template>