Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): size the restart progress bar to the server estimate
Yudhi Armyndharisbc6084cdcaa2
diff --git a/dashboard/src/hooks/useRestartFlow.ts b/dashboard/src/hooks/useRestartFlow.tsindex 7a6d30979..7d2ae894c 100644--- a/dashboard/src/hooks/useRestartFlow.ts+++ b/dashboard/src/hooks/useRestartFlow.ts@@ -17,6 +17,8 @@ export interface RestartOpenRequest {export interface RestartFlow {showRestartModal: boolean;restartCountdown: number;+ /** The countdown's starting value, the server's estimate once it answers; the progress bar's 100%. */+ restartTotal: number;restartStatus: RestartStatus;/** The server's reason when it refused the restart; shown in place of the generic error text. */restartError: string | null;@@ -44,6 +46,7 @@ export interface RestartFlow {export function useRestartFlow(): RestartFlow {const [showRestartModal, setShowRestartModal] = useState(false);const [restartCountdown, setRestartCountdown] = useState(0);+ const [restartTotal, setRestartTotal] = useState(30);const [restartStatus, setRestartStatus] = useState<RestartStatus>('idle');const [restartError, setRestartError] = useState<string | null>(null);const [restartWarnings, setRestartWarnings] = useState<string[]>([]);@@ -142,6 +145,7 @@ export function useRestartFlow(): RestartFlow {const start = async () => {setRestartStatus('restarting');setRestartCountdown(30);+ setRestartTotal(30);const profilesToRemove = profiles.running.filter(p => !profiles.pending.includes(p));@@ -152,7 +156,10 @@ export function useRestartFlow(): RestartFlow {try {const response = await infraApi.restart(profiles.pending, profilesToRemove);estimatedTime = response.estimatedTime;- if (response.estimatedTime) setRestartCountdown(response.estimatedTime);+ if (response.estimatedTime) {+ setRestartCountdown(response.estimatedTime);+ setRestartTotal(response.estimatedTime);+ }warnings = [...(response.orchestration?.errors ?? []), ...(response.removal?.errors ?? [])];setRestartWarnings(warnings);} catch (err) {@@ -198,6 +205,7 @@ export function useRestartFlow(): RestartFlow {return {showRestartModal,restartCountdown,+ restartTotal,restartStatus,restartError,restartWarnings,diff --git a/dashboard/src/pages/Infrastructure.test.ts b/dashboard/src/pages/Infrastructure.test.tsindex b89d36a31..181357156 100644--- a/dashboard/src/pages/Infrastructure.test.ts+++ b/dashboard/src/pages/Infrastructure.test.ts@@ -847,6 +847,23 @@ test('a 502 the gateway stamped with a code is a refusal, not an unknown outcomeassert.ok(within(dialog).getByText('Compose rejected the profile'), 'the server reason is not shown');});+test('the restart progress bar measures the server estimate, not a fixed 30 s', async () => {+ const { within } = rtl;+ resetFetchCalls();+ overrides = {+ readyFails: true,+ restart: () =>+ jsonResponse({ message: 'restarting', restarting: true, profiles: [], profilesToRemove: [], estimatedTime: 35 }),+ };+ const dialog = await clickRestartNow();++ // One second into a 35 s estimate. Against a fixed 30 s total the width would be negative, which+ // the style drops, leaving the bar empty until the countdown fell under 30.+ await within(dialog).findByText('Server restarting... 34s', undefined, { timeout: 2_000 });+ const fill = dialog.querySelector<HTMLElement>('.restart-progress-fill');+ assert.equal(fill?.style.width, `${(1 / 35) * 100}%`);+});+test('services that failed to start are shown after the restart instead of reloading over them',{ timeout: 15_000 },diff --git a/dashboard/src/pages/Infrastructure.tsx b/dashboard/src/pages/Infrastructure.tsxindex dc8ace95a..264217469 100644--- a/dashboard/src/pages/Infrastructure.tsx+++ b/dashboard/src/pages/Infrastructure.tsx@@ -885,7 +885,7 @@ export function Infrastructure() {style={{width:restartFlow.restartCountdown > 0- ? `${((30 - restartFlow.restartCountdown) / 30) * 100}%`+ ? `${((restartFlow.restartTotal - restartFlow.restartCountdown) / restartFlow.restartTotal) * 100}%`: '100%',}}/>