2020-04-22 19:07:51 +05:30
|
|
|
<script>
|
2021-01-03 14:25:43 +05:30
|
|
|
import { GlDropdown, GlDropdownItem, GlDropdownDivider, GlSearchBoxByType } from '@gitlab/ui';
|
2020-04-22 19:07:51 +05:30
|
|
|
import { mapGetters } from 'vuex';
|
2020-10-24 23:57:45 +05:30
|
|
|
import { __, sprintf } from '~/locale';
|
2020-04-22 19:07:51 +05:30
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'CiEnvironmentsDropdown',
|
|
|
|
components: {
|
2021-01-03 14:25:43 +05:30
|
|
|
GlDropdown,
|
|
|
|
GlDropdownItem,
|
|
|
|
GlDropdownDivider,
|
2020-04-22 19:07:51 +05:30
|
|
|
GlSearchBoxByType,
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
value: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
searchTerm: this.value || '',
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
...mapGetters(['joinedEnvironments']),
|
|
|
|
composedCreateButtonLabel() {
|
|
|
|
return sprintf(__('Create wildcard: %{searchTerm}'), { searchTerm: this.searchTerm });
|
|
|
|
},
|
|
|
|
shouldRenderCreateButton() {
|
|
|
|
return this.searchTerm && !this.joinedEnvironments.includes(this.searchTerm);
|
|
|
|
},
|
|
|
|
filteredResults() {
|
|
|
|
const lowerCasedSearchTerm = this.searchTerm.toLowerCase();
|
|
|
|
return this.joinedEnvironments.filter(resultString =>
|
|
|
|
resultString.toLowerCase().includes(lowerCasedSearchTerm),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
value(newVal) {
|
|
|
|
this.searchTerm = newVal;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
selectEnvironment(selected) {
|
|
|
|
this.$emit('selectEnvironment', selected);
|
|
|
|
this.searchTerm = '';
|
|
|
|
},
|
|
|
|
createClicked() {
|
|
|
|
this.$emit('createClicked', this.searchTerm);
|
|
|
|
this.searchTerm = '';
|
|
|
|
},
|
|
|
|
isSelected(env) {
|
|
|
|
return this.value === env;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
<template>
|
2021-01-03 14:25:43 +05:30
|
|
|
<gl-dropdown :text="value">
|
|
|
|
<gl-search-box-by-type v-model.trim="searchTerm" />
|
|
|
|
<gl-dropdown-item
|
2020-04-22 19:07:51 +05:30
|
|
|
v-for="environment in filteredResults"
|
|
|
|
:key="environment"
|
2021-01-03 14:25:43 +05:30
|
|
|
:is-checked="isSelected(environment)"
|
|
|
|
is-check-item
|
2020-04-22 19:07:51 +05:30
|
|
|
@click="selectEnvironment(environment)"
|
|
|
|
>
|
|
|
|
{{ environment }}
|
2021-01-03 14:25:43 +05:30
|
|
|
</gl-dropdown-item>
|
|
|
|
<gl-dropdown-item v-if="!filteredResults.length" ref="noMatchingResults">{{
|
2020-04-22 19:07:51 +05:30
|
|
|
__('No matching results')
|
2021-01-03 14:25:43 +05:30
|
|
|
}}</gl-dropdown-item>
|
2020-04-22 19:07:51 +05:30
|
|
|
<template v-if="shouldRenderCreateButton">
|
2021-01-03 14:25:43 +05:30
|
|
|
<gl-dropdown-divider />
|
|
|
|
<gl-dropdown-item @click="createClicked">
|
2020-04-22 19:07:51 +05:30
|
|
|
{{ composedCreateButtonLabel }}
|
2021-01-03 14:25:43 +05:30
|
|
|
</gl-dropdown-item>
|
2020-04-22 19:07:51 +05:30
|
|
|
</template>
|
2021-01-03 14:25:43 +05:30
|
|
|
</gl-dropdown>
|
2020-04-22 19:07:51 +05:30
|
|
|
</template>
|