Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): count connected sessions without statistics
Yudhi Armyndharis14eddaabdb01
diff --git a/dashboard/src/pages/Dashboard.test.ts b/dashboard/src/pages/Dashboard.test.tsindex 3430c02fc..47bf38c92 100644--- a/dashboard/src/pages/Dashboard.test.ts+++ b/dashboard/src/pages/Dashboard.test.ts@@ -182,6 +182,14 @@ test('a session list without statistics is counted by its own length', async ()assert.equal(document.querySelector('.section-subtitle')?.textContent, 'Showing 1 of 1 sessions');});+test('a connected session is counted without statistics, in the card and the header badge', async () => {+ sessionList = [READY_SESSION, { ...READY_SESSION, id: 'sess-2', name: 'Spare', status: 'disconnected' }];+ renderDashboard();+ await rtl.screen.findByText('Main');+ assert.equal(statValue('Connected Sessions'), '1');+ assert.equal(document.querySelector('.status-badge')?.textContent, 'Connected');+});+test('a read-only key is offered no Disconnect', async () => {webhooksStatus = 403;sessionList = [READY_SESSION];diff --git a/dashboard/src/pages/Dashboard.tsx b/dashboard/src/pages/Dashboard.tsxindex db484e4bb..e48fe7c30 100644--- a/dashboard/src/pages/Dashboard.tsx+++ b/dashboard/src/pages/Dashboard.tsx@@ -47,6 +47,8 @@ export function Dashboard() {const messagesToday = overview ? overview.messages.today.sent + overview.messages.today.received : unavailable;const totalMessages = overview ? overview.messages.sent + overview.messages.received : unavailable;const loading = loadingSessions;+ // Statistics that are unread or refused do not mean no session is connected: the list says which are.+ const readyCount = stats?.ready ?? sessions.filter(session => session.status === 'ready').length;// Only a read that never succeeded replaces the page: a failed background refetch keeps its cached// data (as the webhook card below does), so the last good view stays on screen.const error = sessionsNeverLoaded@@ -72,7 +74,7 @@ export function Dashboard() {// it overstates what an operator reads as "connected". READY is the only status where the// session can actually send and receive.label: t('dashboard.stats.activeSessions'),- value: stats?.ready ?? 0,+ value: readyCount,icon: MessageSquare,detail: stats ? t('dashboard.stats.sessionsDetail', { running: stats.active, total: stats.total }) : undefined,},@@ -116,8 +118,8 @@ export function Dashboard() {title={t('dashboard.title')}subtitle={t('dashboard.subtitle')}badge={- <span className={`status-badge ${stats && stats.ready > 0 ? 'connected' : 'disconnected'}`}>- {stats && stats.ready > 0 ? t('common.connected') : t('common.disconnected')}+ <span className={`status-badge ${readyCount > 0 ? 'connected' : 'disconnected'}`}>+ {readyCount > 0 ? t('common.connected') : t('common.disconnected')}</span>}/>