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
|
<script>
import _ from 'underscore';
import LoadingIcon from '../../../vue_shared/components/loading_icon.vue';
import Item from './item.vue';
export default {
components: {
LoadingIcon,
Item,
},
props: {
isLoading: {
type: Boolean,
required: true,
},
items: {
type: Array,
required: true,
},
currentId: {
type: String,
required: true,
},
emptyText: {
type: String,
required: true,
},
},
data() {
return {
search: '',
};
},
computed: {
hasMergeRequests() {
return this.items.length !== 0;
},
hasNoSearchResults() {
return this.search !== '' && !this.hasMergeRequests;
},
},
watch: {
isLoading() {
this.focusSearch();
},
},
methods: {
viewMergeRequest(item) {
this.$router.push(`/project/${item.projectPathWithNamespace}/merge_requests/${item.iid}`);
},
searchMergeRequests: _.debounce(function debounceSearch() {
this.$emit('search', this.search);
}, 250),
focusSearch() {
if (!this.isLoading) {
this.$nextTick(() => {
this.$refs.searchInput.focus();
});
}
},
},
};
</script>
<template>
<div>
<loading-icon
class="mt-3 mb-3"
v-if="isLoading"
size="2"
/>
<template v-else>
<div class="dropdown-input mt-3 pb-3 mb-3 border-bottom">
<input
type="search"
class="dropdown-input-field"
placeholder="Search merge requests"
v-model="search"
@input="searchMergeRequests"
ref="searchInput"
/>
<i
aria-hidden="true"
class="fa fa-search dropdown-input-search"
></i>
</div>
<div class="dropdown-content ide-merge-requests-dropdown-content">
<ul class="mb-3">
<template v-if="hasMergeRequests">
<li
v-for="item in items"
:key="item.id"
>
<item
:item="item"
:current-id="currentId"
@click="viewMergeRequest"
/>
</li>
</template>
<li
v-else
class="ide-merge-requests-empty d-flex align-items-center justify-content-center"
>
<template v-if="hasNoSearchResults">
No merge requests found
</template>
<template v-else>
{{ emptyText }}
</template>
</li>
</ul>
</div>
</template>
</div>
</template>
<style scoped>
.ide-merge-requests-empty {
height: 230px;
}
.ide-merge-requests-dropdown-content {
min-height: 230px;
max-height: 470px;
}
</style>
|