diff --git a/public/assets/pages/executions.js b/public/assets/pages/executions.js index 3ad229e..3a6f664 100644 --- a/public/assets/pages/executions.js +++ b/public/assets/pages/executions.js @@ -71,10 +71,13 @@ /* ------------------------------------------------------------------ Loading ------------------------------------------------------------------ */ - async function loadView(view, append) { + // keepLoaded: a live refresh fetches as many rows as are already shown, so + // rows brought in with Load More don't vanish when an event arrives (#17). + async function loadView(view, append, keepLoaded) { const st = state[view]; const offset = append ? st.offset : 0; - const params = new URLSearchParams({ limit: String(LIMIT), offset: String(offset) }); + const limit = keepLoaded ? Math.min(Math.max(LIMIT, st.rows.length), 1000) : LIMIT; + const params = new URLSearchParams({ limit: String(limit), offset: String(offset) }); if (view === 'manual') params.set('hide_internal', 'true'); if (view === 'automated') params.set('only_internal', 'true'); // server-side (#4) const term = searchTerm(); @@ -102,8 +105,12 @@ await loadView(state.view, false); render(); } - // Live events trigger this; coalesce bursts into at most one reload per 2 s (#10). - const reloadCurrent = Pulse.util.throttle(reloadNow, 2000); + // Live events trigger this; coalesce bursts into at most one reload per 2 s (#10), + // keeping however many rows are loaded (#17). + const reloadCurrent = Pulse.util.throttle(async () => { + await loadView(state.view, false, true); + render(); + }, 2000); // Typing in the search box: search on the server once typing pauses (#16). let searchTimer = null; diff --git a/tests/ui/quick-command.ui.js b/tests/ui/quick-command.ui.js index 4d134ce..88174cd 100644 --- a/tests/ui/quick-command.ui.js +++ b/tests/ui/quick-command.ui.js @@ -108,3 +108,24 @@ test('Quick Command remembers the mode and workers after a reload (#31)', async await expect(page.locator('#qc-mode-single')).toBeChecked(); await expect(page.locator('#qc-worker option:checked')).toContainText('node-03'); }); + +test('a live update keeps the rows brought in with Load More (#17)', async ({ page, request }) => { + const workers = await (await request.get('/api/workers')).json(); + const id = workers.find(w => w.name === 'node-01').id; + const send = () => request.post(`/api/workers/${id}/command`, { data: { command: 'true' } }); + for (let i = 0; i < 60; i++) await send(); + + await page.goto('/executions'); + const rows = page.locator('#ex-list-manual .ex-row'); + await expect(rows).toHaveCount(50); + await page.getByRole('button', { name: 'Load More Executions' }).click(); + await expect.poll(() => rows.count()).toBeGreaterThan(50); + const shown = await rows.count(); + + // A live event: the list refreshes with the new run on top, and still shows + // as many rows as before rather than dropping back to the first 50. + const marker = `live-${Date.now().toString(36)}`; + await request.post(`/api/workers/${id}/command`, { data: { command: `echo ${marker}` } }); + await expect(rows.first()).toContainText(marker, { timeout: 10_000 }); + await expect(rows).toHaveCount(shown); +});