Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): follow pinned settings in the restart warning
Yudhi Armyndharis9c577100ef55
diff --git a/dashboard/src/pages/Infrastructure.css b/dashboard/src/pages/Infrastructure.cssindex 7367fa581..fb0eb1b1f 100644--- a/dashboard/src/pages/Infrastructure.css+++ b/dashboard/src/pages/Infrastructure.css@@ -532,6 +532,8 @@margin: 0 0 1rem;font-size: 0.8125rem;color: var(--warning-text);+ /* A long variable name (DATABASE_SSL_REJECT_UNAUTHORIZED) breaks instead of running past a narrow card. */+ overflow-wrap: anywhere;}.infrastructure-page .env-pin-note svg {flex-shrink: 0;diff --git a/dashboard/src/pages/Infrastructure.test.ts b/dashboard/src/pages/Infrastructure.test.tsindex c0cd2cefa..aa52aeeb6 100644--- a/dashboard/src/pages/Infrastructure.test.ts+++ b/dashboard/src/pages/Infrastructure.test.ts@@ -1688,6 +1688,173 @@ test('a host the environment pins is named under its Use Built-in toggle', asyncassert.equal(hostPinNoteOf(container, 'Use Built-in MinIO Container'), 'S3_ENDPOINT');});+// Every other setting a save writes, as GET /infra/status reports it: external services so each field shows.+const RUNNING_EXTERNAL_ALL: InfraStatus = {+ ...INFRA_STATUS,+ database: { connected: true, type: 'postgres', host: 'db.ext.example', builtIn: false },+ redis: { enabled: true, connected: true, host: 'cache.ext.example', port: 6379, builtIn: false },+ queue: { enabled: true, webhooks: { pending: 0, completed: 0, failed: 0 } },+ storage: { type: 's3', bucket: 'media', endpoint: 'https://s3.ext.example', builtIn: false, s3Available: true },+};+const SAVED_EXTERNAL_ALL: SavedConfig = {+ ...SAVED_CONFIG,+ database: { ...SAVED_CONFIG.database, host: 'db.ext.example', sslEnabled: true },+ redis: {+ enabled: true,+ builtIn: false,+ builtInSet: true,+ host: 'cache.ext.example',+ port: '6379',+ passwordSet: true,+ },+ queue: { enabled: true },+ storage: {+ ...SAVED_CONFIG.storage,+ type: 's3',+ s3Bucket: 'media',+ s3Region: 'eu-west-1',+ s3Endpoint: 'https://s3.ext.example',+ s3CredentialsSet: true,+ },+};+const DETAIL_PINS = {+ database: [+ 'POSTGRES_BUILTIN',+ 'DATABASE_PORT',+ 'DATABASE_USERNAME',+ 'DATABASE_PASSWORD',+ 'DATABASE_NAME',+ 'DATABASE_POOL_SIZE',+ 'POSTGRES_SCHEMA',+ 'DATABASE_SSL',+ 'DATABASE_SSL_REJECT_UNAUTHORIZED',+ ],+ redis: ['REDIS_BUILTIN', 'REDIS_PORT', 'REDIS_PASSWORD', 'QUEUE_ENABLED'],+ storage: ['MINIO_BUILTIN', 'S3_BUCKET', 'S3_REGION', 'S3_ACCESS_KEY_ID', 'S3_SECRET_ACCESS_KEY'],+};++function infraCard(container: HTMLElement, heading: string): HTMLElement {+ const card = Array.from(container.querySelectorAll<HTMLElement>('.infra-card')).find(+ c => c.querySelector('h2')?.textContent === heading,+ );+ if (!card) throw new Error(`no card "${heading}"`);+ return card;+}++/** The variables the pin notes right after an element name, in order. */+function pinNamesAfter(element: Element | null | undefined): string[] {+ const names: string[] = [];+ for (+ let next = element?.nextElementSibling;+ next?.classList.contains('env-pin-note');+ next = next.nextElementSibling+ ) {+ const name = ENV_PIN_NOTE.exec(next.textContent?.trim() ?? '')?.[1];+ if (name) names.push(name);+ }+ return names;+}++test('every setting a save writes names its variable beside its field when the environment pins it', async () => {+ const { screen } = rtl;+ resetFetchCalls();+ overrides = {+ status: { ...RUNNING_EXTERNAL_ALL, envPinned: Object.values(DETAIL_PINS).flat() },+ saved: SAVED_EXTERNAL_ALL,+ };+ const { container } = renderInfrastructure();++ await screen.findByText('Database Configuration');+ await awaitSeeded(container);++ const db = infraCard(container, 'Database Configuration');+ const redis = infraCard(container, 'Redis');+ const storage = infraCard(container, 'Storage Configuration');+ const row = (card: HTMLElement, label: string) => fieldInput(card, label).closest('.form-row');+ const toggleRow = (card: HTMLElement, label: string) => toggleInput(card, label).closest('.toggle-row');+ assert.deepEqual(+ {+ dbBuiltIn: pinNamesAfter(toggleRow(db, 'Use Built-in PostgreSQL Container')),+ dbHostRow: pinNamesAfter(row(db, 'Host')),+ dbCredentialRow: pinNamesAfter(row(db, 'Username')),+ dbNameRow: pinNamesAfter(row(db, 'Database Name')),+ dbSchemaRow: pinNamesAfter(row(db, 'Schema')),+ dbSsl: pinNamesAfter(toggleRow(db, 'SSL Connection')),+ dbSslVerify: pinNamesAfter(toggleRow(db, 'Verify SSL Certificate')),+ redisBuiltIn: pinNamesAfter(toggleRow(redis, 'Use Built-in Redis Container')),+ redisRow: pinNamesAfter(row(redis, 'Host')),+ queue: pinNamesAfter(toggleRow(redis, 'Enable BullMQ Queue System')),+ storageBuiltIn: pinNamesAfter(toggleRow(storage, 'Use Built-in MinIO Container')),+ storageBucketRow: pinNamesAfter(row(storage, 'Bucket Name')),+ storageKeyRow: pinNamesAfter(row(storage, 'Access Key')),+ },+ {+ dbBuiltIn: ['POSTGRES_BUILTIN'],+ dbHostRow: ['DATABASE_PORT'],+ dbCredentialRow: ['DATABASE_USERNAME', 'DATABASE_PASSWORD'],+ dbNameRow: ['DATABASE_NAME', 'DATABASE_POOL_SIZE'],+ dbSchemaRow: ['POSTGRES_SCHEMA'],+ dbSsl: ['DATABASE_SSL'],+ dbSslVerify: ['DATABASE_SSL_REJECT_UNAUTHORIZED'],+ redisBuiltIn: ['REDIS_BUILTIN'],+ redisRow: ['REDIS_PORT', 'REDIS_PASSWORD'],+ queue: ['QUEUE_ENABLED'],+ storageBuiltIn: ['MINIO_BUILTIN'],+ storageBucketRow: ['S3_BUCKET', 'S3_REGION'],+ storageKeyRow: ['S3_ACCESS_KEY_ID', 'S3_SECRET_ACCESS_KEY'],+ },+ );+ const notes = Array.from(container.querySelectorAll('.env-pin-note')).map(note => note.textContent?.trim() ?? '');+ assert.equal(notes.length, Object.values(DETAIL_PINS).flat().length, 'one note per pinned variable');+});++test('without a reported pin the settings a save writes show no pin note', async () => {+ const { screen } = rtl;+ resetFetchCalls();+ overrides = { status: { ...RUNNING_EXTERNAL_ALL, envPinned: [] }, saved: SAVED_EXTERNAL_ALL };+ const { container } = renderInfrastructure();++ await screen.findByText('Database Configuration');+ await awaitSeeded(container);++ const notes = Array.from(container.querySelectorAll('.env-pin-note')).map(note => note.textContent?.trim() ?? '');+ assert.deepEqual(notes, []);+});++// The next boot reads a pinned bucket, port or database name whatever the form holds, so an edit there moves nothing;+// a field beside it the pin does not cover still does.+for (const { pin, label, value, warns } of [+ { pin: 'S3_BUCKET', label: 'Bucket Name', value: 'newbucket', warns: false },+ { pin: 'S3_BUCKET', label: 'Custom Endpoint (optional)', value: 'https://s3.new.example', warns: true },+ { pin: 'DATABASE_NAME', label: 'Database Name', value: 'otherdb', warns: false },+ { pin: 'DATABASE_PORT', label: 'Port', value: '5433', warns: false },+ { pin: 'DATABASE_NAME', label: 'Host', value: 'db.new.example', warns: true },+ { pin: 'DATABASE_PORT', label: 'Database Name', value: 'otherdb', warns: true },+]) {+ test(`with ${pin} pinned, an edit of ${label} ${warns ? 'still warns of a data move' : 'warns of no data move'}`, async () => {+ const { screen, fireEvent, within } = rtl;+ resetFetchCalls();+ overrides = {+ status: { ...RUNNING_EXTERNAL_ALL, envPinned: [pin] },+ saved: {+ ...SAVED_EXTERNAL_ALL,+ database: { ...SAVED_EXTERNAL_ALL.database, port: '6432', database: 'appdb', sslEnabled: false },+ },+ };+ const { container } = renderInfrastructure();++ await screen.findByText('Database Configuration');+ await awaitSeeded(container);+ const card = infraCard(container, pin.startsWith('S3_') ? 'Storage Configuration' : 'Database Configuration');+ fireEvent.change(fieldInput(card, label), { target: { value } });+ fireEvent.click(screen.getByRole('button', { name: 'Save Configuration' }));++ const dialog = await screen.findByRole('dialog');+ const warning = pin.startsWith('S3_') ? STORAGE_WARNING : DB_SWITCH_WARNING;+ assert.equal(within(dialog).queryByText(warning, { exact: false }) !== null, warns, 'the data-backend warning');+ });+}+test('the engine radio seeds from the effective engine when ENGINE_TYPE is pinned', async () => {const { screen, waitFor } = rtl;resetFetchCalls();diff --git a/dashboard/src/pages/Infrastructure.tsx b/dashboard/src/pages/Infrastructure.tsxindex 91bb50e47..799dea1dd 100644--- a/dashboard/src/pages/Infrastructure.tsx+++ b/dashboard/src/pages/Infrastructure.tsx@@ -108,7 +108,8 @@ export function Infrastructure() {const dbExternalRetarget =!db.builtIn &&!!loaded &&- (db.port !== (loaded.database.port || '5432') || db.database !== (loaded.database.database || 'openwa'));+ ((!pinned('DATABASE_PORT') && db.port !== (loaded.database.port || '5432')) ||+ (!pinned('DATABASE_NAME') && db.database !== (loaded.database.database || 'openwa')));const dbSwitch =!!infraStatus &&(dbType !== infraStatus.database.type ||@@ -123,7 +124,9 @@ export function Infrastructure() {const endpoint =pinned('S3_ENDPOINT')?.storage.s3Endpoint ?? (storageBuiltIn ? 'http://minio:9000' : storage.s3Endpoint);const bucket =- (storageBuiltIn ? (keepsBucket ? savedConfig?.storage.s3Bucket : 'openwa') : storage.s3Bucket) || 'openwa';+ (pinned('S3_BUCKET')?.storage.s3Bucket ??+ (storageBuiltIn ? (keepsBucket ? savedConfig?.storage.s3Bucket : 'openwa') : storage.s3Bucket)) ||+ 'openwa';const storageSwitch =!!infraStatus &&(storageType !== infraStatus.storage.type ||@@ -258,7 +261,8 @@ export function Infrastructure() {// Pin-only: PUPPETEER_ARGS cannot go through settingNote, because the running list is re-tokenized and// gains the pinned `--lang` flag, so it never string-compares equal to the saved value. The headless// flag and the two paths do have a running and a saved value, but show only a reported pin as well, and so- // do the three datastore hosts, under the Use Built-in toggle a pinned host overrides.+ // do the three datastore hosts, under the Use Built-in toggle a pinned host overrides, and every other setting a+ // save writes, after the row that holds its field (a note inside a narrow port field would not fit).const pinNote = (envKey: string) =>infraStatus?.envPinned?.includes(envKey) ? (<p className="env-pin-note">@@ -370,6 +374,7 @@ export function Infrastructure() {namesBundledContainer('postgres', infraStatus.database.host),)}{pinNote('DATABASE_HOST')}+ {pinNote('POSTGRES_BUILTIN')}{!configForm.dbConfig.builtIn && (<div className="config-form">@@ -393,6 +398,7 @@ export function Infrastructure() {/></div></div>+ {pinNote('DATABASE_PORT')}<div className="form-row"><div className="form-group"><label htmlFor="infra-3">{t('common.username')}</label>@@ -414,6 +420,8 @@ export function Infrastructure() {/></div></div>+ {pinNote('DATABASE_USERNAME')}+ {pinNote('DATABASE_PASSWORD')}<div className="form-row"><div className="form-group"><label htmlFor="infra-5">{t('infrastructure.database.dbName')}</label>@@ -444,6 +452,8 @@ export function Infrastructure() {/></div></div>+ {pinNote('DATABASE_NAME')}+ {pinNote('DATABASE_POOL_SIZE')}<div className="form-row"><div className="form-group"><label htmlFor="infra-7">{t('infrastructure.database.schema')}</label>@@ -457,6 +467,7 @@ export function Infrastructure() {<small>{t('infrastructure.database.schemaDesc')}</small></div></div>+ {pinNote('POSTGRES_SCHEMA')}<div className="toggle-row"><div className="toggle-info"><span id="toggle-db-ssl">{t('infrastructure.database.ssl')}</span>@@ -472,6 +483,7 @@ export function Infrastructure() {<span className="toggle-slider"></span></label></div>+ {pinNote('DATABASE_SSL')}{configForm.dbConfig.sslEnabled && (<div className="toggle-row"><div className="toggle-info">@@ -489,6 +501,7 @@ export function Infrastructure() {</label></div>)}+ {configForm.dbConfig.sslEnabled && pinNote('DATABASE_SSL_REJECT_UNAUTHORIZED')}</div>)}</>@@ -675,6 +688,7 @@ export function Infrastructure() {namesBundledContainer('redis', infraStatus.redis.host),)}{pinNote('REDIS_HOST')}+ {pinNote('REDIS_BUILTIN')}{!configForm.redisConfig.builtIn && (<div className="config-form">@@ -709,6 +723,8 @@ export function Infrastructure() {/></div></div>+ {pinNote('REDIS_PORT')}+ {pinNote('REDIS_PASSWORD')}</div>)}@@ -876,6 +892,7 @@ export function Infrastructure() {namesBundledContainer('minio', infraStatus.storage.endpoint),)}{pinNote('S3_ENDPOINT')}+ {pinNote('MINIO_BUILTIN')}{!configForm.storageConfig.builtIn && (<>@@ -899,6 +916,8 @@ export function Infrastructure() {/></div></div>+ {pinNote('S3_BUCKET')}+ {pinNote('S3_REGION')}<div className="form-row"><div className="form-group"><label htmlFor="infra-16">{t('infrastructure.storage.accessKey')}</label>@@ -920,6 +939,8 @@ export function Infrastructure() {/></div></div>+ {pinNote('S3_ACCESS_KEY_ID')}+ {pinNote('S3_SECRET_ACCESS_KEY')}<div className="form-group"><label htmlFor="infra-18">{t('infrastructure.storage.endpoint')}</label><input