2018-11-08 19:23:39 +05:30
|
|
|
<script>
|
2020-04-08 14:13:33 +05:30
|
|
|
import { debounce } from 'lodash';
|
2021-02-22 17:27:13 +05:30
|
|
|
import { mapActions, mapState } from 'vuex';
|
2020-11-24 15:15:51 +05:30
|
|
|
import { GlIcon } from '@gitlab/ui';
|
2018-11-08 19:23:39 +05:30
|
|
|
import eventHub from '../event_hub';
|
|
|
|
import frequentItemsMixin from './frequent_items_mixin';
|
2021-02-22 17:27:13 +05:30
|
|
|
import Tracking from '~/tracking';
|
|
|
|
|
|
|
|
const trackingMixin = Tracking.mixin();
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
export default {
|
2018-12-13 13:39:08 +05:30
|
|
|
components: {
|
2020-11-24 15:15:51 +05:30
|
|
|
GlIcon,
|
2018-12-13 13:39:08 +05:30
|
|
|
},
|
2021-02-22 17:27:13 +05:30
|
|
|
mixins: [frequentItemsMixin, trackingMixin],
|
2018-11-08 19:23:39 +05:30
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
searchQuery: '',
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
2021-02-22 17:27:13 +05:30
|
|
|
...mapState(['dropdownType']),
|
2018-11-08 19:23:39 +05:30
|
|
|
translations() {
|
|
|
|
return this.getTranslations(['searchInputPlaceholder']);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
watch: {
|
2020-04-08 14:13:33 +05:30
|
|
|
searchQuery: debounce(function debounceSearchQuery() {
|
2021-02-22 17:27:13 +05:30
|
|
|
this.track('type_search_query', {
|
|
|
|
label: `${this.dropdownType}_dropdown_frequent_items_search_input`,
|
|
|
|
});
|
2018-11-08 19:23:39 +05:30
|
|
|
this.setSearchQuery(this.searchQuery);
|
|
|
|
}, 500),
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
eventHub.$on(`${this.namespace}-dropdownOpen`, this.setFocus);
|
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
eventHub.$off(`${this.namespace}-dropdownOpen`, this.setFocus);
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
...mapActions(['setSearchQuery']),
|
|
|
|
setFocus() {
|
|
|
|
this.$refs.search.focus();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div class="search-input-container d-none d-sm-block">
|
|
|
|
<input
|
|
|
|
ref="search"
|
|
|
|
v-model="searchQuery"
|
|
|
|
:placeholder="translations.searchInputPlaceholder"
|
|
|
|
type="search"
|
|
|
|
class="form-control"
|
|
|
|
/>
|
2020-11-24 15:15:51 +05:30
|
|
|
<gl-icon v-if="!searchQuery" name="search" class="search-icon" />
|
2018-11-08 19:23:39 +05:30
|
|
|
</div>
|
|
|
|
</template>
|