summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/releases/components/app_edit.vue
blob: bdc2b3abb8c38d26dbb5e004ee71260fce4698f2 (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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<script>
import { mapState, mapActions } from 'vuex';
import { GlButton, GlFormInput, GlFormGroup } from '@gitlab/ui';
import _ from 'underscore';
import { __, sprintf } from '~/locale';
import MarkdownField from '~/vue_shared/components/markdown/field.vue';
import autofocusonshow from '~/vue_shared/directives/autofocusonshow';

export default {
  name: 'ReleaseEditApp',
  components: {
    GlFormInput,
    GlFormGroup,
    GlButton,
    MarkdownField,
  },
  directives: {
    autofocusonshow,
  },
  computed: {
    ...mapState('detail', [
      'isFetchingRelease',
      'fetchError',
      'markdownDocsPath',
      'markdownPreviewPath',
      'releasesPagePath',
      'updateReleaseApiDocsPath',
    ]),
    showForm() {
      return !this.isFetchingRelease && !this.fetchError;
    },
    subtitleText() {
      return sprintf(
        __(
          'Releases are based on Git tags. We recommend naming tags that fit within semantic versioning, for example %{codeStart}v1.0%{codeEnd}, %{codeStart}v2.0-pre%{codeEnd}.',
        ),
        {
          codeStart: '<code>',
          codeEnd: '</code>',
        },
        false,
      );
    },
    tagName() {
      return this.$store.state.detail.release.tagName;
    },
    tagNameHintText() {
      return sprintf(
        __(
          'Changing a Release tag is only supported via Releases API. %{linkStart}More information%{linkEnd}',
        ),
        {
          linkStart: `<a href="${_.escape(
            this.updateReleaseApiDocsPath,
          )}" target="_blank" rel="noopener noreferrer">`,
          linkEnd: '</a>',
        },
        false,
      );
    },
    releaseTitle: {
      get() {
        return this.$store.state.detail.release.name;
      },
      set(title) {
        this.updateReleaseTitle(title);
      },
    },
    releaseNotes: {
      get() {
        return this.$store.state.detail.release.description;
      },
      set(notes) {
        this.updateReleaseNotes(notes);
      },
    },
  },
  created() {
    this.fetchRelease();
  },
  methods: {
    ...mapActions('detail', [
      'fetchRelease',
      'updateRelease',
      'updateReleaseTitle',
      'updateReleaseNotes',
      'navigateToReleasesPage',
    ]),
  },
};
</script>
<template>
  <div class="d-flex flex-column">
    <p class="pt-3 js-subtitle-text" v-html="subtitleText"></p>
    <form v-if="showForm" @submit.prevent="updateRelease()">
      <gl-form-group>
        <div class="row">
          <div class="col-md-6 col-lg-5 col-xl-4">
            <label for="git-ref">{{ __('Tag name') }}</label>
            <gl-form-input
              id="git-ref"
              v-model="tagName"
              type="text"
              class="form-control"
              aria-describedby="tag-name-help"
              disabled
            />
          </div>
        </div>
        <div id="tag-name-help" class="form-text text-muted" v-html="tagNameHintText"></div>
      </gl-form-group>
      <gl-form-group>
        <label for="release-title">{{ __('Release title') }}</label>
        <gl-form-input
          id="release-title"
          ref="releaseTitleInput"
          v-model="releaseTitle"
          v-autofocusonshow
          autofocus
          type="text"
          class="form-control"
        />
      </gl-form-group>
      <gl-form-group>
        <label for="release-notes">{{ __('Release notes') }}</label>
        <div class="bordered-box pr-3 pl-3">
          <markdown-field
            :can-attach-file="true"
            :markdown-preview-path="markdownPreviewPath"
            :markdown-docs-path="markdownDocsPath"
            :add-spacing-classes="false"
            class="prepend-top-10 append-bottom-10"
          >
            <textarea
              id="release-notes"
              slot="textarea"
              v-model="releaseNotes"
              class="note-textarea js-gfm-input js-autosize markdown-area"
              dir="auto"
              data-supports-quick-actions="false"
              :aria-label="__('Release notes')"
              :placeholder="__('Write your release notes or drag your files hereā€¦')"
              @keydown.meta.enter="updateRelease()"
              @keydown.ctrl.enter="updateRelease()"
            >
            </textarea>
          </markdown-field>
        </div>
      </gl-form-group>

      <div class="d-flex pt-3">
        <gl-button
          class="mr-auto js-submit-button"
          variant="success"
          type="submit"
          :aria-label="__('Save changes')"
        >
          {{ __('Save changes') }}
        </gl-button>
        <gl-button
          class="js-cancel-button"
          variant="default"
          type="button"
          :aria-label="__('Cancel')"
          @click="navigateToReleasesPage()"
        >
          {{ __('Cancel') }}
        </gl-button>
      </div>
    </form>
  </div>
</template>