2018-11-20 20:47:30 +05:30
|
|
|
<script>
|
2021-01-03 14:25:43 +05:30
|
|
|
import { GlButton } from '@gitlab/ui';
|
2018-11-20 20:47:30 +05:30
|
|
|
import { mapActions, mapGetters, mapState } from 'vuex';
|
|
|
|
import Dropdown from './dropdown.vue';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
Dropdown,
|
2021-01-03 14:25:43 +05:30
|
|
|
GlButton,
|
2018-11-20 20:47:30 +05:30
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
...mapGetters(['activeFile']),
|
|
|
|
...mapGetters('fileTemplates', ['templateTypes']),
|
|
|
|
...mapState('fileTemplates', ['selectedTemplateType', 'updateSuccess']),
|
|
|
|
showTemplatesDropdown() {
|
|
|
|
return Object.keys(this.selectedTemplateType).length > 0;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
activeFile: 'setInitialType',
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.setInitialType();
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
...mapActions('fileTemplates', [
|
|
|
|
'setSelectedTemplateType',
|
|
|
|
'fetchTemplate',
|
|
|
|
'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
|
|
|
|
class="d-flex align-items-center ide-file-templates qa-file-templates-bar gl-relative gl-z-index-1"
|
|
|
|
>
|
2020-07-28 23:09:34 +05:30
|
|
|
<strong class="gl-mr-3"> {{ __('File templates') }} </strong>
|
2018-11-20 20:47:30 +05:30
|
|
|
<dropdown
|
|
|
|
:data="templateTypes"
|
|
|
|
:label="selectedTemplateType.name || __('Choose a type...')"
|
|
|
|
class="mr-2"
|
|
|
|
@click="selectTemplateType"
|
|
|
|
/>
|
|
|
|
<dropdown
|
|
|
|
v-if="showTemplatesDropdown"
|
|
|
|
:label="__('Choose a template...')"
|
|
|
|
:is-async-data="true"
|
|
|
|
:searchable="true"
|
|
|
|
:title="__('File templates')"
|
2018-12-13 13:39:08 +05:30
|
|
|
class="mr-2 qa-file-template-dropdown"
|
2018-11-20 20:47:30 +05:30
|
|
|
@click="selectTemplate"
|
|
|
|
/>
|
|
|
|
<transition name="fade">
|
2021-01-03 14:25:43 +05:30
|
|
|
<gl-button v-show="updateSuccess" category="secondary" variant="default" @click="undo">
|
2018-11-20 20:47:30 +05:30
|
|
|
{{ __('Undo') }}
|
2021-01-03 14:25:43 +05:30
|
|
|
</gl-button>
|
2018-11-20 20:47:30 +05:30
|
|
|
</transition>
|
|
|
|
</div>
|
|
|
|
</template>
|