@@ -9,6 +9,7 @@ import CodeEditor from "@/components/CodeEditor.vue";
9
9
import { useMessageStore } from " @/stores/MessageStore" ;
10
10
import { storeToRefs } from " pinia" ;
11
11
import LoadingSpinner from " @/components/LoadingSpinner.vue" ;
12
+ import debounce from " lodash/debounce" ;
12
13
13
14
interface HeaderWithEditing extends Header {
14
15
isLocked: boolean ;
@@ -41,28 +42,32 @@ const localMessage = ref<LocalMessageState>({
41
42
isBodyEmpty: false ,
42
43
isContentTypeSupported: false ,
43
44
bodyContentType: undefined ,
44
- bodyUnavailable: true ,
45
+ bodyUnavailable: false ,
45
46
isEvent: false ,
46
47
retried: false ,
47
48
headers: [],
48
49
messageBody: " " ,
49
50
});
50
- let origMessageBody: string ;
51
-
52
51
const showEditAndRetryConfirmation = ref (false );
53
52
const showCancelConfirmation = ref (false );
54
53
const showEditRetryGenericError = ref (false );
55
54
const store = useMessageStore ();
56
55
const { state, headers, body, edit_and_retry_config } = storeToRefs (store );
57
56
const id = computed (() => state .value .data .id ?? " " );
58
- const messageBody = computed (() => body .value .data .value );
57
+ const uneditedMessageBody = computed (() => body .value .data .value ?? " " );
58
+ const regExToPruneLineEndings = new RegExp (/ [\n\r ] * / , " g" );
59
+ const debounceBodyUpdate = debounce ((value : string ) => {
60
+ const newValue = value .replaceAll (regExToPruneLineEndings , " " );
61
+ localMessage .value .isBodyChanged = newValue !== uneditedMessageBody .value .replaceAll (regExToPruneLineEndings , " " );
62
+ localMessage .value .isBodyEmpty = newValue === " " ;
63
+ }, 100 );
59
64
60
- watch (messageBody , (newValue ) => {
61
- if (newValue !== origMessageBody ) {
62
- localMessage .value .isBodyChanged = true ;
65
+ watch (
66
+ () => localMessage .value .messageBody ,
67
+ (newValue ) => {
68
+ debounceBodyUpdate (newValue );
63
69
}
64
- localMessage .value .isBodyEmpty = newValue === " " ;
65
- });
70
+ );
66
71
67
72
function close() {
68
73
emit (" cancel" );
@@ -87,7 +92,7 @@ function confirmCancel() {
87
92
}
88
93
89
94
function resetBodyChanges() {
90
- localMessage .value .messageBody = origMessageBody ;
95
+ localMessage .value .messageBody = uneditedMessageBody . value ;
91
96
localMessage .value .isBodyChanged = false ;
92
97
}
93
98
@@ -113,7 +118,6 @@ function initializeMessageBodyAndHeaders() {
113
118
return header ?.value ;
114
119
}
115
120
116
- origMessageBody = body .value .data .value ?? " " ;
117
121
const local = <LocalMessageState >{
118
122
isBodyChanged: false ,
119
123
isBodyEmpty: false ,
@@ -211,15 +215,22 @@ onMounted(() => {
211
215
</tr >
212
216
</tbody >
213
217
</table >
214
- <div role =" tabpanel" v-if =" panel === 2 && !localMessage.bodyUnavailable" style =" height : calc (100% - 260px )" >
215
- <div style =" margin-top : 1.25rem " >
216
- <LoadingSpinner v-if =" body.loading" />
217
- <CodeEditor v-else aria-label =" message body" :read-only =" !localMessage.isContentTypeSupported" v-model =" localMessage.messageBody" :language =" localMessage.language" :show-gutter =" true" ></CodeEditor >
218
+ <template v-if =" panel === 2 " >
219
+ <div role =" tabpanel" v-if =" !localMessage.bodyUnavailable" >
220
+ <div style =" margin-top : 1.25rem " >
221
+ <LoadingSpinner v-if =" body.loading" />
222
+ <CodeEditor v-else aria-label =" message body" :read-only =" !localMessage.isContentTypeSupported" v-model =" localMessage.messageBody" :language =" localMessage.language" :show-gutter =" true" >
223
+ <template #toolbarLeft >
224
+ <span class =" empty-error" v-if =" localMessage.isBodyEmpty" ><i class =" fa fa-exclamation-triangle" ></i > Message body cannot be empty</span >
225
+ </template >
226
+ <template #toolbarRight >
227
+ <button v-if =" localMessage.isBodyChanged" type =" button" class =" btn btn-secondary btn-sm" @click =" resetBodyChanges" ><i class =" fa fa-undo" ></i > Reset changes</button >
228
+ </template >
229
+ </CodeEditor >
230
+ </div >
218
231
</div >
219
- <span class =" empty-error" v-if =" localMessage.isBodyEmpty" ><i class =" fa fa-exclamation-triangle" ></i > Message body cannot be empty</span >
220
- <span class =" reset-body" v-if =" localMessage.isBodyChanged" ><i class =" fa fa-undo" v-tippy =" `Reset changes`" ></i > <a @click =" resetBodyChanges()" href =" javascript:void(0)" >Reset changes</a ></span >
221
- <div class =" alert alert-info" v-if =" panel === 2 && localMessage.bodyUnavailable" >{{ localMessage.bodyUnavailable }}</div >
222
- </div >
232
+ <div role =" tabpanel" class =" alert alert-info" v-else >{{ localMessage.bodyUnavailable }}</div >
233
+ </template >
223
234
</div >
224
235
</div >
225
236
</div >
@@ -267,14 +278,6 @@ onMounted(() => {
267
278
margin-right : 20px ;
268
279
}
269
280
270
- .modal-msg-editor .reset-body {
271
- color : #00a3c4 ;
272
- font-weight : bold ;
273
- text-align : left ;
274
- margin-top : 15px ;
275
- display : inline-block ;
276
- }
277
-
278
281
.modal-msg-editor .reset-body a :hover {
279
282
cursor : pointer ;
280
283
}
@@ -284,8 +287,6 @@ onMounted(() => {
284
287
}
285
288
286
289
.modal-msg-editor .empty-error {
287
- float : right ;
288
- margin-top : 15px ;
289
290
color : #ce4844 ;
290
291
font-weight : bold ;
291
292
}
0 commit comments