Skip to content

Commit 18a471f

Browse files
committed
Adding auto refresh
More
1 parent f0d8d2e commit 18a471f

File tree

7 files changed

+67
-23
lines changed

7 files changed

+67
-23
lines changed

src/Frontend/src/components/failedmessages/EditRetryDialog2.vue

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import parseContentType from "@/composables/contentTypeParser";
77
import { CodeLanguage } from "@/components/codeEditorTypes";
88
import CodeEditor from "@/components/CodeEditor.vue";
99
import { useMessageViewStore } from "@/stores/MessageViewStore.ts";
10+
import { storeToRefs } from "pinia";
11+
import LoadingSpinner from "@/components/LoadingSpinner.vue";
1012
1113
interface HeaderWithEditing extends Header {
1214
isLocked: boolean;
@@ -51,8 +53,9 @@ const showEditAndRetryConfirmation = ref(false);
5153
const showCancelConfirmation = ref(false);
5254
const showEditRetryGenericError = ref(false);
5355
const store = useMessageViewStore();
54-
const id = computed(() => store.state.data.id ?? "");
55-
const messageBody = computed(() => store.body.data.value);
56+
const { state, headers, body, edit_and_retry_config } = storeToRefs(store);
57+
const id = computed(() => state.value.data.id ?? "");
58+
const messageBody = computed(() => body.value.data.value);
5659
5760
watch(messageBody, (newValue) => {
5861
if (newValue !== origMessageBody) {
@@ -119,17 +122,17 @@ async function retryEditedMessage() {
119122
}
120123
121124
function initializeMessageBodyAndHeaders() {
122-
origMessageBody = store.body.data.value ?? "";
125+
origMessageBody = body.value.data.value ?? "";
123126
localMessage.value = {
124127
isBodyChanged: false,
125128
isBodyEmpty: false,
126129
isContentTypeSupported: false,
127130
bodyContentType: undefined,
128-
bodyUnavailable: store.body.not_found ?? false,
131+
bodyUnavailable: body.value.not_found ?? false,
129132
isEvent: false,
130-
retried: store.state.data.failure_status.retried ?? false,
131-
headers: store.headers.data.map((header: Header) => ({ ...header })) as HeaderWithEditing[],
132-
messageBody: store.body.data.value ?? "",
133+
retried: state.value.data.failure_status.retried ?? false,
134+
headers: headers.value.data.map((header: Header) => ({ ...header })) as HeaderWithEditing[],
135+
messageBody: body.value.data.value ?? "",
133136
};
134137
localMessage.value.isBodyEmpty = false;
135138
localMessage.value.isBodyChanged = false;
@@ -143,17 +146,17 @@ function initializeMessageBodyAndHeaders() {
143146
const messageIntent = getMessageIntent();
144147
localMessage.value.isEvent = messageIntent === "Publish";
145148
146-
for (let index = 0; index < store.headers.data.length; index++) {
147-
const header: HeaderWithEditing = store.headers.data[index] as HeaderWithEditing;
149+
for (let index = 0; index < headers.value.data.length; index++) {
150+
const header: HeaderWithEditing = headers.value.data[index] as HeaderWithEditing;
148151
149152
header.isLocked = false;
150153
header.isSensitive = false;
151154
header.isMarkedAsRemoved = false;
152155
header.isChanged = false;
153156
154-
if (store.edit_and_retry_config.locked_headers.includes(header.key)) {
157+
if (edit_and_retry_config.value.locked_headers.includes(header.key)) {
155158
header.isLocked = true;
156-
} else if (store.edit_and_retry_config.sensitive_headers.includes(header.key)) {
159+
} else if (edit_and_retry_config.value.sensitive_headers.includes(header.key)) {
157160
header.isSensitive = true;
158161
}
159162
@@ -220,7 +223,8 @@ onMounted(() => {
220223
</table>
221224
<div role="tabpanel" v-if="panel === 2 && !localMessage.bodyUnavailable" style="height: calc(100% - 260px)">
222225
<div style="margin-top: 1.25rem">
223-
<CodeEditor aria-label="message body" :read-only="!localMessage.isContentTypeSupported" v-model="localMessage.messageBody" :language="localMessage.language" :show-gutter="true"></CodeEditor>
226+
<LoadingSpinner v-if="body.loading" />
227+
<CodeEditor v-else aria-label="message body" :read-only="!localMessage.isContentTypeSupported" v-model="localMessage.messageBody" :language="localMessage.language" :show-gutter="true"></CodeEditor>
224228
</div>
225229
<span class="empty-error" v-if="localMessage.isBodyEmpty"><i class="fa fa-exclamation-triangle"></i> Message body cannot be empty</span>
226230
<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>

src/Frontend/src/components/messages/DeleteMessageButton.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { showToastAfterOperation } from "@/composables/toast.ts";
66
import { TYPE } from "vue-toastification";
77
import { MessageStatus } from "@/resources/Message.ts";
88
import { storeToRefs } from "pinia";
9+
import { FailedMessageStatus } from "@/resources/FailedMessage.ts";
910
1011
const store = useMessageViewStore();
1112
const { state } = storeToRefs(store);
@@ -20,7 +21,8 @@ const handleConfirm = async () => {
2021
2122
const message = `Deleting the message ${state.value.data.id} ...`;
2223
await showToastAfterOperation(store.archiveMessage, TYPE.INFO, "Info", message);
23-
state.value.data.failure_status.archiving = true;
24+
25+
await store.pollForNextUpdate(FailedMessageStatus.Archived);
2426
};
2527
</script>
2628

src/Frontend/src/components/messages/EditAndRetryButton.vue

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { TYPE } from "vue-toastification";
66
import EditRetryDialog2 from "@/components/failedmessages/EditRetryDialog2.vue";
77
import { MessageStatus } from "@/resources/Message.ts";
88
import { storeToRefs } from "pinia";
9+
import { FailedMessageStatus } from "@/resources/FailedMessage.ts";
910
1011
const store = useMessageViewStore();
1112
const { state } = storeToRefs(store);
@@ -19,13 +20,19 @@ const handleConfirm = async () => {
1920
2021
const message = `Retrying the edited message ${state.value.data.id} ...`;
2122
await showToastAfterOperation(store.retryMessage, TYPE.INFO, "Info", message);
22-
state.value.data.failure_status.retried = true;
23+
24+
await store.pollForNextUpdate(FailedMessageStatus.Resolved);
2325
};
26+
27+
async function openDialog() {
28+
await store.downloadBody();
29+
isConfirmDialogVisible.value = true;
30+
}
2431
</script>
2532

2633
<template>
2734
<template v-if="isVisible">
28-
<button type="button" class="btn btn-default" aria-label="Edit & retry" :disabled="isDisabled" @click="isConfirmDialogVisible = true"><i class="fa fa-pencil"></i> Edit & retry</button>
35+
<button type="button" class="btn btn-default" aria-label="Edit & retry" :disabled="isDisabled" @click="openDialog"><i class="fa fa-pencil"></i> Edit & retry</button>
2936
<Teleport to="#modalDisplay">
3037
<EditRetryDialog2 v-if="isConfirmDialogVisible" @cancel="isConfirmDialogVisible = false" @confirm="handleConfirm"></EditRetryDialog2>
3138
</Teleport>

src/Frontend/src/components/messages/MessageView2.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ watch(
9191
<div class="row">
9292
<div class="col-sm-12 no-side-padding">
9393
<div class="metadata group-message-count message-metadata">
94-
<MetadataLabel v-if="state.data.failure_status.retried" tooltip="Message is being retried" type="info" text="Retried" />
94+
<MetadataLabel v-if="state.data.failure_status.retry_in_progress" tooltip="Message is being added to the retries queue" type="info" text="Requesting retry..." />
95+
<MetadataLabel v-if="state.data.failure_status.retried" tooltip="Message is enqueued to be retried" type="info" text="Waiting for retry" />
9596
<MetadataLabel v-if="state.data.failure_status.restoring" tooltip="Message is being restored" type="info" text="Restoring..." />
9697
<MetadataLabel v-if="state.data.failure_status.archiving" tooltip="Message is being deleted" type="info" text="Deleting..." />
9798
<MetadataLabel v-if="state.data.failure_status.archived" tooltip="Message is deleted" type="warning" text="Deleted" />

src/Frontend/src/components/messages/RestoreMessageButton.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,26 @@ import { computed, ref } from "vue";
55
import { showToastAfterOperation } from "@/composables/toast.ts";
66
import { TYPE } from "vue-toastification";
77
import { storeToRefs } from "pinia";
8+
import { FailedMessageStatus } from "@/resources/FailedMessage.ts";
89
910
const store = useMessageViewStore();
1011
const { state } = storeToRefs(store);
1112
const isConfirmDialogVisible = ref(false);
1213
13-
const failureStatus = computed(() => state.value.data.failure_status);
14+
const isVisible = computed(() => state.value.data.failure_status.archived);
1415
1516
const handleConfirm = async () => {
1617
isConfirmDialogVisible.value = false;
1718
1819
const message = `Restoring the message ${state.value.data.id} ...`;
1920
await showToastAfterOperation(store.restoreMessage, TYPE.INFO, "Info", message);
20-
state.value.data.failure_status.restoring = true;
21+
22+
await store.pollForNextUpdate(FailedMessageStatus.Unresolved);
2123
};
2224
</script>
2325

2426
<template>
25-
<template v-if="failureStatus.archived">
27+
<template v-if="isVisible">
2628
<button type="button" class="btn btn-default" @click="isConfirmDialogVisible = true"><i class="fa fa-undo"></i> Restore</button>
2729
<Teleport to="#modalDisplay">
2830
<ConfirmDialog

src/Frontend/src/components/messages/RetryMessageButton.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { showToastAfterOperation } from "@/composables/toast.ts";
66
import { TYPE } from "vue-toastification";
77
import { MessageStatus } from "@/resources/Message.ts";
88
import { storeToRefs } from "pinia";
9+
import { FailedMessageStatus } from "@/resources/FailedMessage.ts";
910
1011
const store = useMessageViewStore();
1112
const { state } = storeToRefs(store);
@@ -20,7 +21,8 @@ const handleConfirm = async () => {
2021
2122
const message = `Retrying the message ${state.value.data.id} ...`;
2223
await showToastAfterOperation(store.retryMessage, TYPE.INFO, "Info", message);
23-
state.value.data.failure_status.retried = true;
24+
25+
await store.pollForNextUpdate(FailedMessageStatus.Resolved);
2426
};
2527
</script>
2628

src/Frontend/src/stores/MessageViewStore.ts

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,6 @@ export const useMessageViewStore = defineStore("MessageViewStore", () => {
120120
const countdown = moment(state.data.failure_metadata.last_modified).add(error_retention_period, "hours");
121121
state.data.failure_status.delete_soon = countdown < moment();
122122
state.data.failure_metadata.deleted_in = countdown.format();
123-
124-
// TODO: Maintain the mutations of the message in memory until the api returns a newer modified message
125123
}
126124

127125
async function loadMessage(messageId: string, id: string) {
@@ -229,8 +227,35 @@ export const useMessageViewStore = defineStore("MessageViewStore", () => {
229227
async function retryMessage() {
230228
if (state.data.id) {
231229
await useRetryMessages([state.data.id]);
232-
state.data.failure_status.retried = true;
230+
state.data.failure_status.retry_in_progress = true;
231+
}
232+
}
233+
234+
async function pollForNextUpdate(status: FailedMessageStatus) {
235+
if (!state.data.id) {
236+
return;
237+
}
238+
239+
let maxRetries = 60; // We try for 60 seconds
240+
241+
do {
242+
// eslint-disable-next-line no-await-in-loop
243+
await new Promise((resolve) => setTimeout(resolve, 1000));
244+
// eslint-disable-next-line no-await-in-loop
245+
const [, data] = await useTypedFetchFromServiceControl<FailedMessage>(`errors/last/${state.data.id}`);
246+
if (status === data.status) {
247+
break;
248+
}
249+
} while (maxRetries-- > 0);
250+
251+
if (maxRetries === 0) {
252+
// It never changed so no need to refresh UI
253+
return;
233254
}
255+
256+
const id = state.data.id;
257+
reset();
258+
await loadFailedMessage(id);
234259
}
235260

236261
async function exportMessage() {
@@ -278,6 +303,7 @@ export const useMessageViewStore = defineStore("MessageViewStore", () => {
278303
restoreMessage,
279304
retryMessage,
280305
conversationData,
306+
pollForNextUpdate,
281307
};
282308
});
283309

0 commit comments

Comments
 (0)