Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): send the built-in flag with a newly chosen datastore
Yudhi Armyndharis494fb84a3bfa
diff --git a/dashboard/src/hooks/useInfraConfigForm.test.ts b/dashboard/src/hooks/useInfraConfigForm.test.tsindex 9335ecc77..5246912b7 100644--- a/dashboard/src/hooks/useInfraConfigForm.test.ts+++ b/dashboard/src/hooks/useInfraConfigForm.test.ts@@ -407,3 +407,31 @@ test('another edit in the card keeps a built-in flag beside a pinned host out',assert.deepEqual([database?.builtIn, redis?.builtIn, storage?.builtIn], [undefined, undefined, undefined]);});++// Choosing the service in the form is a new selection, and its built-in mode is part of it: the stored flag belongs to+// the selection being left (the first boot writes it false next to SQLite), so the flag the toggle shows is sent.+test('a built-in flag beside a pinned host is sent with a selection the form changes', () => {+ const sqliteSaved: SavedConfig = {+ ...SAVED,+ database: { ...SAVED.database, type: 'sqlite', builtIn: true, builtInSet: false },+ redis: { ...SAVED.redis, enabled: false, builtIn: true, builtInSet: false },+ storage: { ...SAVED.storage, type: 'local', builtIn: true, builtInSet: false },+ };+ // The bundled containers run on the pinned hosts, so the toggles read on.+ const status: InfraStatus = {+ ...PINNED_HOSTS,+ database: { ...PINNED_HOSTS.database, host: 'postgres', builtIn: true },+ redis: { ...PINNED_HOSTS.redis, host: 'redis', builtIn: true },+ storage: { ...PINNED_HOSTS.storage, builtIn: true },+ };+ const { result } = renderForm({ status, saved: sqliteSaved });++ rtl.act(() => {+ result.current.updateDbConfig('type', 'postgres');+ result.current.setRedisEnabled(true);+ result.current.updateStorageConfig('type', 's3');+ });+ const { database, redis, storage } = result.current.buildSavePayload();++ assert.deepEqual([database?.builtIn, redis?.builtIn, storage?.builtIn], [true, true, true]);+});diff --git a/dashboard/src/hooks/useInfraConfigForm.ts b/dashboard/src/hooks/useInfraConfigForm.tsindex a3d588c01..974e660be 100644--- a/dashboard/src/hooks/useInfraConfigForm.ts+++ b/dashboard/src/hooks/useInfraConfigForm.ts@@ -255,7 +255,8 @@ export function useInfraConfigForm(// to the mode the card shows, and a stored selection of the other mode would drop them. Read at save time, like// the engine pin below. A pinned host decides the built-in mode the same way, and a flag of true sent beside it// writes the bundled credentials over stored ones the pinned host may still need, so an unused toggle there is- // left out too and the gateway keeps the stored flag.+ // left out too and the gateway keeps the stored flag, unless the form changes the selection the flag belongs to:+ // the stored flag is the one of the selection being left then (the first boot writes it false beside SQLite).const pinnedSeed = (key: string, touched: { current: boolean }) =>!touched.current && !!infraStatus?.envPinned?.includes(key);@@ -266,7 +267,10 @@ export function useInfraConfigForm(database: {...dbConfig,type: pinnedSeed('DATABASE_TYPE', dbTouched) ? undefined : dbConfig.type,- builtIn: pinnedSeed('DATABASE_HOST', dbBuiltInTouched) ? undefined : dbConfig.builtIn,+ builtIn:+ pinnedSeed('DATABASE_HOST', dbBuiltInTouched) && dbConfig.type === savedConfig?.database.type+ ? undefined+ : dbConfig.builtIn,password: dbConfig.builtIn ? '' : dbConfig.password,poolSize: Number.isInteger(dbConfig.poolSize) ? dbConfig.poolSize : undefined,},@@ -274,7 +278,10 @@ export function useInfraConfigForm(// whitelisted backend DTO so a valid dashboard save cannot be rejected as an unknown field.redis: {enabled: pinnedSeed('REDIS_ENABLED', redisEnabledTouched) ? undefined : redisEnabled,- builtIn: pinnedSeed('REDIS_HOST', redisBuiltInTouched) ? undefined : redisConfig.builtIn,+ builtIn:+ pinnedSeed('REDIS_HOST', redisBuiltInTouched) && redisEnabled === savedConfig?.redis.enabled+ ? undefined+ : redisConfig.builtIn,host: redisConfig.host,port: redisConfig.port,password: redisConfig.builtIn ? '' : redisConfig.password,@@ -283,7 +290,10 @@ export function useInfraConfigForm(storage: {...storageConfig,type: pinnedSeed('STORAGE_TYPE', storageTouched) ? undefined : storageConfig.type,- builtIn: pinnedSeed('S3_ENDPOINT', storageBuiltInTouched) ? undefined : storageConfig.builtIn,+ builtIn:+ pinnedSeed('S3_ENDPOINT', storageBuiltInTouched) && storageConfig.type === savedConfig?.storage.type+ ? undefined+ : storageConfig.builtIn,},// Only send `type` once we actually know it — either the radio seeded from /config or the// operator picked one. If /config never resolved, engineConfig.type still holds its useState