summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/notes/components/comment_type_dropdown.vue
blob: 30ea5d3532edaf8bd78701ea8a259844055a5d1f (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
<script>
import { GlDropdown, GlDropdownItem, GlDropdownDivider } from '@gitlab/ui';

import { sprintf } from '~/locale';
import { COMMENT_FORM } from '~/notes/i18n';
import * as constants from '../constants';

export default {
  i18n: COMMENT_FORM,
  components: {
    GlDropdown,
    GlDropdownItem,
    GlDropdownDivider,
  },
  model: {
    prop: 'noteType',
    event: 'change',
  },
  props: {
    disabled: {
      type: Boolean,
      required: false,
      default: false,
    },
    trackingLabel: {
      type: String,
      required: false,
      default: undefined,
    },
    discussionsRequireResolution: {
      type: Boolean,
      required: false,
      default: false,
    },
    noteableDisplayName: {
      type: String,
      required: true,
    },
    noteType: {
      type: String,
      required: true,
    },
  },
  computed: {
    isNoteTypeComment() {
      return this.noteType === constants.COMMENT;
    },
    isNoteTypeDiscussion() {
      return this.noteType === constants.DISCUSSION;
    },
    commentButtonTitle() {
      return this.noteType === constants.COMMENT
        ? this.$options.i18n.comment
        : this.$options.i18n.startThread;
    },
    startDiscussionDescription() {
      return this.discussionsRequireResolution
        ? this.$options.i18n.discussionThatNeedsResolution
        : this.$options.i18n.discussion;
    },
    commentDescription() {
      return sprintf(this.$options.i18n.submitButton.commentHelp, {
        noteableDisplayName: this.noteableDisplayName,
      });
    },
  },
  methods: {
    handleClick() {
      this.$emit('click');
    },
    setNoteTypeToComment() {
      if (this.noteType !== constants.COMMENT) {
        this.$emit('change', constants.COMMENT);
      }
    },
    setNoteTypeToDiscussion() {
      if (this.noteType !== constants.DISCUSSION) {
        this.$emit('change', constants.DISCUSSION);
      }
    },
  },
};
</script>

<template>
  <gl-dropdown
    split
    :text="commentButtonTitle"
    class="gl-mr-3 js-comment-button js-comment-submit-button comment-type-dropdown"
    category="primary"
    variant="confirm"
    :disabled="disabled"
    data-testid="comment-button"
    data-qa-selector="comment_button"
    :data-track-label="trackingLabel"
    data-track-action="click_button"
    @click="$emit('click')"
  >
    <gl-dropdown-item
      is-check-item
      :is-checked="isNoteTypeComment"
      @click.stop.prevent="setNoteTypeToComment"
    >
      <strong>{{ $options.i18n.submitButton.comment }}</strong>
      <p class="gl-m-0">{{ commentDescription }}</p>
    </gl-dropdown-item>
    <gl-dropdown-divider />
    <gl-dropdown-item
      is-check-item
      :is-checked="isNoteTypeDiscussion"
      data-qa-selector="discussion_menu_item"
      @click.stop.prevent="setNoteTypeToDiscussion"
    >
      <strong>{{ $options.i18n.submitButton.startThread }}</strong>
      <p class="gl-m-0">{{ startDiscussionDescription }}</p>
    </gl-dropdown-item>
  </gl-dropdown>
</template>