Welcome to mirror list, hosted at ThFree Co, Russian Federation.

bar.vue « file_templates « components « ide « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ba679ae7c9b946c5ccb2504247105596dedab8fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<script>
import { GlButton, GlDropdown, GlDropdownItem, GlLoadingIcon, GlSearchBoxByType } from '@gitlab/ui';
import { mapActions, mapGetters, mapState } from 'vuex';
import { __ } from '~/locale';

const barLabel = __('File templates');
const templateListDropdownLabel = __('Choose a template...');
const templateTypesDropdownLabel = __('Choose a type...');
const undoButtonText = __('Undo');

export default {
  i18n: {
    barLabel,
    templateListDropdownLabel,
    templateTypesDropdownLabel,
    undoButtonText,
  },
  components: {
    GlButton,
    GlDropdown,
    GlDropdownItem,
    GlLoadingIcon,
    GlSearchBoxByType,
  },
  data() {
    return {
      search: '',
    };
  },
  computed: {
    ...mapGetters(['activeFile']),
    ...mapGetters('fileTemplates', ['templateTypes']),
    ...mapState('fileTemplates', [
      'selectedTemplateType',
      'updateSuccess',
      'templates',
      'isLoading',
    ]),
    filteredTemplateTypes() {
      return this.templates.filter((t) => {
        return t.name.toLowerCase().includes(this.search.toLowerCase());
      });
    },
    showTemplatesDropdown() {
      return Object.keys(this.selectedTemplateType).length > 0;
    },
  },
  watch: {
    activeFile: 'setInitialType',
  },
  mounted() {
    this.setInitialType();
  },
  methods: {
    ...mapActions('fileTemplates', [
      'setSelectedTemplateType',
      'fetchTemplate',
      'fetchTemplateTypes',
      'undoFileTemplate',
    ]),
    setInitialType() {
      const initialTemplateType = this.templateTypes.find((t) => t.name === this.activeFile.name);

      if (initialTemplateType) {
        this.setSelectedTemplateType(initialTemplateType);
      }
    },
    selectTemplateType(templateType) {
      this.setSelectedTemplateType(templateType);
    },
    selectTemplate(template) {
      this.fetchTemplate(template);
    },
    undo() {
      this.undoFileTemplate();
    },
  },
};
</script>

<template>
  <div
    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"
  >
    <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
      v-if="showTemplatesDropdown"
      class="gl-mr-6"
      data-qa-selector="file_template_dropdown"
      :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>
    <transition name="fade">
      <gl-button v-show="updateSuccess" category="secondary" variant="default" @click="undo">
        {{ $options.i18n.undoButtonText }}
      </gl-button>
    </transition>
  </div>
</template>