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
|
<script>
import {
GlDropdownItem,
GlDropdownSectionHeader,
GlDropdownDivider,
GlAvatar,
GlLoadingIcon,
GlSafeHtmlDirective as SafeHtml,
} from '@gitlab/ui';
import { mapState, mapGetters } from 'vuex';
import highlight from '~/lib/utils/highlight';
import { GROUPS_CATEGORY, PROJECTS_CATEGORY, LARGE_AVATAR_PX, SMALL_AVATAR_PX } from '../constants';
export default {
name: 'HeaderSearchAutocompleteItems',
components: {
GlDropdownItem,
GlDropdownSectionHeader,
GlDropdownDivider,
GlAvatar,
GlLoadingIcon,
},
directives: {
SafeHtml,
},
computed: {
...mapState(['search', 'loading']),
...mapGetters(['autocompleteGroupedSearchOptions']),
},
methods: {
highlightedName(val) {
return highlight(val, this.search);
},
avatarSize(data) {
if (data.category === GROUPS_CATEGORY || data.category === PROJECTS_CATEGORY) {
return LARGE_AVATAR_PX;
}
return SMALL_AVATAR_PX;
},
},
};
</script>
<template>
<div>
<template v-if="!loading">
<div v-for="option in autocompleteGroupedSearchOptions" :key="option.category">
<gl-dropdown-divider />
<gl-dropdown-section-header>{{ option.category }}</gl-dropdown-section-header>
<gl-dropdown-item
v-for="(data, index) in option.data"
:id="`autocomplete-${option.category}-${index}`"
:key="index"
tabindex="-1"
:href="data.url"
>
<div class="gl-display-flex gl-align-items-center">
<gl-avatar
v-if="data.avatar_url !== undefined"
:src="data.avatar_url"
:entity-id="data.id"
:entity-name="data.label"
:size="avatarSize(data)"
shape="square"
/>
<span v-safe-html="highlightedName(data.label)"></span>
</div>
</gl-dropdown-item>
</div>
</template>
<gl-loading-icon v-else size="lg" class="my-4" />
</div>
</template>
|