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

submit_dropdown.vue « components « batch_comments « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5f4a1e44ea394ca2550500e28c1992ce4fcb7949 (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
<script>
import { GlDropdown, GlButton, GlIcon, GlForm, GlFormGroup } from '@gitlab/ui';
import { mapGetters, mapActions } from 'vuex';
import MarkdownField from '~/vue_shared/components/markdown/field.vue';
import { scrollToElement } from '~/lib/utils/common_utils';

export default {
  components: {
    GlDropdown,
    GlButton,
    GlIcon,
    GlForm,
    GlFormGroup,
    MarkdownField,
  },
  data() {
    return {
      isSubmitting: false,
      note: '',
    };
  },
  computed: {
    ...mapGetters(['getNotesData', 'getNoteableData', 'noteableType', 'getCurrentUserLastNote']),
  },
  methods: {
    ...mapActions('batchComments', ['publishReview']),
    async submitReview() {
      const noteData = {
        noteable_type: this.noteableType,
        noteable_id: this.getNoteableData.id,
        note: this.note,
      };

      this.isSubmitting = true;

      await this.publishReview(noteData);

      if (window.mrTabs && this.note) {
        window.location.hash = `note_${this.getCurrentUserLastNote.id}`;
        window.mrTabs.tabShown('show');

        setTimeout(() =>
          scrollToElement(document.getElementById(`note_${this.getCurrentUserLastNote.id}`)),
        );
      }

      this.isSubmitting = false;
    },
  },
  restrictedToolbarItems: ['full-screen'],
};
</script>

<template>
  <gl-dropdown right class="submit-review-dropdown" variant="info" category="secondary">
    <template #button-content>
      {{ __('Finish review') }}
      <gl-icon class="dropdown-chevron" name="chevron-up" />
    </template>
    <gl-form data-testid="submit-gl-form" @submit.prevent="submitReview">
      <gl-form-group
        :label="__('Summary comment (optional)')"
        label-for="review-note-body"
        label-class="gl-mb-2"
      >
        <div class="common-note-form gfm-form">
          <div
            class="comment-warning-wrapper gl-border-solid gl-border-1 gl-rounded-base gl-border-gray-100"
          >
            <markdown-field
              :is-submitting="isSubmitting"
              :add-spacing-classes="false"
              :textarea-value="note"
              :markdown-preview-path="getNoteableData.preview_note_path"
              :markdown-docs-path="getNotesData.markdownDocsPath"
              :quick-actions-docs-path="getNotesData.quickActionsDocsPath"
              :restricted-tool-bar-items="$options.restrictedToolbarItems"
              :force-autosize="false"
              class="js-no-autosize"
            >
              <template #textarea>
                <textarea
                  id="review-note-body"
                  ref="textarea"
                  v-model="note"
                  dir="auto"
                  :disabled="isSubmitting"
                  name="review[note]"
                  class="note-textarea js-gfm-input markdown-area"
                  data-supports-quick-actions="true"
                  data-testid="comment-textarea"
                  :aria-label="__('Comment')"
                  :placeholder="__('Write a comment or drag your files here…')"
                  @keydown.meta.enter="submitReview"
                  @keydown.ctrl.enter="submitReview"
                ></textarea>
              </template>
            </markdown-field>
          </div>
        </div>
      </gl-form-group>
      <div class="gl-display-flex gl-justify-content-end gl-mt-5">
        <gl-button
          :loading="isSubmitting"
          variant="confirm"
          type="submit"
          class="js-no-auto-disable"
          data-testid="submit-review-button"
        >
          {{ __('Submit review') }}
        </gl-button>
      </div>
    </gl-form>
  </gl-dropdown>
</template>