debian-mirror-gitlab/app/assets/javascripts/ide/components/file_templates/bar.vue

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

130 lines
3.4 KiB
Vue
Raw Normal View History

2018-11-20 20:47:30 +05:30
<script>
2022-05-07 20:08:51 +05:30
import { GlButton, GlDropdown, GlDropdownItem, GlLoadingIcon, GlSearchBoxByType } from '@gitlab/ui';
2018-11-20 20:47:30 +05:30
import { mapActions, mapGetters, mapState } from 'vuex';
2022-05-07 20:08:51 +05:30
import { __ } from '~/locale';
const barLabel = __('File templates');
const templateListDropdownLabel = __('Choose a template...');
const templateTypesDropdownLabel = __('Choose a type...');
const undoButtonText = __('Undo');
2018-11-20 20:47:30 +05:30
export default {
2022-05-07 20:08:51 +05:30
i18n: {
barLabel,
templateListDropdownLabel,
templateTypesDropdownLabel,
undoButtonText,
},
2018-11-20 20:47:30 +05:30
components: {
2021-01-03 14:25:43 +05:30
GlButton,
2022-05-07 20:08:51 +05:30
GlDropdown,
GlDropdownItem,
GlLoadingIcon,
GlSearchBoxByType,
},
data() {
return {
search: '',
};
2018-11-20 20:47:30 +05:30
},
computed: {
...mapGetters(['activeFile']),
...mapGetters('fileTemplates', ['templateTypes']),
2022-05-07 20:08:51 +05:30
...mapState('fileTemplates', [
'selectedTemplateType',
'updateSuccess',
'templates',
'isLoading',
]),
filteredTemplateTypes() {
return this.templates.filter((t) => {
return t.name.toLowerCase().includes(this.search.toLowerCase());
});
},
2018-11-20 20:47:30 +05:30
showTemplatesDropdown() {
return Object.keys(this.selectedTemplateType).length > 0;
},
},
watch: {
activeFile: 'setInitialType',
},
mounted() {
this.setInitialType();
},
methods: {
...mapActions('fileTemplates', [
'setSelectedTemplateType',
'fetchTemplate',
2022-05-07 20:08:51 +05:30
'fetchTemplateTypes',
2018-11-20 20:47:30 +05:30
'undoFileTemplate',
]),
setInitialType() {
2021-03-08 18:12:59 +05:30
const initialTemplateType = this.templateTypes.find((t) => t.name === this.activeFile.name);
2018-11-20 20:47:30 +05:30
if (initialTemplateType) {
this.setSelectedTemplateType(initialTemplateType);
}
},
selectTemplateType(templateType) {
this.setSelectedTemplateType(templateType);
},
selectTemplate(template) {
this.fetchTemplate(template);
},
undo() {
this.undoFileTemplate();
},
},
};
</script>
<template>
2021-04-17 20:07:23 +05:30
<div
2022-08-27 11:52:29 +05:30
class="gl-display-flex gl-align-items-center ide-file-templates gl-relative gl-z-index-1"
data-testid="file-templates-bar"
data-qa-selector="file_templates_container"
2021-04-17 20:07:23 +05:30
>
2022-05-07 20:08:51 +05:30
<strong class="gl-mr-3"> {{ $options.i18n.barLabel }} </strong>
<gl-dropdown
class="gl-mr-6"
:text="selectedTemplateType.name || $options.i18n.templateTypesDropdownLabel"
>
<gl-dropdown-item
v-for="template in templateTypes"
:key="template.key"
@click.prevent="selectTemplateType(template)"
>
{{ template.name }}
</gl-dropdown-item>
</gl-dropdown>
<gl-dropdown
2018-11-20 20:47:30 +05:30
v-if="showTemplatesDropdown"
2022-08-27 11:52:29 +05:30
class="gl-mr-6"
data-qa-selector="file_template_dropdown"
2022-05-07 20:08:51 +05:30
:text="$options.i18n.templateListDropdownLabel"
@show="fetchTemplateTypes"
>
<template #header>
<gl-search-box-by-type v-model.trim="search" data-qa-selector="dropdown_filter_input" />
</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>
2018-11-20 20:47:30 +05:30
<transition name="fade">
2021-01-03 14:25:43 +05:30
<gl-button v-show="updateSuccess" category="secondary" variant="default" @click="undo">
2022-05-07 20:08:51 +05:30
{{ $options.i18n.undoButtonText }}
2021-01-03 14:25:43 +05:30
</gl-button>
2018-11-20 20:47:30 +05:30
</transition>
</div>
</template>