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
|
<script>
import { sprintf, __ } from '~/locale';
import { createAlert } from '~/alert';
import { clearDraft } from '~/lib/utils/autosave';
import createNoteMutation from '../../graphql/notes/create_abuse_report_note.mutation.graphql';
import AbuseReportCommentForm from './abuse_report_comment_form.vue';
export default {
name: 'AbuseReportAddNote',
i18n: {
reply: __('Reply'),
replyToComment: __('Reply to comment'),
commentError: __('Your comment could not be submitted because %{reason}.'),
genericError: __(
'Your comment could not be submitted! Please check your network connection and try again.',
),
},
components: {
AbuseReportCommentForm,
},
props: {
abuseReportId: {
type: String,
required: true,
},
discussionId: {
type: String,
required: false,
default: '',
},
isNewDiscussion: {
type: Boolean,
required: false,
default: false,
},
},
data() {
return {
isEditing: this.isNewDiscussion,
isSubmitting: false,
};
},
computed: {
autosaveKey() {
// eslint-disable-next-line @gitlab/require-i18n-strings
return this.discussionId ? `${this.discussionId}-comment` : `${this.abuseReportId}-comment`;
},
timelineEntryClasses() {
return this.isNewDiscussion
? 'timeline-entry note-form'
: // eslint-disable-next-line @gitlab/require-i18n-strings
'note note-wrapper note-comment discussion-reply-holder gl-border-t-0! clearfix';
},
timelineEntryInnerClasses() {
return this.isNewDiscussion ? 'timeline-entry-inner' : '';
},
commentFormWrapperClasses() {
return !this.isEditing
? 'gl-relative gl-display-flex gl-align-items-flex-start gl-flex-nowrap'
: '';
},
},
methods: {
async addNote({ commentText }) {
this.isSubmitting = true;
this.$apollo
.mutate({
mutation: createNoteMutation,
variables: {
input: {
noteableId: this.abuseReportId,
body: commentText,
discussionId: this.discussionId || null,
},
},
})
.then(() => {
clearDraft(this.autosaveKey);
this.cancelEditing();
})
.catch((error) => {
const errorMessage = error?.message
? sprintf(this.$options.i18n.commentError, { reason: error.message.toLowerCase() })
: this.$options.i18n.genericError;
createAlert({
message: errorMessage,
parent: this.$el,
captureError: true,
});
})
.finally(() => {
this.isSubmitting = false;
});
},
cancelEditing() {
this.isEditing = this.isNewDiscussion;
this.$emit('cancelEditing');
},
showReplyForm() {
this.isEditing = true;
},
},
};
</script>
<template>
<li :class="timelineEntryClasses" data-testid="abuse-report-note-timeline-entry">
<div :class="timelineEntryInnerClasses" data-testid="abuse-report-note-timeline-entry-inner">
<div class="timeline-content">
<div class="flash-container"></div>
<div :class="commentFormWrapperClasses" data-testid="abuse-report-comment-form-wrapper">
<abuse-report-comment-form
v-if="isEditing"
:abuse-report-id="abuseReportId"
:is-submitting="isSubmitting"
:autosave-key="autosaveKey"
:is-new-discussion="isNewDiscussion"
@submitForm="addNote"
@cancelEditing="cancelEditing"
/>
<textarea
v-else
ref="textarea"
rows="1"
class="reply-placeholder-text-field gl-font-regular!"
data-testid="abuse-report-note-reply-textarea"
:placeholder="$options.i18n.reply"
:aria-label="$options.i18n.replyToComment"
@focus="showReplyForm"
@click="showReplyForm"
></textarea>
</div>
</div>
</div>
</li>
</template>
|