11<script setup lang="ts">
2- import { ref , watch } from " vue" ;
2+ import { ref , computed , watch } from " vue" ;
33import { useRouter } from " vue-router" ;
44import { useShowToast } from " ../../composables/toast" ;
55import NoData from " ../NoData.vue" ;
@@ -18,8 +18,10 @@ import { useStoreAutoRefresh } from "@/composables/useAutoRefresh";
1818import { storeToRefs } from " pinia" ;
1919import LoadingSpinner from " ../LoadingSpinner.vue" ;
2020
21- let pollingFaster = false ;
22- const { autoRefresh, isRefreshing, updateInterval } = useStoreAutoRefresh (" deletedMessageGroups" , useDeletedMessageGroupsStore , 5000 );
21+ const POLLING_INTERVAL_NORMAL = 5000 ;
22+ const POLLING_INTERVAL_FAST = 1000 ;
23+
24+ const { autoRefresh, isRefreshing, updateInterval } = useStoreAutoRefresh (" deletedMessageGroups" , useDeletedMessageGroupsStore , POLLING_INTERVAL_NORMAL );
2325const { store } = autoRefresh ();
2426const { archiveGroups, classifiers, selectedClassifier } = storeToRefs (store );
2527const router = useRouter ();
@@ -36,7 +38,6 @@ async function classifierChanged(classifier: string) {
3638
3739// Restore operation
3840function showRestoreGroupDialog(group : ExtendedFailureGroupView ) {
39- groupRestoreSuccessful .value = null ;
4041 selectedGroup .value = group ;
4142 showRestoreGroupModal .value = true ;
4243}
@@ -46,12 +47,10 @@ async function restoreGroup() {
4647 if (group ) {
4748 const { result, errorMessage } = await store .restoreGroup (group );
4849 if (! result ) {
49- groupRestoreSuccessful .value = false ;
5050 useShowToast (TYPE .ERROR , " Error" , ` Failed to restore the group: ${errorMessage } ` );
5151 } else {
5252 // We're starting a restore, poll more frequently
53- pollingFaster = true ;
54- updateInterval (1000 );
53+ updateInterval (POLLING_INTERVAL_FAST );
5554 groupRestoreSuccessful .value = true ;
5655 useShowToast (TYPE .INFO , " Info" , " Group restore started..." );
5756 }
@@ -83,19 +82,17 @@ function navigateToGroup(groupId: string) {
8382 router .push (routeLinks .failedMessage .deletedGroup .link (groupId ));
8483}
8584
86- function isRestoreInProgress() {
85+ const isRestoreInProgress = computed (() => {
8786 return archiveGroups .value .some ((group ) => group .workflow_state .status !== " none" && group .workflow_state .status !== " restorecompleted" );
88- }
87+ });
8988
90- watch (isRefreshing , () => {
91- // If we're currently polling at 5 seconds and there is a restore in progress, then change the polling interval to poll every 1 second
92- if (! pollingFaster && isRestoreInProgress ()) {
93- pollingFaster = true ;
94- updateInterval (1000 );
95- } else if (pollingFaster && ! isRestoreInProgress ()) {
96- // if we're currently polling every 1 second and all restores are done, change polling frequency back to every 5 seconds
97- pollingFaster = false ;
98- updateInterval (5000 );
89+ watch (isRestoreInProgress , (restoreInProgress ) => {
90+ if (restoreInProgress ) {
91+ // If there is a restore in progress, poll every 1 second
92+ updateInterval (POLLING_INTERVAL_FAST );
93+ } else {
94+ // If all restores are done, change polling frequency back to every 5 seconds
95+ updateInterval (POLLING_INTERVAL_NORMAL );
9996 }
10097});
10198 </script >
@@ -138,7 +135,7 @@ watch(isRefreshing, () => {
138135 <div class =" row" >
139136 <div class =" col-sm-12 no-mobile-side-padding" >
140137 <div v-if =" archiveGroups.length > 0" >
141- <div :class =" `row box box-group wf-${group.workflow_state.status} repeat-modify deleted-message-group`" v-for =" ( group, index) in archiveGroups" :key =" index " :disabled =" group.count == 0" @click.prevent =" navigateToGroup(group.id)" >
138+ <div :class =" `row box box-group wf-${group.workflow_state.status} repeat-modify deleted-message-group`" v-for =" group in archiveGroups" :key =" group.id " :disabled =" group.count == 0" @click.prevent =" navigateToGroup(group.id)" >
142139 <div class =" col-sm-12 no-mobile-side-padding" >
143140 <div class =" row" >
144141 <div class =" col-sm-12 no-side-padding" >
@@ -147,7 +144,7 @@ watch(isRefreshing, () => {
147144 <p class =" lead break" >{{ group.title }}</p >
148145 <p class =" metadata" v-if =" !isBeingRestored(group.workflow_state.status)" >
149146 <MetadataItem :icon =" faEnvelope" >
150- <span >{{ group.count }} message<span v-if =" group.count > 1" >s</span ></span >
147+ <span >{{ group.count }} message<template v-if =" group .count > 1 " >s</template ></span >
151148 <span v-if =" group.operation_remaining_count" > (currently restoring {{ group.operation_remaining_count }} </span >
152149 </MetadataItem >
153150
0 commit comments