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

apply_suggestion.vue « markdown « components « vue_shared « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 05ce007e615cd59796768dce28957faa5217b1ba (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
<script>
import { GlDisclosureDropdown, GlForm, GlFormTextarea, GlButton, GlAlert } from '@gitlab/ui';
import { __, n__ } from '~/locale';

export default {
  components: { GlDisclosureDropdown, GlForm, GlFormTextarea, GlButton, GlAlert },
  props: {
    disabled: {
      type: Boolean,
      required: false,
      default: false,
    },
    defaultCommitMessage: {
      type: String,
      required: false,
      default: null,
    },
    batchSuggestionsCount: {
      type: Number,
      required: false,
      default: 0,
    },
    errorMessage: {
      type: String,
      required: false,
      default: null,
    },
  },
  data() {
    return {
      message: null,
    };
  },
  computed: {
    dropdownText() {
      if (this.batchSuggestionsCount <= 1) {
        return __('Apply suggestion');
      }

      return n__('Apply %d suggestion', 'Apply %d suggestions', this.batchSuggestionsCount);
    },
    helperText() {
      if (this.batchSuggestionsCount <= 1) {
        return __('This also resolves this thread');
      }

      return __('This also resolves all related threads');
    },
  },
  methods: {
    onApply() {
      this.$emit('apply', this.message);
    },
    focusCommitMessageInput() {
      this.$refs.commitMessage.$el.focus();
    },
  },
};
</script>

<template>
  <gl-disclosure-dropdown
    data-qa-selector="apply_suggestion_dropdown"
    fluid-width
    placement="right"
    size="small"
    :disabled="disabled"
    :toggle-text="dropdownText"
    @shown="focusCommitMessageInput"
  >
    <gl-form class="gl-display-flex gl-flex-direction-column gl-px-4! gl-mx-0! gl-my-2!">
      <label for="commit-message">{{ __('Commit message') }}</label>
      <gl-alert v-if="errorMessage" variant="danger" :dismissible="false" class="gl-mb-4">
        {{ errorMessage }}
      </gl-alert>

      <gl-form-textarea
        id="commit-message"
        ref="commitMessage"
        v-model="message"
        class="apply-suggestions-input-min-width"
        :placeholder="defaultCommitMessage"
        submit-on-enter
        data-qa-selector="commit_message_field"
        @submit="onApply"
      />

      <span class="gl-mt-2 gl-text-secondary">
        {{ helperText }}
      </span>

      <gl-button
        class="gl-w-auto! gl-mt-3 gl-align-self-end"
        category="primary"
        variant="confirm"
        data-qa-selector="commit_with_custom_message_button"
        @click="onApply"
      >
        {{ __('Apply') }}
      </gl-button>
    </gl-form>
  </gl-disclosure-dropdown>
</template>