summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/static_site_editor/components/edit_meta_controls.vue
blob: c6247632b6e5b6950b885bfcc4702a60cb9e33e8 (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
130
<script>
import {
  GlDropdown,
  GlDropdownDivider,
  GlDropdownItem,
  GlForm,
  GlFormGroup,
  GlFormInput,
  GlFormTextarea,
} from '@gitlab/ui';

import { __ } from '~/locale';

export default {
  components: {
    GlDropdown,
    GlDropdownDivider,
    GlDropdownItem,
    GlForm,
    GlFormGroup,
    GlFormInput,
    GlFormTextarea,
  },
  props: {
    title: {
      type: String,
      required: true,
    },
    description: {
      type: String,
      required: true,
    },
    templates: {
      type: Array,
      required: false,
      default: null,
    },
    currentTemplate: {
      type: Object,
      required: false,
      default: null,
    },
  },
  computed: {
    dropdownLabel() {
      return this.currentTemplate ? this.currentTemplate.name : __('None');
    },
    hasTemplates() {
      return this.templates?.length > 0;
    },
  },
  mounted() {
    this.preSelect();
  },
  methods: {
    getId(type, key) {
      return `sse-merge-request-meta-${type}-${key}`;
    },
    preSelect() {
      this.$nextTick(() => {
        this.$refs.title.$el.select();
      });
    },
    onChangeTemplate(template) {
      this.$emit('changeTemplate', template || null);
    },
    onUpdate(field, value) {
      const payload = {
        title: this.title,
        description: this.description,
        [field]: value,
      };
      this.$emit('updateSettings', payload);
    },
  },
};
</script>

<template>
  <gl-form>
    <gl-form-group
      key="title"
      :label="__('Brief title about the change')"
      :label-for="getId('control', 'title')"
    >
      <gl-form-input
        :id="getId('control', 'title')"
        ref="title"
        :value="title"
        type="text"
        @input="onUpdate('title', $event)"
      />
    </gl-form-group>

    <gl-form-group
      v-if="hasTemplates"
      key="template"
      :label="__('Description template')"
      :label-for="getId('control', 'template')"
    >
      <gl-dropdown :text="dropdownLabel">
        <gl-dropdown-item key="none" @click="onChangeTemplate(null)">
          {{ __('None') }}
        </gl-dropdown-item>

        <gl-dropdown-divider />

        <gl-dropdown-item
          v-for="template in templates"
          :key="template.key"
          @click="onChangeTemplate(template)"
        >
          {{ template.name }}
        </gl-dropdown-item>
      </gl-dropdown>
    </gl-form-group>

    <gl-form-group
      key="description"
      :label="__('Goal of the changes and what reviewers should be aware of')"
      :label-for="getId('control', 'description')"
    >
      <gl-form-textarea
        :id="getId('control', 'description')"
        :value="description"
        @input="onUpdate('description', $event)"
      />
    </gl-form-group>
  </gl-form>
</template>