summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/search/topbar/components/searchable_dropdown_item.vue
blob: a4254a355a28e004a5ab466f3c3b9b94d0020371 (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
<script>
import { GlDropdownItem, GlAvatar, GlSafeHtmlDirective as SafeHtml } from '@gitlab/ui';
import highlight from '~/lib/utils/highlight';
import { truncateNamespace } from '~/lib/utils/text_utility';
import { AVATAR_SHAPE_OPTION_RECT } from '~/vue_shared/constants';

export default {
  name: 'SearchableDropdownItem',
  components: {
    GlDropdownItem,
    GlAvatar,
  },
  directives: {
    SafeHtml,
  },
  props: {
    item: {
      type: Object,
      required: true,
    },
    selectedItem: {
      type: Object,
      required: true,
    },
    searchText: {
      type: String,
      required: false,
      default: '',
    },
    name: {
      type: String,
      required: true,
    },
    fullName: {
      type: String,
      required: true,
    },
  },
  computed: {
    isSelected() {
      return this.item.id === this.selectedItem.id;
    },
    truncatedNamespace() {
      return truncateNamespace(this.item[this.fullName]);
    },
    highlightedItemName() {
      return highlight(this.item[this.name], this.searchText);
    },
  },
  AVATAR_SHAPE_OPTION_RECT,
};
</script>

<template>
  <gl-dropdown-item
    :is-check-item="true"
    :is-checked="isSelected"
    :is-check-centered="true"
    @click="$emit('change', item)"
  >
    <div class="gl-display-flex gl-align-items-center">
      <gl-avatar
        :src="item.avatar_url"
        :entity-id="item.id"
        :entity-name="item[name]"
        :shape="$options.AVATAR_SHAPE_OPTION_RECT"
        :size="32"
      />
      <div class="gl-display-flex gl-flex-direction-column">
        <span v-safe-html="highlightedItemName" data-testid="item-title"></span>
        <span class="gl-font-sm gl-text-gray-700" data-testid="item-namespace">{{
          truncatedNamespace
        }}</span>
      </div>
    </div>
  </gl-dropdown-item>
</template>