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

user_select.vue « components « new_user_map « fogbugz « import « pages « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 20ce296bbec1ec4852aaf3564fe0f4fd54dae596 (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
<script>
import { GlAvatarLabeled, GlListbox } from '@gitlab/ui';
import { __ } from '~/locale';
import searchUsersQuery from '~/graphql_shared/queries/users_search_all.query.graphql';
import { getIdFromGraphQLId } from '~/graphql_shared/utils';

import { DEFAULT_DEBOUNCE_AND_THROTTLE_MS } from '~/lib/utils/constants';

const USERS_PER_PAGE = 20;

export default {
  components: {
    GlAvatarLabeled,
    GlListbox,
  },
  props: {
    name: {
      type: String,
      required: true,
    },
  },
  apollo: {
    usersQuery: {
      query: searchUsersQuery,
      variables() {
        return {
          search: this.search,
          first: USERS_PER_PAGE,
        };
      },
      update(data) {
        return data;
      },
      debounce: DEFAULT_DEBOUNCE_AND_THROTTLE_MS,
    },
  },
  data() {
    return {
      user: '',
      search: '',
    };
  },
  computed: {
    userId() {
      return getIdFromGraphQLId(this.user);
    },
    users() {
      return [
        { text: __('(no user)'), value: '' },
        ...(this.usersQuery?.users.nodes || []).map((u) => ({
          username: `@${u.username}`,
          avatarUrl: u.avatarUrl,
          text: u.name,
          value: u.id,
        })),
      ];
    },
  },
  methods: {
    clearTransform() {
      // FIXME: workaround for listbox issue
      // https://gitlab.com/gitlab-org/gitlab-ui/-/issues/1986
      const { listbox } = this.$refs;
      if (listbox.querySelector('.dropdown-menu')) {
        listbox.querySelector('.dropdown-menu').style.transform = '';
      }
    },
  },
};
</script>
<template>
  <div>
    <gl-listbox
      ref="listbox"
      v-model="user"
      :items="users"
      searchable
      is-check-centered
      :searching="$apollo.loading"
      @click.capture.native="clearTransform"
      @search="search = $event"
    >
      <template #list-item="{ item }">
        <gl-avatar-labeled
          shape="circle"
          :size="32"
          :src="item.avatarUrl"
          :label="item.text"
          :sub-label="item.username"
        />
      </template>
    </gl-listbox>
    <input type="hidden" :name="name" :value="userId" />
  </div>
</template>