2020-10-24 23:57:45 +05:30
|
|
|
<script>
|
2020-11-24 15:15:51 +05:30
|
|
|
import { GlDropdown, GlDeprecatedDropdownItem, GlSearchBoxByType, GlIcon } from '@gitlab/ui';
|
2020-10-24 23:57:45 +05:30
|
|
|
import { __ } from '~/locale';
|
|
|
|
import autofocusonshow from '~/vue_shared/directives/autofocusonshow';
|
2020-11-24 15:15:51 +05:30
|
|
|
import { secondsToHours } from '~/lib/utils/datetime_utility';
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'TimezoneDropdown',
|
|
|
|
components: {
|
2020-11-24 15:15:51 +05:30
|
|
|
GlDropdown,
|
2020-10-24 23:57:45 +05:30
|
|
|
GlDeprecatedDropdownItem,
|
|
|
|
GlSearchBoxByType,
|
|
|
|
GlIcon,
|
|
|
|
},
|
|
|
|
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() {
|
|
|
|
return this.timezoneData.map(timezone => ({
|
|
|
|
formattedTimezone: this.formatTimezone(timezone),
|
|
|
|
identifier: timezone.identifier,
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
filteredResults() {
|
|
|
|
const lowerCasedSearchTerm = this.searchTerm.toLowerCase();
|
|
|
|
return this.timezones.filter(timezone =>
|
|
|
|
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>
|
2020-11-24 15:15:51 +05:30
|
|
|
<gl-dropdown :text="value" block lazy menu-class="gl-w-full!">
|
2020-10-24 23:57:45 +05:30
|
|
|
<template #button-content>
|
|
|
|
<span class="gl-flex-grow-1" :class="{ 'gl-text-gray-300': !value }">
|
|
|
|
{{ selectedTimezoneLabel }}
|
|
|
|
</span>
|
|
|
|
<gl-icon name="chevron-down" />
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<gl-search-box-by-type v-model.trim="searchTerm" v-autofocusonshow autofocus class="gl-m-3" />
|
|
|
|
<gl-deprecated-dropdown-item
|
|
|
|
v-for="timezone in filteredResults"
|
|
|
|
:key="timezone.formattedTimezone"
|
|
|
|
@click="selectTimezone(timezone)"
|
|
|
|
>
|
|
|
|
<gl-icon
|
|
|
|
:class="{ invisible: !isSelected(timezone) }"
|
|
|
|
name="mobile-issue-close"
|
|
|
|
class="gl-vertical-align-middle"
|
|
|
|
/>
|
|
|
|
{{ timezone.formattedTimezone }}
|
|
|
|
</gl-deprecated-dropdown-item>
|
|
|
|
<gl-deprecated-dropdown-item v-if="!filteredResults.length" data-testid="noMatchingResults">
|
|
|
|
{{ $options.tranlations.noResultsText }}
|
|
|
|
</gl-deprecated-dropdown-item>
|
2020-11-24 15:15:51 +05:30
|
|
|
</gl-dropdown>
|
2020-10-24 23:57:45 +05:30
|
|
|
</template>
|