2020-10-24 23:57:45 +05:30
|
|
|
<script>
|
2021-01-03 14:25:43 +05:30
|
|
|
import { GlDropdown, GlDropdownItem, GlSearchBoxByType } from '@gitlab/ui';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { secondsToHours } from '~/lib/utils/datetime_utility';
|
2020-10-24 23:57:45 +05:30
|
|
|
import { __ } from '~/locale';
|
|
|
|
import autofocusonshow from '~/vue_shared/directives/autofocusonshow';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'TimezoneDropdown',
|
|
|
|
components: {
|
2020-11-24 15:15:51 +05:30
|
|
|
GlDropdown,
|
2021-01-03 14:25:43 +05:30
|
|
|
GlDropdownItem,
|
2020-10-24 23:57:45 +05:30
|
|
|
GlSearchBoxByType,
|
|
|
|
},
|
|
|
|
directives: {
|
|
|
|
autofocusonshow,
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
value: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
timezoneData: {
|
|
|
|
type: Array,
|
|
|
|
required: true,
|
|
|
|
default: () => [],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
searchTerm: '',
|
|
|
|
};
|
|
|
|
},
|
|
|
|
tranlations: {
|
|
|
|
noResultsText: __('No matching results'),
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
timezones() {
|
2021-03-08 18:12:59 +05:30
|
|
|
return this.timezoneData.map((timezone) => ({
|
2020-10-24 23:57:45 +05:30
|
|
|
formattedTimezone: this.formatTimezone(timezone),
|
|
|
|
identifier: timezone.identifier,
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
filteredResults() {
|
|
|
|
const lowerCasedSearchTerm = this.searchTerm.toLowerCase();
|
2021-03-08 18:12:59 +05:30
|
|
|
return this.timezones.filter((timezone) =>
|
2020-10-24 23:57:45 +05:30
|
|
|
timezone.formattedTimezone.toLowerCase().includes(lowerCasedSearchTerm),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
selectedTimezoneLabel() {
|
|
|
|
return this.value || __('Select timezone');
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
selectTimezone(selectedTimezone) {
|
|
|
|
this.$emit('input', selectedTimezone);
|
|
|
|
this.searchTerm = '';
|
|
|
|
},
|
|
|
|
isSelected(timezone) {
|
|
|
|
return this.value === timezone.formattedTimezone;
|
|
|
|
},
|
|
|
|
formatTimezone(item) {
|
2020-11-24 15:15:51 +05:30
|
|
|
return `[UTC ${secondsToHours(item.offset)}] ${item.name}`;
|
2020-10-24 23:57:45 +05:30
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
<template>
|
2021-11-11 11:23:49 +05:30
|
|
|
<gl-dropdown :text="selectedTimezoneLabel" block lazy menu-class="gl-w-full!" v-bind="$attrs">
|
2021-01-03 14:25:43 +05:30
|
|
|
<gl-search-box-by-type v-model.trim="searchTerm" v-autofocusonshow autofocus />
|
|
|
|
<gl-dropdown-item
|
2020-10-24 23:57:45 +05:30
|
|
|
v-for="timezone in filteredResults"
|
|
|
|
:key="timezone.formattedTimezone"
|
2021-01-03 14:25:43 +05:30
|
|
|
:is-checked="isSelected(timezone)"
|
|
|
|
:is-check-item="true"
|
2020-10-24 23:57:45 +05:30
|
|
|
@click="selectTimezone(timezone)"
|
|
|
|
>
|
|
|
|
{{ timezone.formattedTimezone }}
|
2021-01-03 14:25:43 +05:30
|
|
|
</gl-dropdown-item>
|
|
|
|
<gl-dropdown-item
|
|
|
|
v-if="!filteredResults.length"
|
|
|
|
class="gl-pointer-events-none"
|
|
|
|
data-testid="noMatchingResults"
|
|
|
|
>
|
2020-10-24 23:57:45 +05:30
|
|
|
{{ $options.tranlations.noResultsText }}
|
2021-01-03 14:25:43 +05:30
|
|
|
</gl-dropdown-item>
|
2020-11-24 15:15:51 +05:30
|
|
|
</gl-dropdown>
|
2020-10-24 23:57:45 +05:30
|
|
|
</template>
|