@@ -24,8 +24,30 @@ const props = defineProps<{
2424 configuration: EditAndRetryConfig ;
2525}>();
2626
27- const panel = ref ();
28- const localMessage = ref ();
27+ interface LocalMessageState {
28+ isBodyChanged: boolean ;
29+ isBodyEmpty: boolean ;
30+ isContentTypeSupported: boolean ;
31+ bodyContentType: string | undefined ;
32+ bodyUnavailable: boolean ;
33+ isEvent: boolean ;
34+ retried: boolean ;
35+ headers: HeaderWithEditing [];
36+ messageBody: string ;
37+ }
38+
39+ const panel = ref (0 );
40+ const localMessage = ref <LocalMessageState >({
41+ isBodyChanged: false ,
42+ isBodyEmpty: false ,
43+ isContentTypeSupported: false ,
44+ bodyContentType: undefined ,
45+ bodyUnavailable: true ,
46+ isEvent: false ,
47+ retried: false ,
48+ headers: [],
49+ messageBody: " " ,
50+ });
2951let origMessageBody: string ;
3052
3153const showEditAndRetryConfirmation = ref (false );
@@ -79,10 +101,12 @@ function findHeadersByKey(key: string) {
79101
80102function getContentType() {
81103 const header = findHeadersByKey (" NServiceBus.ContentType" );
82- return header .value ;
104+ return header ? .value ;
83105}
84106
85- function isContentTypeSupported(contentType : string ) {
107+ function isContentTypeSupported(contentType : string | undefined ) {
108+ if (contentType === undefined ) return false ;
109+
86110 if (contentType .startsWith (" text/" )) return true ;
87111
88112 const charsetUtf8 = " ; charset=utf-8" ;
@@ -106,7 +130,7 @@ function isContentTypeSupported(contentType: string) {
106130
107131function getMessageIntent() {
108132 const intent = findHeadersByKey (" NServiceBus.MessageIntent" );
109- return intent ?.value ?? " " ;
133+ return intent ?.value ;
110134}
111135
112136function removeHeadersMarkedAsRemoved() {
@@ -127,7 +151,17 @@ async function retryEditedMessage() {
127151
128152function initializeMessageBodyAndHeaders() {
129153 origMessageBody = props .message .messageBody ;
130- localMessage .value = props .message ;
154+ localMessage .value = {
155+ isBodyChanged: false ,
156+ isBodyEmpty: false ,
157+ isContentTypeSupported: false ,
158+ bodyContentType: undefined ,
159+ bodyUnavailable: props .message .bodyUnavailable ,
160+ isEvent: false ,
161+ retried: props .message .retried ,
162+ headers: props .message .headers .map ((header : Header ) => ({ ... header })) as HeaderWithEditing [],
163+ messageBody: props .message .messageBody ,
164+ };
131165 localMessage .value .isBodyEmpty = false ;
132166 localMessage .value .isBodyChanged = false ;
133167
@@ -136,7 +170,7 @@ function initializeMessageBodyAndHeaders() {
136170 localMessage .value .isContentTypeSupported = isContentTypeSupported (contentType );
137171
138172 const messageIntent = getMessageIntent ();
139- localMessage .value .isEvent = messageIntent . value === " Publish" ;
173+ localMessage .value .isEvent = messageIntent === " Publish" ;
140174
141175 for (let index = 0 ; index < props .message .headers .length ; index ++ ) {
142176 const header: HeaderWithEditing = props .message .headers [index ] as HeaderWithEditing ;
@@ -191,15 +225,15 @@ onMounted(() => {
191225 </div >
192226 <div class =" row msg-editor-content" >
193227 <div class =" col-sm-12 no-side-padding" >
194- <div class =" alert alert-warning" v-if =" localMessage? .isEvent" >
228+ <div class =" alert alert-warning" v-if =" localMessage.isEvent" >
195229 <div class =" col-sm-12" >
196230 <i class =" fa fa-exclamation-circle" ></i > This message is an event. If it was already successfully handled by other subscribers, editing it now has the risk of changing the semantic meaning of the event and may result in
197231 altering the system behavior.
198232 </div >
199233 </div >
200- <div class =" alert alert-warning" v-if =" !localMessage? .isContentTypeSupported || localMessage? .bodyUnavailable" >
234+ <div class =" alert alert-warning" v-if =" !localMessage.isContentTypeSupported || localMessage.bodyUnavailable" >
201235 <div role =" status" aria-label =" cannot edit message body" class =" col-sm-12" >
202- <i class =" fa fa-exclamation-circle" ></i > Message body cannot be edited because content type "{{ localMessage? .bodyContentType }}" is not supported. Only messages with content types "application/json" and "text/xml" can be
236+ <i class =" fa fa-exclamation-circle" ></i > Message body cannot be edited because content type "{{ localMessage.bodyContentType }}" is not supported. Only messages with content types "application/json" and "text/xml" can be
203237 edited.
204238 </div >
205239 </div >
@@ -208,16 +242,16 @@ onMounted(() => {
208242 </div >
209243 <table role =" tabpanel" class =" table" v-if =" panel === 1" >
210244 <tbody >
211- <tr class =" interactiveList" v-for =" header in localMessage? .headers" :key =" header.key" >
245+ <tr class =" interactiveList" v-for =" header in localMessage.headers" :key =" header.key" >
212246 <MessageHeader :header =" header" ></MessageHeader >
213247 </tr >
214248 </tbody >
215249 </table >
216- <div role =" tabpanel" v-if =" panel === 2 && !localMessage? .bodyUnavailable" style =" height : calc (100% - 260px )" >
217- <textarea aria-label =" message body" class =" form-control" :disabled =" !localMessage? .isContentTypeSupported" v-model =" localMessage.messageBody" ></textarea >
218- <span class =" empty-error" v-if =" localMessage? .isBodyEmpty" ><i class =" fa fa-exclamation-triangle" ></i > Message body cannot be empty</span >
219- <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 >
220- <div class =" alert alert-info" v-if =" localMessage?. panel === 2 && localMessage.bodyUnavailable" >{{ localMessage.bodyUnavailable }}</div >
250+ <div role =" tabpanel" v-if =" panel === 2 && !localMessage.bodyUnavailable" style =" height : calc (100% - 260px )" >
251+ <textarea aria-label =" message body" class =" form-control" :disabled =" !localMessage.isContentTypeSupported" v-model =" localMessage.messageBody" ></textarea >
252+ <span class =" empty-error" v-if =" localMessage.isBodyEmpty" ><i class =" fa fa-exclamation-triangle" ></i > Message body cannot be empty</span >
253+ <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 >
254+ <div class =" alert alert-info" v-if =" panel === 2 && localMessage.bodyUnavailable" >{{ localMessage.bodyUnavailable }}</div >
221255 </div >
222256 </div >
223257 </div >
@@ -226,7 +260,7 @@ onMounted(() => {
226260 </div >
227261 <div class =" modal-footer" v-if =" !showEditAndRetryConfirmation && !showCancelConfirmation" >
228262 <button class =" btn btn-default" @click =" confirmCancel()" >Cancel</button >
229- <button class =" btn btn-primary" :disabled =" localMessage? .isBodyEmpty || localMessage? .bodyUnavailable" @click =" confirmEditAndRetry()" >Retry</button >
263+ <button class =" btn btn-primary" :disabled =" localMessage.isBodyEmpty || localMessage.bodyUnavailable" @click =" confirmEditAndRetry()" >Retry</button >
230264 </div >
231265 <div class =" modal-footer cancel-confirmation" v-if =" showCancelConfirmation" >
232266 <div >Are you sure you want to cancel? Any changes you made will be lost.</div >
0 commit comments