Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): hold the infrastructure form until the saved config loads

Yudhi Armyndharisff02572fe5ff
diff --git a/dashboard/src/pages/Infrastructure.test.ts b/dashboard/src/pages/Infrastructure.test.ts
index 667bbf2b2..2fb59fa11 100644
--- a/dashboard/src/pages/Infrastructure.test.ts
+++ b/dashboard/src/pages/Infrastructure.test.ts
@@ -81,7 +81,12 @@ const CURRENT_ENGINE = { engineType: 'whatsapp-web.js' };
// Per-test fixture swaps for the three responses whose disagreement the engine-pin tests turn on
// (running engine vs saved engine vs whether ENGINE_TYPE is pinned). Reset in afterEach so the
// smoke tests above keep seeing the stock fixtures.
-let overrides: { status?: InfraStatus; saved?: SavedConfig; currentEngine?: { engineType: string } } = {};
+let overrides: {
+ status?: InfraStatus;
+ saved?: SavedConfig;
+ savedFails?: boolean;
+ currentEngine?: { engineType: string };
+} = {};
// ENGINE_TYPE supplied by the container environment, so the dashboard cannot change it.
const PINNED_STATUS: InfraStatus = { ...INFRA_STATUS, envPinned: ['ENGINE_TYPE'] };
@@ -142,8 +147,10 @@ function installFetchStub(): void {
if (method === 'GET' && path === '/api/infra/status')
return Promise.resolve(jsonResponse(overrides.status ?? INFRA_STATUS));
- if (method === 'GET' && path === '/api/infra/config')
+ if (method === 'GET' && path === '/api/infra/config') {
+ if (overrides.savedFails) return Promise.resolve(jsonResponse({ message: 'boom' }, 500));
return Promise.resolve(jsonResponse(overrides.saved ?? SAVED_CONFIG));
+ }
if (method === 'GET' && path === '/api/infra/engines') return Promise.resolve(jsonResponse(ENGINES));
if (method === 'GET' && path === '/api/infra/engines/current')
return Promise.resolve(jsonResponse(overrides.currentEngine ?? CURRENT_ENGINE));
@@ -269,6 +276,19 @@ test('Infrastructure renders and the config form hydrates from /status and /conf
});
});
+// The detail fields (username, database, schema, bucket, engine options) come only from /config.
+// Rendered without it, the form holds its built-in defaults, and a Save would write them over the
+// stored external database, S3 and engine settings.
+test('a failed /config read offers no Save, so defaults cannot overwrite the stored settings', async () => {
+ const { screen } = rtl;
+ resetFetchCalls();
+ overrides = { savedFails: true };
+ renderInfrastructure();
+
+ await screen.findByText("Couldn't load the current infrastructure status. Refresh to try again.");
+ assert.ok(!screen.queryByRole('button', { name: 'Save Configuration' }), 'Save offered without the saved config');
+});
+
/**
* Every toggle is a bare checkbox inside a `<label class="toggle-switch">` whose only other child is
* the decorative slider span, so the wrapping label contributes no text: a screen reader announced
diff --git a/dashboard/src/pages/Infrastructure.tsx b/dashboard/src/pages/Infrastructure.tsx
index bcd2bbf6e..ac4b59425 100644
--- a/dashboard/src/pages/Infrastructure.tsx
+++ b/dashboard/src/pages/Infrastructure.tsx
@@ -42,7 +42,7 @@ export function Infrastructure() {
useDocumentTitle(t('infrastructure.title'));
const toast = useToast();
const { data: infraStatus, isLoading: loading, isError: statusError } = useInfraStatusQuery();
- const { data: savedConfig } = useInfraConfigQuery();
+ const { data: savedConfig, isLoading: configLoading } = useInfraConfigQuery();
const { data: engines = [] } = useEnginesQuery();
const { data: currentEngineData } = useCurrentEngineQuery();
const currentEngine = currentEngineData?.engineType ?? '';
@@ -98,7 +98,7 @@ export function Infrastructure() {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [infraStatus]);
- if (loading) {
+ if (loading || configLoading) {
return (
<div className="infrastructure-page infra-loading">
<Loader2 className="animate-spin" size={32} />
@@ -109,7 +109,9 @@ export function Infrastructure() {
// If the live infrastructure status can't be loaded, do NOT render the editable form: it would seed
// from component defaults (sqlite/local/built-in:false) and a Save could flip a running backend to
// external+empty. Show an error + retry instead. (#488 review)
- if (statusError || !infraStatus) {
+ // Likewise without the saved config: the database, storage and engine detail fields hydrate only
+ // from it, and a Save sends every one of them.
+ if (statusError || !infraStatus || !savedConfig) {
return (
<div className="infrastructure-page">
<PageHeader title={t('infrastructure.title')} subtitle={t('infrastructure.subtitle')} />