Skip to content

Commit a422379

Browse files
authored
Update Saga Diagram to lossless json (#2382)
1 parent 2e54595 commit a422379

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

src/Frontend/src/components/messages2/SagaDiagram/SagaUpdateNode.vue

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import DiffViewer from "@/components/messages2/DiffViewer.vue";
77
import CodeEditor from "@/components/CodeEditor.vue";
88
import { useSagaDiagramStore } from "@/stores/SagaDiagramStore";
99
import { ref, watch, computed } from "vue";
10+
import { parse, stringify } from "lossless-json";
1011
1112
// Import the images directly
1213
import CommandIcon from "@/assets/command.svg";
@@ -16,13 +17,6 @@ import TimeoutIcon from "@/assets/timeout.svg";
1617
import EventIcon from "@/assets/event.svg";
1718
import SagaTimeoutIcon from "@/assets/SagaTimeoutIcon.svg";
1819
19-
// Define types for JSON values and properties
20-
type JsonValue = string | number | boolean | null | JsonObject | JsonArray;
21-
interface JsonObject {
22-
[key: string]: JsonValue;
23-
}
24-
type JsonArray = Array<JsonValue>;
25-
2620
const props = defineProps<{
2721
update: SagaUpdateViewModel;
2822
showMessageData?: boolean;
@@ -57,18 +51,20 @@ watch(
5751
const formatJsonValue = (value: unknown): string => {
5852
if (value === null || value === undefined) return "null";
5953
if (typeof value === "object") {
60-
return JSON.stringify(value, null, 2);
54+
return stringify(value as object, null, 2) || "{}";
6155
}
6256
return String(value);
6357
};
6458
6559
// Process JSON state and remove standard properties
66-
const processState = (state: string | undefined): Record<string, JsonValue> => {
60+
const processState = (state: string | undefined): object => {
6761
if (!state) return {};
6862
6963
let stateObj: Record<string, unknown>;
7064
try {
71-
stateObj = JSON.parse(state);
65+
const parsedState = parse(state);
66+
67+
stateObj = parsedState as Record<string, unknown>;
7268
} catch (e) {
7369
console.error("Error parsing state:", e);
7470
hasParsingError.value = true;
@@ -83,7 +79,7 @@ const processState = (state: string | undefined): Record<string, JsonValue> => {
8379
}
8480
});
8581
86-
return stateObj as Record<string, JsonValue>;
82+
return stateObj;
8783
};
8884
8985
const sagaUpdateStateChanges = computed(() => {
@@ -120,7 +116,7 @@ const hasStateChanges = computed(() => {
120116
const currentState = processState(props.update.stateAfterChange);
121117
const previousState = processState(props.update.previousStateAfterChange);
122118
123-
return JSON.stringify(currentState) !== JSON.stringify(previousState);
119+
return stringify(currentState) !== stringify(previousState);
124120
});
125121
</script>
126122

src/Frontend/src/stores/SagaDiagramStore.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ref, watch } from "vue";
33
import { SagaHistory, SagaMessage } from "@/resources/SagaHistory";
44
import { useFetchFromServiceControl } from "@/composables/serviceServiceControlUrls";
55
import Message from "@/resources/Message";
6+
import { parse } from "lossless-json";
67

78
const StandardKeys = ["$type", "Id", "Originator", "OriginalMessageId"];
89
export interface SagaMessageDataItem {
@@ -155,12 +156,11 @@ export const useSagaDiagramStore = defineStore("SagaDiagramStore", () => {
155156
}
156157
}
157158

158-
// Replace or modify the existing processJsonValues function
159159
function processJsonValues(jsonBody: string | Record<string, unknown>): SagaMessageDataItem[] {
160160
let parsedBody: Record<string, unknown>;
161161
if (typeof jsonBody === "string") {
162162
try {
163-
parsedBody = JSON.parse(jsonBody);
163+
parsedBody = parse(jsonBody) as Record<string, unknown>;
164164
} catch (e) {
165165
console.error("Error parsing JSON:", e);
166166
return [];

0 commit comments

Comments
 (0)