Skip to content
Snippets Groups Projects

Use GlCollapsibleListbox in ci_environments_dropdown.vue

Merged Eugie Limpin requested to merge el-use-collapsible-listbox into master
1 unresolved thread
<script>
import { GlDropdown, GlDropdownItem, GlDropdownDivider, GlSearchBoxByType } from '@gitlab/ui';
import {
GlDropdown,
GlDropdownItem,
GlDropdownDivider,
GlSearchBoxByType,
GlCollapsibleListbox,
} from '@gitlab/ui';
import { __, sprintf } from '~/locale';
import { convertEnvironmentScope } from '../utils';
@@ -10,6 +16,7 @@ export default {
GlDropdownItem,
GlDropdownDivider,
GlSearchBoxByType,
GlCollapsibleListbox,
},
props: {
environments: {
@@ -24,6 +31,7 @@ export default {
},
data() {
return {
selectedEnvironment: '',
searchTerm: '',
};
},
@@ -37,6 +45,18 @@ export default {
return environment.toLowerCase().includes(lowerCasedSearchTerm);
});
},
environmentOptions() {
const lowerCasedSearchTerm = this.searchTerm.toLowerCase();
return this.environments
.filter((environment) => {
return environment.toLowerCase().includes(lowerCasedSearchTerm);
})
.map((environment) => ({
value: environment,
text: environment,
}));
},
shouldRenderCreateButton() {
return this.searchTerm && !this.environments.includes(this.searchTerm);
},
@@ -66,25 +86,35 @@ export default {
};
</script>
<template>
<gl-dropdown :text="environmentScopeLabel" @show="clearSearch">
<gl-search-box-by-type v-model.trim="searchTerm" data-testid="ci-environment-search" />
<gl-dropdown-item
v-for="environment in filteredEnvironments"
:key="environment"
:is-checked="isSelected(environment)"
is-check-item
@click="selectEnvironment(environment)"
>
{{ convertEnvironmentScopeValue(environment) }}
</gl-dropdown-item>
<gl-dropdown-item v-if="!filteredEnvironments.length" ref="noMatchingResults">{{
__('No matching results')
}}</gl-dropdown-item>
<template v-if="shouldRenderCreateButton">
<gl-dropdown-divider />
<gl-dropdown-item data-testid="create-wildcard-button" @click="createEnvironmentScope">
{{ composedCreateButtonLabel }}
<div>
<gl-dropdown :text="environmentScopeLabel" @show="clearSearch">
<gl-search-box-by-type v-model.trim="searchTerm" data-testid="ci-environment-search" />
<gl-dropdown-item
v-for="environment in filteredEnvironments"
:key="environment"
:is-checked="isSelected(environment)"
is-check-item
@click="selectEnvironment(environment)"
>
{{ convertEnvironmentScopeValue(environment) }}
</gl-dropdown-item>
</template>
</gl-dropdown>
<gl-dropdown-item v-if="!filteredEnvironments.length" ref="noMatchingResults">{{
__('No matching results')
}}</gl-dropdown-item>
<template v-if="shouldRenderCreateButton">
<gl-dropdown-divider />
<gl-dropdown-item data-testid="create-wildcard-button" @click="createEnvironmentScope">
{{ composedCreateButtonLabel }}
</gl-dropdown-item>
</template>
</gl-dropdown>
<gl-collapsible-listbox
v-model="selectedEnvironment"
searchable
:items="environmentOptions"
:toggle-text="environmentScopeLabel"
@search="searchTerm = $event.trim()"
@select="selectEnvironment"
/>
</div>
</template>
Loading