summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/feature_flags/components/strategies/gitlab_user_list.vue
blob: ec97e8b13506e27d60a0ee703ea5c9103749e04d (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
<script>
import { GlFormSelect } from '@gitlab/ui';
import { s__ } from '~/locale';
import ParameterFormGroup from './parameter_form_group.vue';

export default {
  components: {
    GlFormSelect,
    ParameterFormGroup,
  },
  props: {
    strategy: {
      required: true,
      type: Object,
    },
    userLists: {
      required: false,
      type: Array,
      default: () => [],
    },
  },
  translations: {
    rolloutUserListLabel: s__('FeatureFlag|List'),
    rolloutUserListDescription: s__('FeatureFlag|Select a user list'),
    rolloutUserListNoListError: s__('FeatureFlag|There are no configured user lists'),
  },
  computed: {
    userListOptions() {
      return this.userLists.map(({ name, id }) => ({ value: id, text: name }));
    },
    hasUserLists() {
      return this.userListOptions.length > 0;
    },
    userListId() {
      return this.strategy?.userListId ?? '';
    },
  },
  methods: {
    onUserListChange(list) {
      this.$emit('change', {
        userListId: list,
      });
    },
  },
};
</script>
<template>
  <parameter-form-group
    :state="hasUserLists"
    :invalid-feedback="$options.translations.rolloutUserListNoListError"
    :label="$options.translations.rolloutUserListLabel"
    :description="hasUserLists ? $options.translations.rolloutUserListDescription : ''"
  >
    <template #default="{ inputId }">
      <gl-form-select
        :id="inputId"
        :value="userListId"
        :options="userListOptions"
        @change="onUserListChange"
      />
    </template>
  </parameter-form-group>
</template>