Commit 49aa0200 authored by Ezekiel Kigbo's avatar Ezekiel Kigbo

Merge branch 'arfedoro_replace_dropdown_ide_file_template' into 'master'

Replace bootstrap Dropdown to gitlab-ui Dropdown

See merge request gitlab-org/gitlab!81609
parents a9134733 76b20c02
<script> <script>
import { GlButton } from '@gitlab/ui'; import { GlButton, GlDropdown, GlDropdownItem, GlLoadingIcon, GlSearchBoxByType } from '@gitlab/ui';
import { mapActions, mapGetters, mapState } from 'vuex'; import { mapActions, mapGetters, mapState } from 'vuex';
import Dropdown from './dropdown.vue'; import { __ } from '~/locale';
const barLabel = __('File templates');
const templateListDropdownLabel = __('Choose a template...');
const templateTypesDropdownLabel = __('Choose a type...');
const undoButtonText = __('Undo');
export default { export default {
i18n: {
barLabel,
templateListDropdownLabel,
templateTypesDropdownLabel,
undoButtonText,
},
components: { components: {
Dropdown,
GlButton, GlButton,
GlDropdown,
GlDropdownItem,
GlLoadingIcon,
GlSearchBoxByType,
},
data() {
return {
search: '',
};
}, },
computed: { computed: {
...mapGetters(['activeFile']), ...mapGetters(['activeFile']),
...mapGetters('fileTemplates', ['templateTypes']), ...mapGetters('fileTemplates', ['templateTypes']),
...mapState('fileTemplates', ['selectedTemplateType', 'updateSuccess']), ...mapState('fileTemplates', [
'selectedTemplateType',
'updateSuccess',
'templates',
'isLoading',
]),
filteredTemplateTypes() {
return this.templates.filter((t) => {
return t.name.toLowerCase().includes(this.search.toLowerCase());
});
},
showTemplatesDropdown() { showTemplatesDropdown() {
return Object.keys(this.selectedTemplateType).length > 0; return Object.keys(this.selectedTemplateType).length > 0;
}, },
...@@ -26,6 +55,7 @@ export default { ...@@ -26,6 +55,7 @@ export default {
...mapActions('fileTemplates', [ ...mapActions('fileTemplates', [
'setSelectedTemplateType', 'setSelectedTemplateType',
'fetchTemplate', 'fetchTemplate',
'fetchTemplateTypes',
'undoFileTemplate', 'undoFileTemplate',
]), ]),
setInitialType() { setInitialType() {
...@@ -50,27 +80,46 @@ export default { ...@@ -50,27 +80,46 @@ export default {
<template> <template>
<div <div
class="d-flex align-items-center ide-file-templates qa-file-templates-bar gl-relative gl-z-index-1" class="gl-display-flex gl-align-items-center ide-file-templates qa-file-templates-bar gl-relative gl-z-index-1"
> >
<strong class="gl-mr-3"> {{ __('File templates') }} </strong> <strong class="gl-mr-3"> {{ $options.i18n.barLabel }} </strong>
<dropdown <gl-dropdown
:data="templateTypes" class="gl-mr-6 qa-file-templates-bar"
:label="selectedTemplateType.name || __('Choose a type...')" :text="selectedTemplateType.name || $options.i18n.templateTypesDropdownLabel"
class="mr-2" >
@click="selectTemplateType" <gl-dropdown-item
/> v-for="template in templateTypes"
<dropdown :key="template.key"
@click.prevent="selectTemplateType(template)"
>
{{ template.name }}
</gl-dropdown-item>
</gl-dropdown>
<gl-dropdown
v-if="showTemplatesDropdown" v-if="showTemplatesDropdown"
:label="__('Choose a template...')" class="gl-mr-6 qa-file-template-dropdown"
:is-async-data="true" :text="$options.i18n.templateListDropdownLabel"
:searchable="true" @show="fetchTemplateTypes"
:title="__('File templates')" >
class="mr-2 qa-file-template-dropdown" <template #header>
@click="selectTemplate" <gl-search-box-by-type v-model.trim="search" />
/> </template>
<div>
<gl-loading-icon v-if="isLoading" />
<template v-else>
<gl-dropdown-item
v-for="template in filteredTemplateTypes"
:key="template.key"
@click="selectTemplate(template)"
>
{{ template.name }}
</gl-dropdown-item>
</template>
</div>
</gl-dropdown>
<transition name="fade"> <transition name="fade">
<gl-button v-show="updateSuccess" category="secondary" variant="default" @click="undo"> <gl-button v-show="updateSuccess" category="secondary" variant="default" @click="undo">
{{ __('Undo') }} {{ $options.i18n.undoButtonText }}
</gl-button> </gl-button>
</transition> </transition>
</div> </div>
......
...@@ -36,7 +36,7 @@ describe('IDE file templates bar component', () => { ...@@ -36,7 +36,7 @@ describe('IDE file templates bar component', () => {
it('calls setSelectedTemplateType when clicking item', () => { it('calls setSelectedTemplateType when clicking item', () => {
jest.spyOn(vm, 'setSelectedTemplateType').mockImplementation(); jest.spyOn(vm, 'setSelectedTemplateType').mockImplementation();
vm.$el.querySelector('.dropdown-content button').click(); vm.$el.querySelector('.dropdown-menu button').click();
expect(vm.setSelectedTemplateType).toHaveBeenCalledWith({ expect(vm.setSelectedTemplateType).toHaveBeenCalledWith({
name: '.gitlab-ci.yml', name: '.gitlab-ci.yml',
...@@ -64,10 +64,10 @@ describe('IDE file templates bar component', () => { ...@@ -64,10 +64,10 @@ describe('IDE file templates bar component', () => {
expect(vm.$el.querySelectorAll('.dropdown')[1].textContent).toContain('Choose a template'); expect(vm.$el.querySelectorAll('.dropdown')[1].textContent).toContain('Choose a template');
}); });
it('calls fetchTemplate on click', () => { it('calls fetchTemplate on dropdown open', () => {
jest.spyOn(vm, 'fetchTemplate').mockImplementation(); jest.spyOn(vm, 'fetchTemplate').mockImplementation();
vm.$el.querySelectorAll('.dropdown-content')[1].querySelector('button').click(); vm.$el.querySelectorAll('.dropdown-menu')[1].querySelector('button').click();
expect(vm.fetchTemplate).toHaveBeenCalledWith({ expect(vm.fetchTemplate).toHaveBeenCalledWith({
name: 'test', name: 'test',
...@@ -85,7 +85,7 @@ describe('IDE file templates bar component', () => { ...@@ -85,7 +85,7 @@ describe('IDE file templates bar component', () => {
it('calls undoFileTemplate when clicking undo button', () => { it('calls undoFileTemplate when clicking undo button', () => {
jest.spyOn(vm, 'undoFileTemplate').mockImplementation(); jest.spyOn(vm, 'undoFileTemplate').mockImplementation();
vm.$el.querySelector('.btn-default').click(); vm.$el.querySelector('.btn-default-secondary').click();
expect(vm.undoFileTemplate).toHaveBeenCalled(); expect(vm.undoFileTemplate).toHaveBeenCalled();
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment