Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): stop warning of a database switch on unrelated saves
Yudhi Armyndharis6e80a9a85e6d
diff --git a/dashboard/src/pages/Infrastructure.test.ts b/dashboard/src/pages/Infrastructure.test.tsindex 181357156..fe504a28b 100644--- a/dashboard/src/pages/Infrastructure.test.ts+++ b/dashboard/src/pages/Infrastructure.test.ts@@ -449,6 +449,27 @@ test('a successful save opens the restart modal', async () => {within(dialog).getByRole('button', { name: 'Restart Later' });});+const DB_SWITCH_WARNING = 'The new database starts empty.';++test('an external Postgres on the default host, port and name does not warn of a switch on save', async () => {+ const { screen, fireEvent, within } = rtl;+ resetFetchCalls();+ // Nothing saved for the three keys (the environment supplies them, or they are left at the defaults):+ // /config reports '', while the form shows the host from /status and the defaults 5432 and openwa.+ overrides = {+ saved: { ...SAVED_CONFIG, database: { ...SAVED_CONFIG.database, host: '', port: '', database: '' } },+ };+ const { container } = renderInfrastructure();++ await screen.findByText('Database Configuration');+ await awaitConfigHydrated(container);+ fireEvent.click(screen.getByRole('button', { name: 'Save Configuration' }));++ const dialog = await screen.findByRole('dialog');+ within(dialog).getByText('Configuration saved');+ assert.ok(!within(dialog).queryByText(DB_SWITCH_WARNING, { exact: false }), 'an unchanged database is no switch');+});+const STATUS_LOAD_ERROR = "Couldn't load the current infrastructure status. Refresh to try again.";test('a failed first /status read shows the status error card and no form', async () => {diff --git a/dashboard/src/pages/Infrastructure.tsx b/dashboard/src/pages/Infrastructure.tsxindex 264217469..6c41a0d4d 100644--- a/dashboard/src/pages/Infrastructure.tsx+++ b/dashboard/src/pages/Infrastructure.tsx@@ -61,14 +61,15 @@ export function Infrastructure() {// empty-database / orphaned-media data move before it happens. A switch is: changing type;// flipping built-in↔external (different physical backend); OR retargeting an external Postgres// to a different host/port/database (also a different, empty DB). Host/port/db aren't all in- // /status, so compare the edited form against the still-cached saved config.+ // /status, so compare the edited form against the still-cached saved config. A key with nothing+ // saved reads '', and runs on the same fallback the form was seeded with.const dbExternalRetarget =configForm.dbConfig.type === 'postgres' &&!configForm.dbConfig.builtIn &&!!savedConfig &&- (configForm.dbConfig.host !== savedConfig.database.host ||- configForm.dbConfig.port !== savedConfig.database.port ||- configForm.dbConfig.database !== savedConfig.database.database);+ (configForm.dbConfig.host !== (savedConfig.database.host || infraStatus?.database.host || 'localhost') ||+ configForm.dbConfig.port !== (savedConfig.database.port || '5432') ||+ configForm.dbConfig.database !== (savedConfig.database.database || 'openwa'));const dbSwitch =!!infraStatus &&(configForm.dbConfig.type !== infraStatus.database.type ||