Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): keep the Logs search box mounted while a page loads
Yudhi Armyndharisb339ce534eab
diff --git a/dashboard/src/pages/Logs.test.ts b/dashboard/src/pages/Logs.test.tsindex eeec8aa2c..c8ae59e97 100644--- a/dashboard/src/pages/Logs.test.ts+++ b/dashboard/src/pages/Logs.test.ts@@ -61,6 +61,10 @@ let exportTotal: number | null = null;let exportThrottledFrom: number | null = null;// When set, the export walks a 300-row table that gains a newest row after its first page is read.let exportGrowsMidWalk = false;+// When set, the on-screen list reports this many rows in total, so the page has a pager.+let listTotal: number | null = null;+// When set, a request for the first on-screen page waits for it before answering.+let firstPageGate: Promise<void> | null = null;/** Row `i` of a table walked newest first; every row has its own id, as the gateway's rows do. */function exportRow(i: number): AuditLog {@@ -88,7 +92,8 @@ function installFetchStub(): void {const shifted = [exportRow(-1), ...[...Array(300).keys()].map(exportRow)];return Promise.resolve(jsonResponse({ data: shifted.slice(offset), total: 301 }));}- return Promise.resolve(jsonResponse({ data: LOGS, total: LOGS.length }));+ const reply = jsonResponse({ data: LOGS, total: listTotal ?? LOGS.length });+ return firstPageGate && offset === 0 ? firstPageGate.then(() => reply) : Promise.resolve(reply);}) as typeof fetch;}@@ -128,8 +133,8 @@ before(async () => {afterEach(() => rtl.cleanup());-function renderLogs(): HTMLElement {- const client = new QueryClient({ defaultOptions: { queries: { retry: false } } });+function renderLogs(gcTime?: number): HTMLElement {+ const client = new QueryClient({ defaultOptions: { queries: { retry: false, gcTime } } });return rtl.render(createElement(QueryClientProvider, { client }, createElement(ToastProvider, null, createElement(Logs))),).container;@@ -269,3 +274,29 @@ test('the table grid declares one column track per rendered cell', async () => {assert.equal(template.split(/\s+/).length, row.children.length, template);}});++test('typing a search on a later page keeps the search box mounted while page one loads', async () => {+ const { screen, fireEvent, waitFor } = rtl;+ listTotal = 60;+ let release!: () => void;+ try {+ // A zero gcTime drops page one from the cache as soon as page two replaces it, as the default+ // five minutes does for an operator who stays on a later page.+ renderLogs(0);+ await screen.findByText('infra.restart');+ fireEvent.click(screen.getByRole('button', { name: '2' }));+ await waitFor(() => assert.equal(screen.getByRole('button', { name: '2' }).className, 'active'));+ await screen.findByText('infra.restart');+ await new Promise(resolve => setTimeout(resolve, 20));++ firstPageGate = new Promise(resolve => (release = resolve));+ const search = screen.getByPlaceholderText('Search logs...');+ fireEvent.change(search, { target: { value: 'sess' } });+ assert.ok(search.isConnected, 'the search box was replaced by the page spinner mid-typing');+ release();+ await screen.findByText('session.stop');+ } finally {+ listTotal = null;+ firstPageGate = null;+ }+});diff --git a/dashboard/src/pages/Logs.tsx b/dashboard/src/pages/Logs.tsxindex c8eded9bf..ea8aaedb1 100644--- a/dashboard/src/pages/Logs.tsx+++ b/dashboard/src/pages/Logs.tsx@@ -127,17 +127,6 @@ export function Logs() {}};- if (loading && logs.length === 0) {- return (- <div- className="logs-page"- style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', minHeight: '400px' }}- >- <Loader2 className="animate-spin" size={32} />- </div>- );- }-return (<div className="logs-page"><PageHeader@@ -201,7 +190,13 @@ export function Logs() {<span>{t('logs.columns.ip')}</span><span>{t('logs.columns.severity')}</span></div>- {filteredLogs.length === 0 ? (+ {/* The spinner stays inside the table: a search or severity change switches to a page that+ may not be cached, and replacing the whole page would unmount the search box mid-typing. */}+ {loading && logs.length === 0 ? (+ <div className="empty-table-state">+ <Loader2 className="animate-spin" size={32} />+ </div>+ ) : filteredLogs.length === 0 ? (<div className="empty-table-state"><FileText size={48} strokeWidth={1} />{hasSeverityFilter || hasSearch ? (