@@ -30,6 +30,7 @@ const props = defineProps<{
30
30
const store = useSagaDiagramStore ();
31
31
const initiatingMessageRef = ref <HTMLElement | null >(null );
32
32
const isActive = ref (false );
33
+ const hasParsingError = ref (false );
33
34
34
35
// Watch for changes to selectedMessageId
35
36
watch (
@@ -61,33 +62,30 @@ const formatJsonValue = (value: unknown): string => {
61
62
};
62
63
63
64
// Process JSON state and remove standard properties
64
- const processState = (state : unknown ): Record <string , JsonValue > => {
65
+ const processState = (state : string | undefined ): Record <string , JsonValue > => {
65
66
if (! state ) return {};
66
67
67
68
let stateObj: Record <string , unknown >;
68
69
try {
69
- stateObj = typeof state === " string " ? JSON .parse (state ) : ( state as Record < string , unknown > );
70
+ stateObj = JSON .parse (state );
70
71
} catch (e ) {
71
72
console .error (" Error parsing state:" , e );
73
+ hasParsingError .value = true ;
72
74
return {};
73
75
}
74
76
75
- // Filter out standard properties
77
+ // Filter out standard properties using delete
76
78
const standardKeys = [" $type" , " Id" , " Originator" , " OriginalMessageId" ];
77
- const filteredState: Record <string , JsonValue > = {};
78
-
79
- Object .keys (stateObj ).forEach ((key ) => {
80
- if (! standardKeys .includes (key )) {
81
- // Type assertion here since we can't guarantee the type exactly matches JsonValue
82
- filteredState [key ] = stateObj [key ] as JsonValue ;
79
+ standardKeys .forEach ((key ) => {
80
+ if (key in stateObj ) {
81
+ delete stateObj [key ];
83
82
}
84
83
});
85
84
86
- return filteredState ;
85
+ return stateObj as Record < string , JsonValue > ;
87
86
};
88
87
89
- // Compute the diff between current and previous states
90
- const stateDiff = computed (() => {
88
+ const sagaUpdateStateChanges = computed (() => {
91
89
const currentState = processState (props .update .stateAfterChange );
92
90
const previousState = processState (props .update .previousStateAfterChange );
93
91
const isFirstNode = props .update .IsFirstNode ;
@@ -175,9 +173,14 @@ const hasStateChanges = computed(() => {
175
173
<h3 class =" saga-state-title" v-if =" update.IsFirstNode" >Initial Saga State</h3 >
176
174
<h3 class =" saga-state-title" v-else >State Changes</h3 >
177
175
176
+ <!-- Error message when parsing fails -->
177
+ <div v-if =" hasParsingError" class =" json-container" >
178
+ <div class =" parsing-error-message" >An error occurred while parsing and displaying the saga state for this update</div >
179
+ </div >
180
+
178
181
<!-- Initial state display -->
179
- <div v-if =" update.IsFirstNode" class =" json-container" >
180
- <CodeEditor css =" monospace-code" :model-value =" stateDiff .formattedState || ''" language =" json" :showCopyToClipboard =" false" :showGutter =" false" />
182
+ <div v-else- if =" update.IsFirstNode" class =" json-container" >
183
+ <CodeEditor css =" monospace-code" :model-value =" sagaUpdateStateChanges .formattedState || ''" language =" json" :showCopyToClipboard =" false" :showGutter =" false" />
181
184
</div >
182
185
183
186
<!-- No changes message -->
@@ -187,7 +190,7 @@ const hasStateChanges = computed(() => {
187
190
188
191
<!-- Side-by-side diff view for state changes -->
189
192
<div v-else-if =" hasStateChanges && !update.IsFirstNode" >
190
- <DiffViewer :hide-line-numbers =" true" :showDiffOnly =" true" :oldValue =" stateDiff .previousFormatted" :newValue =" stateDiff .currentFormatted" leftTitle =" Previous State" rightTitle =" Updated State" />
193
+ <DiffViewer :hide-line-numbers =" true" :showDiffOnly =" true" :oldValue =" sagaUpdateStateChanges .previousFormatted" :newValue =" sagaUpdateStateChanges .currentFormatted" leftTitle =" Previous State" rightTitle =" Updated State" />
191
194
</div >
192
195
</div >
193
196
</div >
@@ -403,6 +406,13 @@ const hasStateChanges = computed(() => {
403
406
color : #666 ;
404
407
}
405
408
409
+ .parsing-error-message {
410
+ padding : 1rem ;
411
+ text-align : center ;
412
+ font-style : italic ;
413
+ color : #a94442 ;
414
+ }
415
+
406
416
/* Monospace font styling that matches DiffViewer */
407
417
:deep(.monospace-code ) {
408
418
border-radius : 0 ;
0 commit comments