Skip to content

Commit 5a1dc38

Browse files
committed
move has saga watch from component to store
1 parent 02351a0 commit 5a1dc38

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

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

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import { computed, onUnmounted, watch } from "vue";
2+
import { computed, onUnmounted } from "vue";
33
import routeLinks from "@/router/routeLinks";
44
import { useSagaDiagramStore } from "@/stores/SagaDiagramStore";
55
import { useMessageStore } from "@/stores/MessageStore";
@@ -20,17 +20,6 @@ const { showMessageData } = storeToRefs(sagaDiagramStore);
2020
2121
const messageStore = useMessageStore();
2222
23-
//Watch for message and set saga ID when component mounts or message changes
24-
watch(
25-
() => messageStore.state,
26-
(newState) => {
27-
if (newState.data.invoked_saga.saga_id !== sagaDiagramStore.sagaId) {
28-
sagaDiagramStore.setSagaId(newState.data.invoked_saga.saga_id || "");
29-
}
30-
},
31-
{ immediate: true }
32-
);
33-
3423
onUnmounted(() => {
3524
sagaDiagramStore.clearSagaHistory();
3625
});

src/Frontend/src/stores/SagaDiagramStore.ts

Lines changed: 16 additions & 9 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 { useMessageStore } from "@/stores/MessageStore";
67
const StandardKeys = ["$type", "Id", "Originator", "OriginalMessageId"];
78
export interface SagaMessageDataItem {
89
key: string;
@@ -21,15 +22,22 @@ export const useSagaDiagramStore = defineStore("sagaHistory", () => {
2122
const fetchedMessages = ref(new Set<string>());
2223
const messagesData = ref<SagaMessageData[]>([]);
2324
const MessageBodyEndpoint = "messages/{0}/body";
24-
// Watch for changes to sagaId and fetch saga history data
25-
watch(sagaId, async (newSagaId) => {
26-
if (!newSagaId) {
27-
sagaHistory.value = null;
28-
return;
29-
}
3025

31-
await fetchSagaHistory(newSagaId);
32-
});
26+
const messageStore = useMessageStore();
27+
28+
//Watch for changes to messageStore.state.data.invoked_saga.has_saga
29+
watch(
30+
() => messageStore.state.data.invoked_saga.has_saga,
31+
async (newValue) => {
32+
if (newValue) {
33+
sagaId.value = messageStore.state.data.invoked_saga.saga_id || "";
34+
await fetchSagaHistory(sagaId.value);
35+
} else {
36+
clearSagaHistory();
37+
}
38+
},
39+
{ immediate: true }
40+
);
3341

3442
// Watch for changes to showMessageData
3543
watch([showMessageData, sagaHistory], async ([show, history]) => {
@@ -244,7 +252,6 @@ export const useSagaDiagramStore = defineStore("sagaHistory", () => {
244252
showMessageData,
245253
messagesData,
246254
setSagaId,
247-
fetchSagaHistory,
248255
clearSagaHistory,
249256
toggleMessageData,
250257
};

0 commit comments

Comments
 (0)