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
|
<script>
import { GlButton } from '@gitlab/ui';
import { __, s__ } from '~/locale';
import { helpPagePath } from '~/helpers/help_page_helper';
import { getDraft, clearDraft, updateDraft } from '~/lib/utils/autosave';
import { confirmAction } from '~/lib/utils/confirm_via_gl_modal/confirm_via_gl_modal';
import MarkdownEditor from '~/vue_shared/components/markdown/markdown_editor.vue';
export default {
name: 'AbuseReportCommentForm',
i18n: {
addReplyText: __('Add a reply'),
placeholderText: __('Write a comment or drag your files here…'),
cancelButtonText: __('Cancel'),
confirmText: s__('Notes|Are you sure you want to cancel creating this comment?'),
discardText: __('Discard changes'),
continueEditingText: __('Continue editing'),
},
components: {
GlButton,
MarkdownEditor,
},
inject: ['uploadNoteAttachmentPath'],
props: {
abuseReportId: {
type: String,
required: true,
},
isSubmitting: {
type: Boolean,
required: false,
default: false,
},
autosaveKey: {
type: String,
required: true,
},
isNewDiscussion: {
type: Boolean,
required: false,
default: false,
},
initialValue: {
type: String,
required: false,
default: '',
},
},
data() {
return {
commentText: getDraft(this.autosaveKey) || this.initialValue || '',
};
},
computed: {
formFieldProps() {
return {
'aria-label': this.$options.i18n.addReplyText,
placeholder: this.$options.i18n.placeholderText,
id: 'abuse-report-add-or-edit-comment',
name: 'abuse-report-add-or-edit-comment',
};
},
markdownDocsPath() {
return helpPagePath('user/markdown');
},
commentButtonText() {
return this.isNewDiscussion ? __('Comment') : __('Reply');
},
},
methods: {
setCommentText(newText) {
if (!this.isSubmitting) {
this.commentText = newText;
updateDraft(this.autosaveKey, this.commentText);
}
},
async cancelEditing() {
if (this.commentText && this.commentText !== this.initialValue) {
const confirmed = await confirmAction(this.$options.i18n.confirmText, {
primaryBtnText: this.$options.i18n.discardText,
cancelBtnText: this.$options.i18n.continueEditingText,
primaryBtnVariant: 'danger',
});
if (!confirmed) {
return;
}
}
this.$emit('cancelEditing');
clearDraft(this.autosaveKey);
},
},
};
</script>
<template>
<div class="timeline-discussion-body gl-overflow-visible!">
<div class="note-body gl-p-0! gl-overflow-visible!">
<form class="common-note-form gfm-form js-main-target-form gl-flex-grow-1 new-note">
<markdown-editor
:value="commentText"
:enable-content-editor="false"
render-markdown-path=""
:uploads-path="uploadNoteAttachmentPath"
:markdown-docs-path="markdownDocsPath"
:form-field-props="formFieldProps"
:autofocus="true"
@input="setCommentText"
@keydown.meta.enter="$emit('submitForm', { commentText })"
@keydown.ctrl.enter="$emit('submitForm', { commentText })"
@keydown.esc.stop="cancelEditing"
/>
<div class="note-form-actions">
<gl-button
category="primary"
variant="confirm"
data-testid="comment-button"
:disabled="!commentText.length"
:loading="isSubmitting"
@click="$emit('submitForm', { commentText })"
>
{{ commentButtonText }}
</gl-button>
<gl-button
data-testid="cancel-button"
category="primary"
class="gl-ml-3"
@click="cancelEditing"
>{{ $options.i18n.cancelButtonText }}
</gl-button>
</div>
</form>
</div>
</div>
</template>
|