From 6634daddb5fc6a89fb4cf4866ea6a48ad243ef1e Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Tue, 20 Oct 2026 21:02:14 +0200 Subject: [PATCH 01/28] test: scrolling within 20 rows of the end loads the 100 events before the oldest held and appends them without moving the rows in view (#767) --- .../{events.spec.ts => activity.spec.ts} | 106 +++++++++++++++++- .../{waiting.spec.ts => queue.spec.ts} | 17 +-- 2 files changed, 110 insertions(+), 13 deletions(-) rename e2e/console/{events.spec.ts => activity.spec.ts} (78%) rename e2e/console/{waiting.spec.ts => queue.spec.ts} (93%) diff --git a/e2e/console/events.spec.ts b/e2e/console/activity.spec.ts similarity index 78% rename from e2e/console/events.spec.ts rename to e2e/console/activity.spec.ts index 752402d19..299320a3a 100644 --- a/e2e/console/events.spec.ts +++ b/e2e/console/activity.spec.ts @@ -1,4 +1,4 @@ -import type { Locator, Page } from "@playwright/test"; +import type { Locator, Page, Route } from "@playwright/test"; import { disposeFleet, @@ -106,6 +106,75 @@ async function openEvent(page: Page, id: string): Promise { await link.click(); } +interface Stubbed { + readonly id: string; + readonly seq: number; + readonly timestamp: number; + readonly event: string; + readonly payload: Record; +} + +function stubbed(n: number, now: number): Stubbed { + return { + event: "lease.renewed", + id: `evt_${String(n).padStart(4, "0")}`, + payload: {}, + seq: 1_000_000 - n, + timestamp: now - n * 60_000, + }; +} + +function stubbedRange(from: number, to: number): Stubbed[] { + const now = Date.now(); + return Array.from({ length: to - from + 1 }, (_, index) => stubbed(to - index, now)); +} + +interface StubbedAnswer { + readonly status?: number; + readonly events?: readonly Stubbed[]; +} + +/** + * why: Answers every `GET /v1/events` with what `answer` returns for its query, and records each + * query, so a test sees which pages the console asked for. + */ +async function stubEvents( + page: Page, + answer: (query: URLSearchParams) => StubbedAnswer, +): Promise { + const queries: string[] = []; + await page.route( + (url) => url.pathname === "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/v1/events", + async (route: Route) => { + const { search } = new URL(route.request().url()); + queries.push(search); + const { events = [], status = 200 } = answer(new URLSearchParams(search)); + if (status === 200) await route.fulfill({ json: { events } }); + else + await route.fulfill({ json: { error: { code: "STUBBED", message: "stubbed" } }, status }); + }, + ); + return queries; +} + +// why: the feed draws only the rows in view and prints no count, so its scroll height, one row +// tall per event, is the only measure of how many events it holds. +const ROW_PX = 60; + +async function eventsHeld(page: Page): Promise { + return Math.round((await feed(page).evaluate((box) => box.scrollHeight)) / ROW_PX); +} + +async function rowOffset(page: Page, id: string): Promise { + return feed(page).evaluate((box, wanted) => { + const link = box.querySelector(`a[href^="/activity/${wanted}"]`); + if (link === null) throw new Error(`${wanted} is not drawn`); + return Math.round( + link.closest("li")!.getBoundingClientRect().top - box.getBoundingClientRect().top, + ); + }, id); +} + async function hasHorizontalScroll(page: Page): Promise { await settled(page); return page.evaluate( @@ -113,7 +182,7 @@ async function hasHorizontalScroll(page: Page): Promise { ); } -test.describe("the events page", () => { +test.describe("the Activity page", () => { test("a lease taken with the CLI appears in the feed within a second, and its page opens from it", async ({ page, }) => { @@ -242,6 +311,39 @@ test.describe("the events page", () => { } }); + test("scrolling within 20 rows of the end loads the 100 events before the oldest held and appends them without moving the rows in view", async ({ + page, + }) => { + const host = await startDaemon("worker", { driverScript: { ios: IOS } }); + try { + const queries = await stubEvents(page, (query) => { + const before = query.get("before"); + if (before === null) return { events: stubbedRange(1, 30) }; + if (before === "evt_0030") return { events: stubbedRange(31, 130) }; + if (before === "evt_0130") return { events: stubbedRange(131, 230) }; + return {}; + }); + await openEvents(page, host); + + await expect.poll(() => eventsHeld(page)).toBe(130); + expect(queries).toEqual(["?since=1h", "?before=evt_0030&limit=100"]); + + await feed(page).evaluate((box, top) => box.scrollTo({ top }), 100 * ROW_PX); + await expect.poll(() => rowOffset(page, "evt_0101")).toBe(0); + await expect.poll(() => eventsHeld(page)).toBe(230); + + expect(queries).toEqual([ + "?since=1h", + "?before=evt_0030&limit=100", + "?before=evt_0130&limit=100", + ]); + expect(await rowOffset(page, "evt_0101")).toBe(0); + expect(await feed(page).evaluate((box) => box.scrollTop)).toBe(100 * ROW_PX); + } finally { + await host.dispose(); + } + }); + test("on a gateway, a worker's event shows that worker's label", async ({ page }) => { const fleet = await startFleet([{ driverScript: { ios: IOS }, label: "worker-a" }]); try { diff --git a/e2e/console/waiting.spec.ts b/e2e/console/queue.spec.ts similarity index 93% rename from e2e/console/waiting.spec.ts rename to e2e/console/queue.spec.ts index 7a91b9af5..3a06c80f2 100644 --- a/e2e/console/waiting.spec.ts +++ b/e2e/console/queue.spec.ts @@ -3,7 +3,6 @@ import type { Locator, Page } from "@playwright/test"; import { waitFor } from "../helpers/wait.js"; import { expect, type RunningDaemon, settled, signIn, startDaemon, test } from "./fixtures.js"; -/** What `GET /v1/lease-requests` answers, as far as these tests read. */ interface WaitingRequest { readonly id: string; readonly requesterId: string; @@ -12,18 +11,15 @@ interface WaitingRequest { } const IOS = { availableOsVersions: ["18.4"], knownModels: ["iPhone 16"] }; -/** One iOS device and no more, so a second request waits. */ const ONE_DEVICE = { limits: { ios: { maxDevices: 1, maxRunning: 1 }, maxRunning: 1 } }; const LEASE = ["lease", "--platform", "ios", "--device", "iPhone 16", "--os", "18.4"] as const; -/** Leases the host's one device for `agent`, and answers the lease id. */ async function holdTheDevice(daemon: RunningDaemon, agent: string): Promise { const granted = await daemon.cli([...LEASE, "--agent-id", agent, "--detach"]); expect(granted.code, granted.stderr).toBe(0); return (granted.json as { lease: { id: string } }).lease.id; } -/** The daemon's own `GET /v1/lease-requests`, asked as an operator. */ async function waiting(daemon: RunningDaemon): Promise { const response = await fetch(new URL("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/v1/lease-requests", daemon.url), { headers: { Authorization: `Bearer ${daemon.tokens.operator}` }, @@ -33,7 +29,7 @@ async function waiting(daemon: RunningDaemon): Promise { return page.evaluate( () => document.documentElement.scrollWidth > document.documentElement.clientWidth, ); } -test.describe("the Waiting page", () => { +test.describe("the Queue page", () => { test("a request waiting for a device appears in the list with its place, device and stage, and opens with its time waited", async ({ page, }) => { @@ -103,7 +98,7 @@ test.describe("the Waiting page", () => { await expect(inspector).toContainText("wants iOS iPhone 16, runtime 18.4, mode slim"); await expect(inspector).toContainText("2 of 2"); await expect(inspector.getByRole("navigation", { name: "Breadcrumb" })).toBeVisible(); - // The time waited counts on in the browser, with no reload. + // why: The time waited counts on in the browser, with no reload. const waited = inspector.locator(".waiting-card-value").first(); const before = await waited.textContent(); await expect(waited).not.toHaveText(before ?? "", { timeout: 3_000 }); @@ -129,7 +124,7 @@ test.describe("the Waiting page", () => { }, driverScript: { ios: IOS }, }); - // A local agent on the worker takes the fleet's one device, and a second one waits in the + // why: A local agent on the worker takes the fleet's one device, and a second one waits in the // worker's own queue. A further lease through the gateway then waits in the gateway's. await holdTheDevice(worker, "local-a"); worker.cliBackground([...LEASE, "--agent-id", "local-b"]); @@ -234,7 +229,7 @@ test.describe("the Waiting page", () => { }); test("the Waiting page is usable with the keyboard alone", async ({ browserName, page }) => { - // Safari moves focus to links with Option-Tab; plain Tab reaches only form controls there. + // why: Safari moves focus to links with Option-Tab; plain Tab reaches only form controls there. const tab = browserName === "webkit" ? "Alt+Tab" : "Tab"; const host = await startDaemon("worker", { config: ONE_DEVICE, driverScript: { ios: IOS } }); try { @@ -259,7 +254,7 @@ test.describe("the Waiting page", () => { await expect(page.getByRole("heading", { level: 2, name: "agent-b" })).toBeVisible(); expect(new URL(page.url()).pathname).toMatch(/^\/queue\/.+/); - // The request's worker opens that worker's page. + // why: The request's worker opens that worker's page. await follow(inspectorOf(page, "agent-b").getByRole("link").last()); expect(new URL(page.url()).pathname).toMatch(/^\/fleet\/.+/); } finally { From e2a1eeff089c23959f2b3b652a0471e71ec3ba23 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Tue, 20 Oct 2026 21:05:07 +0200 Subject: [PATCH 02/28] feat(console): Activity loads older events as the list nears its end (#767) --- e2e/console/activity.spec.ts | 17 +++++++++-------- ui/src/data/event-feed.ts | 26 ++++++++++++++++++++++++++ ui/src/ds/feed.tsx | 27 ++++++++++++++++++++++++++- ui/src/model/events.ts | 3 +++ ui/src/screens/events/events.test.tsx | 1 + ui/src/screens/events/index.tsx | 1 + ui/src/state/events.ts | 15 ++++++++++++--- 7 files changed, 78 insertions(+), 12 deletions(-) diff --git a/e2e/console/activity.spec.ts b/e2e/console/activity.spec.ts index 299320a3a..dc92f125a 100644 --- a/e2e/console/activity.spec.ts +++ b/e2e/console/activity.spec.ts @@ -157,6 +157,10 @@ async function stubEvents( return queries; } +function older(queries: readonly string[]): string[] { + return queries.filter((query) => !query.startsWith("?since=")); +} + // why: the feed draws only the rows in view and prints no count, so its scroll height, one row // tall per event, is the only measure of how many events it holds. const ROW_PX = 60; @@ -326,18 +330,15 @@ test.describe("the Activity page", () => { await openEvents(page, host); await expect.poll(() => eventsHeld(page)).toBe(130); - expect(queries).toEqual(["?since=1h", "?before=evt_0030&limit=100"]); + expect(older(queries)).toEqual(["?before=evt_0030&limit=100"]); await feed(page).evaluate((box, top) => box.scrollTo({ top }), 100 * ROW_PX); - await expect.poll(() => rowOffset(page, "evt_0101")).toBe(0); + await expect.poll(() => rowOffset(page, "evt_0101").catch(() => undefined)).toBeDefined(); + const inView = await rowOffset(page, "evt_0101"); await expect.poll(() => eventsHeld(page)).toBe(230); - expect(queries).toEqual([ - "?since=1h", - "?before=evt_0030&limit=100", - "?before=evt_0130&limit=100", - ]); - expect(await rowOffset(page, "evt_0101")).toBe(0); + expect(older(queries)).toEqual(["?before=evt_0030&limit=100", "?before=evt_0130&limit=100"]); + expect(await rowOffset(page, "evt_0101")).toBe(inView); expect(await feed(page).evaluate((box) => box.scrollTop)).toBe(100 * ROW_PX); } finally { await host.dispose(); diff --git a/ui/src/data/event-feed.ts b/ui/src/data/event-feed.ts index 634010161..c666e196c 100644 --- a/ui/src/data/event-feed.ts +++ b/ui/src/data/event-feed.ts @@ -9,6 +9,7 @@ import { import { type ConsoleEvent, mergeEvents, + OLDER_PAGE as PAGE, readEvent, readReplay, RECENT, @@ -28,6 +29,7 @@ export class EventFeed { #needRecent = true; #gapFrom: number | undefined; #loading = false; + #loadingOlder = false; // why: counts the stream's opens, so a load knows whether one happened while it was out. #opens = 0; #retryTimer: unknown; @@ -115,6 +117,30 @@ export class EventFeed { ); } + // why: one page at a time; a second signal before the answer is dropped. + readonly loadOlder = (): void => { + if (!this.#active || this.#loadingOlder) return; + const oldest = this.#events.at(-1); + const query = + oldest === undefined + ? `limit=${PAGE}` + : `before=${encodeURIComponent(oldest.id)}&limit=${PAGE}`; + this.#loadingOlder = true; + this.#get(`/v1/events?${query}`) + .then(readReplay) + .then( + (events) => { + this.#loadingOlder = false; + if (!this.#active) return; + this.#events = mergeEvents(this.#events, events); + this.#publish({ ...this.#state, data: this.#events }); + }, + () => { + this.#loadingOlder = false; + }, + ); + }; + #retryLater(): void { const delay = RETRY_BACKOFF_MS[this.#retryAttempt] ?? RETRY_INTERVAL_MS; this.#retryAttempt += 1; diff --git a/ui/src/ds/feed.tsx b/ui/src/ds/feed.tsx index 402390d58..ceda6a7a6 100644 --- a/ui/src/ds/feed.tsx +++ b/ui/src/ds/feed.tsx @@ -10,6 +10,9 @@ const BOX_HEIGHT_PX = 640; // why: rows drawn past each edge of the box, so a short scroll shows rows already there. const OVERSCAN = 5; +// why: how close to the last row the last drawn row must be before the list asks for more. +const NEAR_END_ROWS = 20; + // why: only the rows in view, and a few past each edge, are in the page; the space of the rest is // padding, so the scroll bar is as long as every row. New rows come in at the top: while the box // is at the top they push the rows down, so the newest is always in view; once the reader scrolls @@ -23,9 +26,20 @@ export function Feed(props: { readonly keyAt: (index: number) => string; readonly newText: (count: number) => string; readonly startAt?: number; + readonly onNearEnd?: () => void; readonly renderRow: (index: number) => ReactNode; }) { - const { count, keyAt, label, listLabel, newText, renderRow, rowHeight, startAt = 0 } = props; + const { + count, + keyAt, + label, + listLabel, + newText, + onNearEnd, + renderRow, + rowHeight, + startAt = 0, + } = props; const box = useRef(null); const [atTop, setAtTop] = useState(true); const unseen = useUnseen(count, keyAt, atTop); @@ -44,6 +58,7 @@ export function Feed(props: { box.current?.focus(); }; const items = virtualizer.getVirtualItems(); + useNearEnd(items.at(-1)?.index, count, onNearEnd); const before = items[0]?.start ?? 0; const after = Math.max(0, virtualizer.getTotalSize() - (items.at(-1)?.end ?? 0)); return ( @@ -75,6 +90,16 @@ export function Feed(props: { ); } +// why: the callback is read through a ref, so a new function on each render does not ask again; +// only a change in the last drawn row or in the count does. +function useNearEnd(last: number | undefined, count: number, onNearEnd: (() => void) | undefined) { + const callback = useRef(onNearEnd); + callback.current = onNearEnd; + useEffect(() => { + if (last !== undefined && last >= count - NEAR_END_ROWS) callback.current?.(); + }, [last, count]); +} + function useUnseen(count: number, keyAt: (index: number) => string, atTop: boolean): number { const newest = count === 0 ? undefined : keyAt(0); // why: the newest row the reader saw at the top of the box: every row above it is new to them. diff --git a/ui/src/model/events.ts b/ui/src/model/events.ts index 1376c0adf..d7191c28b 100644 --- a/ui/src/model/events.ts +++ b/ui/src/model/events.ts @@ -9,6 +9,9 @@ export interface ConsoleEvent { export const MAX_EVENTS = 10_000; +// why: the size of one page of older events the console asks for. +export const OLDER_PAGE = 100; + // why: the same window as `simlock events --since 1h`, so the two show the same events. export const RECENT = "1h"; diff --git a/ui/src/screens/events/events.test.tsx b/ui/src/screens/events/events.test.tsx index 3bad6e101..a18d2fa3d 100644 --- a/ui/src/screens/events/events.test.tsx +++ b/ui/src/screens/events/events.test.tsx @@ -48,6 +48,7 @@ function page(over: Partial = {}): EventsPage { chosen: { detail: DETAIL, kind: "event" }, chosenIndex: 0, held: 1, + loadOlder: () => {}, named: false, rows: [row(1)], subject: "all", diff --git a/ui/src/screens/events/index.tsx b/ui/src/screens/events/index.tsx index a4a5edb22..8abc1fc37 100644 --- a/ui/src/screens/events/index.tsx +++ b/ui/src/screens/events/index.tsx @@ -104,6 +104,7 @@ function EventList(props: { keyAt={(index) => rows[index]?.id ?? String(index)} newText={(count) => (count === 1 ? "1 new event" : `${count} new events`)} startAt={page.chosenIndex} + onNearEnd={page.loadOlder} renderRow={(index) => { const row = rows[index]; return row === undefined ? null : ; diff --git a/ui/src/state/events.ts b/ui/src/state/events.ts index 107cf893f..46aaf06d3 100644 --- a/ui/src/state/events.ts +++ b/ui/src/state/events.ts @@ -32,13 +32,20 @@ export { SUBJECT_CHOICES }; // why: each screen that reads events holds its own feed, filled from the last hour and then the // stream while it is on screen, so a screen opened later still starts from a full hour. -export function useRecentEvents(): ResourceState { +export function useEventFeed(): { + readonly feed: EventFeed; + readonly state: ResourceState; +} { const api = useApi(); const [feed] = useState(() => new EventFeed((path) => api.getJson(path), browserClock)); useLiveEvents(feed.streamEvent); useStreamOpened(feed.streamOpened); useEffect(() => feed.start(), [feed]); - return useSyncExternalStore(feed.subscribe, feed.snapshot); + return { feed, state: useSyncExternalStore(feed.subscribe, feed.snapshot) }; +} + +export function useRecentEvents(): ResourceState { + return useEventFeed().state; } const NO_WORKERS: readonly WorkerView[] = []; @@ -57,10 +64,11 @@ export interface EventsPage { readonly named: boolean; // why: the row the chosen event sits at, so the box opens with it in view. readonly chosenIndex: number; + readonly loadOlder: () => void; } export function useEvents(): LoadView { - const feed = useRecentEvents(); + const { feed: source, state: feed } = useEventFeed(); const events = feed.data; // why: the places an event links to are read for the links only; a route that is slow, refused // or not served here costs the feed nothing, only the link. @@ -84,6 +92,7 @@ export function useEvents(): LoadView { chart, chosen, held: held.length, + loadOlder: source.loadOlder, chosenIndex: Math.max( 0, rows.findIndex((row) => row.id === chosenId), From addee7d71fa09985209cee25dd4584e91dd204ba Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Tue, 20 Oct 2026 21:07:59 +0200 Subject: [PATCH 03/28] test: the chips and the search filter the Activity list and are kept in the address (#767) --- e2e/console/activity.spec.ts | 16 +++++++++++++++- ui/src/model/event-list.test.ts | 23 +++++++++++++++++++++++ ui/src/model/event-list.ts | 1 + 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/e2e/console/activity.spec.ts b/e2e/console/activity.spec.ts index dc92f125a..e84c2b535 100644 --- a/e2e/console/activity.spec.ts +++ b/e2e/console/activity.spec.ts @@ -272,7 +272,9 @@ test.describe("the Activity page", () => { } }); - test("the filter shows only one subject's events and is kept in the URL", async ({ page }) => { + test("the filter and the search show only the events they match and are kept in the URL", async ({ + page, + }) => { const host = await startDaemon("worker", { driverScript: { ios: IOS } }); try { await lease(host, "console-e2e-filter"); @@ -286,6 +288,18 @@ test.describe("the Activity page", () => { expect(names.every((name) => name.startsWith("lease."))).toBe(true); await page.reload(); await expect(page.getByRole("radio", { name: "Leases" })).toBeChecked(); + + await page.getByRole("searchbox", { name: "Search events" }).fill("GRANTED"); + + await expect(page).toHaveURL(/\?subject=lease&q=GRANTED$/); + await expect(rows(page)).not.toHaveCount(0); + expect( + (await rows(page).locator("time + span").allTextContents()).every( + (name) => name === "lease.granted", + ), + ).toBe(true); + await page.reload(); + await expect(page.getByRole("searchbox", { name: "Search events" })).toHaveValue("GRANTED"); } finally { await host.dispose(); } diff --git a/ui/src/model/event-list.test.ts b/ui/src/model/event-list.test.ts index c8a3ea22c..c9f252034 100644 --- a/ui/src/model/event-list.test.ts +++ b/ui/src/model/event-list.test.ts @@ -120,6 +120,29 @@ describe("a list row", () => { }); }); +describe("a search of the list", () => { + const events = [ + event("lease.granted", { requester: "claude-1", token: "Marker-Value" }, 1), + event("worker.connected", { workerId: "wrk_1" }, 2), + event("device.ready", { deviceId: "dev_1" }, 3), + ]; + const found = (query: string) => + eventRows(events, [worker("wrk_1", "Mac Studio")], "all", query).map((row) => row.name); + + it("matches part of the event name or the summary line, ignoring case, and no other payload value", () => { + expect(found("")).toEqual(["lease.granted", "worker.connected", "device.ready"]); + expect(found("GRANT")).toEqual(["lease.granted"]); + expect(found("ice.rea")).toEqual(["device.ready"]); + expect(found("mac stu")).toEqual(["worker.connected"]); + expect(found("CLAUDE")).toEqual(["lease.granted"]); + expect(found("marker-value")).toEqual([]); + expect(found("dev_1")).toEqual([]); + expect(eventRows(events, [], "lease", "grant")[0]?.to).toBe( + "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/activity/evt_1?subject=lease&q=grant", + ); + }); +}); + describe("an event's day", () => { const noon = new Date(2026, 9, 2, 12, 0, 0).getTime(); diff --git a/ui/src/model/event-list.ts b/ui/src/model/event-list.ts index 357744d78..126d723b8 100644 --- a/ui/src/model/event-list.ts +++ b/ui/src/model/event-list.ts @@ -84,6 +84,7 @@ export function eventRows( events: readonly ConsoleEvent[], workers: readonly WorkerView[], subject: SubjectFilter, + _search = "", ): readonly EventRow[] { const query = writeSubject("", subject); return shownEvents(events, subject).map((event) => { From 25f1e62b1d001f03f35d876b4a0e51e3d3b472db Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Tue, 20 Oct 2026 21:13:22 +0200 Subject: [PATCH 04/28] feat(console): Activity is a page with a toolbar of chips and search, and an event opens in a drawer (#767) --- e2e/console/activity.spec.ts | 11 +- ui/src/app/routes.ts | 14 +- ui/src/ds/focus-after-drawer.ts | 16 ++ ui/src/ds/index.ts | 1 + ui/src/model/event-list.test.ts | 23 +- ui/src/model/event-list.ts | 33 +-- .../events.css => activity/activity.css} | 22 ++ .../activity.test.tsx} | 43 ++-- ui/src/screens/activity/index.tsx | 205 ++++++++++++++++++ ui/src/screens/events/index.tsx | 193 ----------------- ui/src/screens/leases/index.tsx | 21 +- ui/src/screens/{waiting => queue}/index.tsx | 4 +- .../{waiting/waiting.css => queue/queue.css} | 0 .../waiting.test.tsx => queue/queue.test.tsx} | 0 ui/src/state/drawer.ts | 27 +++ ui/src/state/events.ts | 25 ++- ui/src/state/leases.ts | 28 +-- 17 files changed, 371 insertions(+), 295 deletions(-) create mode 100644 ui/src/ds/focus-after-drawer.ts rename ui/src/screens/{events/events.css => activity/activity.css} (50%) rename ui/src/screens/{events/events.test.tsx => activity/activity.test.tsx} (86%) create mode 100644 ui/src/screens/activity/index.tsx delete mode 100644 ui/src/screens/events/index.tsx rename ui/src/screens/{waiting => queue}/index.tsx (98%) rename ui/src/screens/{waiting/waiting.css => queue/queue.css} (100%) rename ui/src/screens/{waiting/waiting.test.tsx => queue/queue.test.tsx} (100%) create mode 100644 ui/src/state/drawer.ts diff --git a/e2e/console/activity.spec.ts b/e2e/console/activity.spec.ts index e84c2b535..58796af76 100644 --- a/e2e/console/activity.spec.ts +++ b/e2e/console/activity.spec.ts @@ -50,7 +50,10 @@ async function cliEvents(daemon: RunningDaemon): Promise { async function openEvents(page: Page, daemon: RunningDaemon, path = "/activity"): Promise { await page.goto(new URL(path, daemon.url).href); await signIn(page, daemon.tokens.operator); - await expect(page.getByRole("heading", { level: 1, name: "Activity" })).toBeVisible(); + // why: a drawer over the page hides the page's heading from the accessibility tree. + if (path === "/activity") { + await expect(page.getByRole("heading", { level: 1, name: "Activity" })).toBeVisible(); + } else await expect(page.getByRole("dialog")).toBeVisible(); } function feed(page: Page): Locator { @@ -251,7 +254,7 @@ test.describe("the Activity page", () => { await expect(page).toHaveURL(new RegExp(`/activity/${(started as Envelope).id}$`)); await expect(title(page)).toHaveText("daemon.started"); - await expect(page.getByRole("heading", { level: 2, name: "Payload" })).toBeVisible(); + await expect(page.getByRole("heading", { level: 3, name: "Payload" })).toBeVisible(); await page.reload(); await expect(title(page)).toHaveText("daemon.started"); } finally { @@ -396,7 +399,9 @@ test.describe("the Activity page", () => { for (const event of events) { await openEvent(page, event.id); await expect(title(page)).toHaveText(event.event); - seen.push(await page.locator("#main").innerText()); + seen.push(await page.getByRole("dialog").innerText()); + await page.keyboard.press("Escape"); + await expect(page.getByRole("dialog")).toHaveCount(0); } expect(seen.join("\n"), name).not.toContain(joinToken); expect(await page.content(), name).not.toContain(joinToken); diff --git a/ui/src/app/routes.ts b/ui/src/app/routes.ts index a890a08a4..5b2d47cfa 100644 --- a/ui/src/app/routes.ts +++ b/ui/src/app/routes.ts @@ -2,11 +2,11 @@ import type { ComponentType } from "react"; import type { IconName } from "../ds"; import { AttentionScreen } from "../screens/attention"; -import { EventsScreen } from "../screens/events"; +import { ActivityScreen } from "../screens/activity"; import { LeasesScreen } from "../screens/leases"; import { OverviewScreen } from "../screens/overview"; import { UsageScreen } from "../screens/usage"; -import { WaitingScreen } from "../screens/waiting"; +import { QueueScreen } from "../screens/queue"; import { FleetScreen } from "../screens/fleet"; export type NavGroup = "Operate" | "Observe"; @@ -24,8 +24,14 @@ export const ROUTES: readonly Route[] = [ { Screen: AttentionScreen, icon: "attention", label: "Attention", path: "/attention" }, { Screen: FleetScreen, group: "Operate", icon: "workers", label: "Fleet", path: "/fleet" }, { Screen: LeasesScreen, group: "Operate", icon: "leases", label: "Leases", path: "/leases" }, - { Screen: WaitingScreen, group: "Operate", icon: "waiting", label: "Queue", path: "/queue" }, - { Screen: EventsScreen, group: "Observe", icon: "events", label: "Activity", path: "/activity" }, + { Screen: QueueScreen, group: "Operate", icon: "waiting", label: "Queue", path: "/queue" }, + { + Screen: ActivityScreen, + group: "Observe", + icon: "events", + label: "Activity", + path: "/activity", + }, { Screen: UsageScreen, group: "Observe", icon: "usage", label: "Usage", path: "/usage" }, ]; diff --git a/ui/src/ds/focus-after-drawer.ts b/ui/src/ds/focus-after-drawer.ts new file mode 100644 index 000000000..26fab80cc --- /dev/null +++ b/ui/src/ds/focus-after-drawer.ts @@ -0,0 +1,16 @@ +// why: focus goes back to the row that opened the drawer, or to the page's heading when that row is +// gone or the drawer was loaded directly. A row's link is found by its path alone, trailing slash +// and query set aside, so `evt_1` does not match `evt_10`. +export function focusAfterClosing(options: { + readonly fromList: boolean; + readonly path: string; + readonly links: string; +}): HTMLElement | null { + const { fromList, links, path } = options; + const row = fromList + ? [...document.querySelectorAll(links)].find( + (link) => link.getAttribute("href")?.split("?", 1)[0]?.replace(/\/$/, "") === path, + ) + : undefined; + return row ?? document.querySelector("main h1"); +} diff --git a/ui/src/ds/index.ts b/ui/src/ds/index.ts index 6a6de3431..fcfdeb65e 100644 --- a/ui/src/ds/index.ts +++ b/ui/src/ds/index.ts @@ -21,3 +21,4 @@ export { StatRow, StatTile } from "./stat"; export { Status, StatusDot } from "./status"; export { type Column, DataTable } from "./table"; export { Toolbar } from "./toolbar"; +export { focusAfterClosing } from "./focus-after-drawer"; diff --git a/ui/src/model/event-list.test.ts b/ui/src/model/event-list.test.ts index c9f252034..13e280244 100644 --- a/ui/src/model/event-list.test.ts +++ b/ui/src/model/event-list.test.ts @@ -286,32 +286,19 @@ describe("the events chart", () => { describe("the event chosen", () => { const events = [event("lease.granted", {}, 2), event("device.ready", {}, 1)]; - const rows = eventRows(events, [], "all"); - const choose = (id: string | undefined, shown = rows) => - chosenEvent(events, shown, id, NO_PLACES, T0); + const choose = (id: string | undefined) => chosenEvent(events, id, NO_PLACES, T0); - it("is the one the URL names", () => { + it("is the one the URL names, even one a filter or a search hides", () => { const chosen = choose("evt_1"); expect(chosen.kind === "event" && chosen.detail.name).toBe("device.ready"); }); - it("is the first row when the URL names none", () => { - const chosen = choose(undefined); - - expect(chosen.kind === "event" && chosen.detail.id).toBe("evt_2"); - }); - - it("opens an event the filter hides", () => { - const filtered = eventRows(events, [], "lease"); - - const chosen = choose("evt_1", filtered); - - expect(chosen.kind === "event" && chosen.detail.id).toBe("evt_1"); + it("is none when the URL names none, so the drawer stays shut", () => { + expect(choose(undefined)).toEqual({ kind: "none" }); }); - it("is missing for an id the feed does not hold, and none for an empty feed", () => { + it("is missing for an id the feed does not hold", () => { expect(choose("evt_gone")).toEqual({ id: "evt_gone", kind: "missing" }); - expect(chosenEvent([], [], undefined, NO_PLACES, T0)).toEqual({ kind: "none" }); }); }); diff --git a/ui/src/model/event-list.ts b/ui/src/model/event-list.ts index 126d723b8..73713921a 100644 --- a/ui/src/model/event-list.ts +++ b/ui/src/model/event-list.ts @@ -11,7 +11,7 @@ import { } from "./events"; import { eventsPerMinute, extremes, type MinuteCount } from "./history"; import { type LeaseRecord, leasePath } from "./leases"; -import { formatCount } from "./paging"; +import { formatCount, writeQuery } from "./paging"; import { itemPath } from "./paths"; import type { Tone } from "./tones"; import type { WaitingRequest } from "./waiting"; @@ -79,15 +79,16 @@ export interface EventRow { readonly summary: string; } -// why: a row keeps the filter in its link, so choosing an event does not undo the filter. +// why: a row keeps the filter and the search in its link, so choosing an event does not undo them. export function eventRows( events: readonly ConsoleEvent[], workers: readonly WorkerView[], subject: SubjectFilter, - _search = "", + search = "", ): readonly EventRow[] { - const query = writeSubject("", subject); - return shownEvents(events, subject).map((event) => { + const query = writeQuery(writeSubject("", subject), search); + const wanted = search.toLowerCase(); + const rows = shownEvents(events, subject).map((event) => { const tone = eventTone(event.event); return { id: event.id, @@ -99,6 +100,14 @@ export function eventRows( ...(tone === undefined ? {} : { tone }), }; }); + // why: the match is over what a row shows, its name and its summary line, and over no other + // part of the payload. + return wanted === "" + ? rows + : rows.filter( + (row) => + row.name.toLowerCase().includes(wanted) || row.summary.toLowerCase().includes(wanted), + ); } export interface EventAction { @@ -197,19 +206,17 @@ export type Chosen = | { readonly kind: "missing"; readonly id: string } | { readonly kind: "event"; readonly detail: EventDetail }; -// why: with no id in the URL the first row shows, so a wide screen is never half empty; an id the -// feed does not hold (older than the hour, or not loaded yet) is said so, not guessed at. An id is -// looked up among every event held, so an event the filter hides still opens. +// why: the drawer opens only for an id in the URL; an id the console does not hold (older than +// what has loaded) is said so, not guessed at. An id is looked up among every event held, so an +// event the filter or the search hides still opens. export function chosenEvent( events: readonly ConsoleEvent[], - rows: readonly EventRow[], id: string | undefined, places: EventPlaces, now: number, ): Chosen { - const wanted = id ?? rows[0]?.id; - if (wanted === undefined) return { kind: "none" }; - const event = events.find((entry) => entry.id === wanted); - if (event === undefined) return { id: wanted, kind: "missing" }; + if (id === undefined) return { kind: "none" }; + const event = events.find((entry) => entry.id === id); + if (event === undefined) return { id, kind: "missing" }; return { detail: eventDetail(event, places, now), kind: "event" }; } diff --git a/ui/src/screens/events/events.css b/ui/src/screens/activity/activity.css similarity index 50% rename from ui/src/screens/events/events.css rename to ui/src/screens/activity/activity.css index eb717478f..1f55b2116 100644 --- a/ui/src/screens/events/events.css +++ b/ui/src/screens/activity/activity.css @@ -23,3 +23,25 @@ .event-error { color: var(--status-error); } + +.event-drawer-body { + display: flex; + flex-direction: column; + gap: var(--space-4); + padding: var(--space-4) var(--space-6); +} + +.event-line { + margin: 0; + color: var(--text-muted); +} + +.event-payload-title { + margin: 0; + color: var(--text-muted); + font-family: var(--font-mono); + font-size: var(--text-xs); + font-weight: 500; + letter-spacing: var(--label-tracking); + text-transform: uppercase; +} diff --git a/ui/src/screens/events/events.test.tsx b/ui/src/screens/activity/activity.test.tsx similarity index 86% rename from ui/src/screens/events/events.test.tsx rename to ui/src/screens/activity/activity.test.tsx index a18d2fa3d..70464a645 100644 --- a/ui/src/screens/events/events.test.tsx +++ b/ui/src/screens/activity/activity.test.tsx @@ -3,7 +3,7 @@ import { describe, expect, it } from "vitest"; import type { LoadView } from "../../ds"; import type { EventDetail, EventRow, EventsPage } from "../../state/events"; -import { EventsContent } from "."; +import { ActivityContent, DrawerBody } from "."; function text(html: string): string { return html @@ -49,15 +49,28 @@ function page(over: Partial = {}): EventsPage { chosenIndex: 0, held: 1, loadOlder: () => {}, - named: false, + query: "", rows: [row(1)], subject: "all", + urlId: "evt_1", ...over, }; } function render(view: LoadView): string { - return renderToStaticMarkup( {}} />); + return renderToStaticMarkup( + {}} + onSearch={() => {}} + onClose={() => {}} + finalFocus={() => null} + />, + ); +} + +function drawer(over: Partial = {}): string { + return renderToStaticMarkup(); } function ready(over: Partial = {}): string { @@ -145,41 +158,33 @@ describe("the events page", () => { it("shows a refusal above the events it keeps", () => { const html = render({ data: page(), kind: "ready", refusal: "Internal error" }); - expect(html).toMatch(/^'); expect(text(html)).toContain("lease.granted"); }); - - it("opens on the phone at the inspector only when the URL names an event", () => { - expect(ready({ named: true })).toContain("focus-detail"); - expect(ready({ named: false })).toContain("focus-list"); - }); }); describe("the events page's inspector", () => { - it("is titled with the event's name and says when and what", () => { - const html = ready(); + it("says when and what the event was", () => { + const html = drawer(); - expect(html).toMatch( - /

]*class="inspector-title mono"[^>]*>lease\.granted<\/span><\/h2>/, - ); expect(text(html)).toContain("11:30:00 today · claude-1 · mac-1"); }); it("shows the payload whole, keys as the daemon spelled them", () => { - const html = ready(); + const html = drawer(); expect(html).toContain('
'); expect(text(html)).toContain('leaseId lse_1 nested {"deep":true}'); }); it("says when there is no payload", () => { - expect(text(ready({ chosen: { detail: { ...DETAIL, pairs: [] }, kind: "event" } }))).toContain( + expect(text(drawer({ chosen: { detail: { ...DETAIL, pairs: [] }, kind: "event" } }))).toContain( "No payload.", ); }); it("links to what the event is about when the console has a page for it", () => { - const withAction = ready({ + const withAction = drawer({ chosen: { detail: { ...DETAIL, action: { label: "Open lease", to: "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/leases/lse_1/" } }, kind: "event", @@ -189,11 +194,11 @@ describe("the events page's inspector", () => { expect(withAction).toContain( 'Open lease', ); - expect(ready()).not.toContain("Open lease"); + expect(drawer()).not.toContain("Open lease"); }); it("says an event older than the hour is not there, and links back to the list", () => { - const html = ready({ chosen: { id: "evt_old", kind: "missing" }, named: true }); + const html = drawer({ chosen: { id: "evt_old", kind: "missing" } }); expect(text(html)).toContain("Event not in the last hour."); expect(html).toContain('Back to Activity'); diff --git a/ui/src/screens/activity/index.tsx b/ui/src/screens/activity/index.tsx new file mode 100644 index 000000000..db0280494 --- /dev/null +++ b/ui/src/screens/activity/index.tsx @@ -0,0 +1,205 @@ +import "./activity.css"; + +import { + ButtonLink, + ChoiceChips, + Drawer, + Empty, + Facts, + Feed, + focusAfterClosing, + Link, + ListRow, + Loaded, + type LoadView, + MinuteChart, + MinuteTable, + Page, + SearchField, + Toolbar, +} from "../../ds"; +import { useListDrawer } from "../../state/drawer"; +import { + type EventDetail, + type EventRow, + type EventsChart, + type EventsPage, + SUBJECT_CHOICES, + setQuery, + setSubject, + type SubjectFilter, + useEvents, +} from "../../state/events"; + +// why: a row is two lines of fixed height, so the feed can place the rows it draws by arithmetic. +const ROW_PX = 60; + +export function ActivityScreen() { + const view = useEvents(); + const urlId = view.kind === "ready" ? view.data.urlId : undefined; + const { close, fromList } = useListDrawer("/activity", urlId); + return ( + + urlId === undefined + ? null + : focusAfterClosing({ + fromList, + links: ".feed-list a", + path: `/activity/${encodeURIComponent(urlId)}`, + }) + } + /> + ); +} + +export function ActivityContent(props: { + readonly view: LoadView; + readonly onSubject: (subject: SubjectFilter) => void; + readonly onSearch: (query: string) => void; + readonly onClose: () => void; + readonly finalFocus: () => HTMLElement | null; +}) { + const { finalFocus, onClose, onSearch, onSubject, view } = props; + return ( + live}> + + {(page) => ( + <> + + + } + end={} + /> + + {page.urlId === undefined ? null : ( + } + onClose={onClose} + finalFocus={finalFocus} + > + + + )} + + )} + + + ); +} + +function EventList({ page }: { readonly page: EventsPage }) { + const { rows } = page; + const chosenId = page.chosen.kind === "event" ? page.chosen.detail.id : undefined; + if (rows.length === 0) { + return ( + {page.held === 0 ? "No events in the last hour." : "No events of this kind."} + ); + } + return ( + rows[index]?.id ?? String(index)} + newText={(count) => (count === 1 ? "1 new event" : `${count} new events`)} + startAt={page.chosenIndex} + onNearEnd={page.loadOlder} + renderRow={(index) => { + const row = rows[index]; + return row === undefined ? null : ; + }} + /> + ); +} + +function PerMinute({ chart }: { readonly chart: EventsChart }) { + return ( +
+ +

{chart.summary}

+ +
+ ); +} + +function Row({ row, selected }: { readonly row: EventRow; readonly selected: boolean }) { + return ( + + + {row.name} + + } + sub={row.summary} + /> + ); +} + +function toneClass(tone: EventRow["tone"], base: string): string | undefined { + return ( + [base, tone === undefined ? undefined : `event-${tone}`].filter(Boolean).join(" ") || undefined + ); +} + +function DrawerTitle({ page }: { readonly page: EventsPage }) { + const { chosen } = page; + if (chosen.kind !== "event") return <>Event; + return {chosen.detail.name}; +} + +export function DrawerBody({ page }: { readonly page: EventsPage }) { + const { chosen } = page; + if (chosen.kind === "event") return ; + return ( +

+ Event not in the last hour. Back to Activity +

+ ); +} + +function Detail({ detail }: { readonly detail: EventDetail }) { + return ( +
+

+ +

+ {detail.action === undefined ? null : ( +

+ {detail.action.label} +

+ )} +

Payload

+ {detail.pairs.length === 0 ? ( + No payload. + ) : ( + ({ label: pair.key, value: pair.value }))} /> + )} +
+ ); +} diff --git a/ui/src/screens/events/index.tsx b/ui/src/screens/events/index.tsx deleted file mode 100644 index 8abc1fc37..000000000 --- a/ui/src/screens/events/index.tsx +++ /dev/null @@ -1,193 +0,0 @@ -import "./events.css"; - -import { - ButtonLink, - ChoiceChips, - Empty, - Facts, - Feed, - Inspector, - InspectorEmpty, - Link, - ListPane, - ListRow, - Loaded, - type LoadView, - MasterDetail, - MinuteChart, - MinuteTable, - Panel, -} from "../../ds"; -import { - type EventDetail, - type EventRow, - type EventsChart, - type EventsPage, - SUBJECT_CHOICES, - setSubject, - type SubjectFilter, - useEvents, -} from "../../state/events"; - -// why: a row is two lines of fixed height, so the feed can place the rows it draws by arithmetic. -const ROW_PX = 60; - -export function EventsScreen() { - return ; -} - -export function EventsContent(props: { - readonly view: LoadView; - readonly onSubject: (subject: SubjectFilter) => void; -}) { - const { onSubject, view } = props; - if (view.kind !== "ready") { - return ( - - {() => null} - - } - detail={Nothing to show yet.} - /> - ); - } - return ( - - {(page) => ( - } - detail={} - /> - )} - - ); -} - -function EventList(props: { - readonly page: EventsPage; - readonly onSubject: (subject: SubjectFilter) => void; -}) { - const { onSubject, page } = props; - const { rows } = page; - const chosenId = page.chosen.kind === "event" ? page.chosen.detail.id : undefined; - return ( - - - - - } - > - {rows.length === 0 ? ( - {page.held === 0 ? "No events in the last hour." : "No events of this kind."} - ) : ( - rows[index]?.id ?? String(index)} - newText={(count) => (count === 1 ? "1 new event" : `${count} new events`)} - startAt={page.chosenIndex} - onNearEnd={page.loadOlder} - renderRow={(index) => { - const row = rows[index]; - return row === undefined ? null : ; - }} - /> - )} - - ); -} - -function PerMinute({ chart }: { readonly chart: EventsChart }) { - return ( -
- -

{chart.summary}

- -
- ); -} - -function Row({ row, selected }: { readonly row: EventRow; readonly selected: boolean }) { - return ( - - - {row.name} - - } - sub={row.summary} - /> - ); -} - -function toneClass(tone: EventRow["tone"], base: string): string | undefined { - return ( - [base, tone === undefined ? undefined : `event-${tone}`].filter(Boolean).join(" ") || undefined - ); -} - -function Chosen({ page }: { readonly page: EventsPage }) { - const { chosen } = page; - if (chosen.kind === "none") return Nothing to show.; - if (chosen.kind === "missing") { - return ( - - Event not in the last hour. Back to Activity - - ); - } - return ; -} - -function Detail({ detail }: { readonly detail: EventDetail }) { - return ( - {detail.name}} - mono - line={} - actions={ - detail.action === undefined ? undefined : ( - {detail.action.label} - ) - } - > - - {detail.pairs.length === 0 ? ( - No payload. - ) : ( - ({ label: pair.key, value: pair.value }))} /> - )} - - - ); -} diff --git a/ui/src/screens/leases/index.tsx b/ui/src/screens/leases/index.tsx index 1eb3f00cb..5b3f4252c 100644 --- a/ui/src/screens/leases/index.tsx +++ b/ui/src/screens/leases/index.tsx @@ -3,6 +3,7 @@ import "./leases.css"; import { ChoiceChips, type Column, + focusAfterClosing, DataTable, Link, Loaded, @@ -48,7 +49,13 @@ export function LeasesScreen() { key={urlId} id={urlId} onClose={close} - finalFocus={() => focusAfterClosing(fromList, urlId)} + finalFocus={() => + focusAfterClosing({ + fromList, + links: "main tbody a", + path: `/leases/${encodeURIComponent(urlId)}`, + }) + } /> )} @@ -96,15 +103,3 @@ export function LeaseTable(props: { /> ); } - -// why: focus goes back to the row that opened the drawer, or to the page's heading when that row is -// gone or the drawer was loaded directly. -function focusAfterClosing(fromList: boolean, id: string): HTMLElement | null { - const prefix = `/leases/${encodeURIComponent(id)}/`; - const row = fromList - ? [...document.querySelectorAll("main tbody a")].find((link) => - link.getAttribute("href")?.startsWith(prefix), - ) - : undefined; - return row ?? document.querySelector("main h1"); -} diff --git a/ui/src/screens/waiting/index.tsx b/ui/src/screens/queue/index.tsx similarity index 98% rename from ui/src/screens/waiting/index.tsx rename to ui/src/screens/queue/index.tsx index d86259dd2..9cd8d435a 100644 --- a/ui/src/screens/waiting/index.tsx +++ b/ui/src/screens/queue/index.tsx @@ -1,4 +1,4 @@ -import "./waiting.css"; +import "./queue.css"; import { Card, @@ -28,7 +28,7 @@ import { useWaiting, } from "../../state/waiting"; -export function WaitingScreen() { +export function QueueScreen() { const view = useWaiting(); return {(page) => }; } diff --git a/ui/src/screens/waiting/waiting.css b/ui/src/screens/queue/queue.css similarity index 100% rename from ui/src/screens/waiting/waiting.css rename to ui/src/screens/queue/queue.css diff --git a/ui/src/screens/waiting/waiting.test.tsx b/ui/src/screens/queue/queue.test.tsx similarity index 100% rename from ui/src/screens/waiting/waiting.test.tsx rename to ui/src/screens/queue/queue.test.tsx diff --git a/ui/src/state/drawer.ts b/ui/src/state/drawer.ts new file mode 100644 index 000000000..227d62ea6 --- /dev/null +++ b/ui/src/state/drawer.ts @@ -0,0 +1,27 @@ +import { useRef } from "react"; + +import type { Section } from "../model/paths"; +import { navigate, useSearch } from "./router"; + +export interface ListDrawerState { + readonly fromList: boolean; + readonly close: () => void; +} + +// why: the screen stays mounted from the list to an item, so an item that appears while it is +// mounted was opened from the list in this tab, and one present at the first render was loaded +// directly. Closing the first is a step back, so Back does not reopen it; the second has no list +// entry behind it, so closing replaces its address. +export function useListDrawer(section: Section, urlId: string | undefined): ListDrawerState { + const mountedOpen = useRef(urlId !== undefined); + if (urlId === undefined) mountedOpen.current = false; + const fromList = !mountedOpen.current; + const address = useSearch(); + return { + close: () => { + if (fromList) window.history.back(); + else navigate(`${section}${address}`, { replace: true }); + }, + fromList, + }; +} diff --git a/ui/src/state/events.ts b/ui/src/state/events.ts index 46aaf06d3..ed0e74d32 100644 --- a/ui/src/state/events.ts +++ b/ui/src/state/events.ts @@ -18,6 +18,7 @@ import { writeSubject, } from "../model/event-list"; import type { ConsoleEvent } from "../model/events"; +import { readQuery, writeQuery } from "../model/paging"; import type { LeaseList, LeaseRecord } from "../model/leases"; import { itemIdFrom } from "../model/paths"; import type { WaitingList, WaitingRequest } from "../model/waiting"; @@ -55,16 +56,17 @@ const MINUTE = 60_000; export interface EventsPage { readonly subject: SubjectFilter; + readonly query: string; // why: an empty list says whether nothing happened or the filter hides it. readonly held: number; readonly rows: readonly EventRow[]; readonly chart: EventsChart; readonly chosen: Chosen; - // why: only a URL that names an event shows the inspector first on a phone. - readonly named: boolean; // why: the row the chosen event sits at, so the box opens with it in view. readonly chosenIndex: number; readonly loadOlder: () => void; + // why: the id in the URL stands before the list has loaded, so the drawer can open at once. + readonly urlId: string | undefined; } export function useEvents(): LoadView { @@ -76,17 +78,19 @@ export function useEvents(): LoadView { const leases = useLiveResource("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/v1/leases").data?.leases ?? NO_LEASES; const requests = useLiveResource("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/v1/lease-requests").data?.requests ?? NO_REQUESTS; const now = useNow().server; - const subject = readSubject(useSearch()); + const address = useSearch(); + const subject = readSubject(address); + const query = readQuery(address); const id = itemIdFrom("/activity", usePath()); const rows = useMemo( - () => (events === undefined ? [] : eventRows(events, workers, subject)), - [events, workers, subject], + () => (events === undefined ? [] : eventRows(events, workers, subject, query)), + [events, workers, subject, query], ); // why: the chart moves once a minute, not with the clock's every tick. const minute = Math.floor(now / MINUTE) * MINUTE; const chart = useMemo(() => eventsChart(events ?? [], minute), [events, minute]); return mapView(loadView(feed), (held) => { - const chosen = chosenEvent(held, rows, id, { leases, requests, workers }, now); + const chosen = chosenEvent(held, id, { leases, requests, workers }, now); const chosenId = chosen.kind === "event" ? chosen.detail.id : undefined; return { chart, @@ -97,9 +101,10 @@ export function useEvents(): LoadView { 0, rows.findIndex((row) => row.id === chosenId), ), - named: id !== undefined, + query, rows, subject, + urlId: id, }; }); } @@ -107,3 +112,9 @@ export function useEvents(): LoadView { export function setSubject(subject: SubjectFilter): void { setSearch(writeSubject(window.location.search, subject), { replace: true }); } + +// why: each key replaces the entry rather than adding one, so Back leaves the page, not a letter +// of the search. +export function setQuery(query: string): void { + setSearch(writeQuery(window.location.search, query), { replace: true }); +} diff --git a/ui/src/state/leases.ts b/ui/src/state/leases.ts index ae91c7f91..38b546362 100644 --- a/ui/src/state/leases.ts +++ b/ui/src/state/leases.ts @@ -1,4 +1,4 @@ -import { useRef, useState } from "react"; +import { useState } from "react"; import { ApiError } from "../data/api"; import type { LoadView } from "../ds/loaded"; @@ -21,10 +21,11 @@ import { listSearch, readQuery, TABLE_SIZES, writeQuery } from "../model/paging" import { itemIdFrom } from "../model/paths"; import type { WorkerList } from "../model/workers"; import { useRecentEvents } from "./events"; +import { useListDrawer, type ListDrawerState } from "./drawer"; import { useLiveResource, useNow } from "./live"; import { usePaging } from "./paging"; import { loadView, mapView } from "./resource"; -import { navigate, setSearch, usePath, useSearch } from "./router"; +import { setSearch, usePath, useSearch } from "./router"; export { type EventRow } from "../model/event-list"; export { @@ -50,27 +51,8 @@ export interface Leases { readonly urlId: string | undefined; } -export interface LeaseDrawerState { - readonly fromList: boolean; - readonly close: () => void; -} - -// why: the screen stays mounted from the list to a lease, so a lease that appears while it is -// mounted was opened from the list in this tab, and one present at the first render was loaded -// directly. Closing the first is a step back, so Back does not reopen it; the second has no list -// entry behind it, so closing replaces its address. -export function useLeaseDrawer(urlId: string | undefined): LeaseDrawerState { - const mountedOpen = useRef(urlId !== undefined); - if (urlId === undefined) mountedOpen.current = false; - const fromList = !mountedOpen.current; - const address = useSearch(); - return { - close: () => { - if (fromList) window.history.back(); - else navigate(`/leases${address}`, { replace: true }); - }, - fromList, - }; +export function useLeaseDrawer(urlId: string | undefined): ListDrawerState { + return useListDrawer("/leases", urlId); } // why: tokens and workers only name what the leases already show, so while they have not arrived From 6f9855e0ec5ebf5afdaebf9a4c88cbaeb662aa1d Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Tue, 20 Oct 2026 21:14:49 +0200 Subject: [PATCH 05/28] test: each Activity end row shows its wording in the browser (#767) --- e2e/console/activity.spec.ts | 70 ++++++++++++++++++++++++++++++++++-- 1 file changed, 68 insertions(+), 2 deletions(-) diff --git a/e2e/console/activity.spec.ts b/e2e/console/activity.spec.ts index 58796af76..1a1359786 100644 --- a/e2e/console/activity.spec.ts +++ b/e2e/console/activity.spec.ts @@ -127,9 +127,17 @@ function stubbed(n: number, now: number): Stubbed { }; } +// why: one clock for every stubbed event, so a time the test names is the time the page shows. +const BASE = Date.now(); + function stubbedRange(from: number, to: number): Stubbed[] { - const now = Date.now(); - return Array.from({ length: to - from + 1 }, (_, index) => stubbed(to - index, now)); + return Array.from({ length: to - from + 1 }, (_, index) => stubbed(to - index, BASE)); +} + +function localMinute(timestamp: number): string { + const date = new Date(timestamp); + const part = (value: number) => String(value).padStart(2, "0"); + return `${date.getFullYear()}-${part(date.getMonth() + 1)}-${part(date.getDate())} ${part(date.getHours())}:${part(date.getMinutes())}`; } interface StubbedAnswer { @@ -362,6 +370,64 @@ test.describe("the Activity page", () => { } }); + test("each end row shows its wording: the history's start, the 10,000 cap, a 422, a 503 and a 500 with Try again, and a page of events already held", async ({ + page, + }) => { + const host = await startDaemon("worker", { driverScript: { ios: IOS } }); + try { + await openEvents(page, host); + + let queries = await stubEvents(page, (query) => { + if (query.get("before") === null) return { events: stubbedRange(1, 30) }; + return query.get("before") === "evt_0030" ? { events: stubbedRange(31, 70) } : {}; + }); + await page.reload(); + await expect( + page.getByText(`Start of the history (${localMinute(BASE - 70 * 60_000)})`), + ).toBeVisible(); + await expect.poll(() => eventsHeld(page)).toBe(70); + expect(older(queries)).toEqual(["?before=evt_0030&limit=100"]); + + queries = await stubEvents(page, () => ({ events: stubbedRange(1, 10_000) })); + await page.reload(); + await expect(page.getByText("Showing the newest 10,000 events.")).toBeVisible(); + expect(older(queries)).toEqual([]); + + queries = await stubEvents(page, (query) => + query.get("before") === null ? { events: stubbedRange(1, 30) } : { status: 422 }, + ); + await page.reload(); + await expect(page.getByText("Older events are no longer kept.")).toBeVisible(); + expect(older(queries)).toHaveLength(1); + + for (const status of [503, 500]) { + let failing = true; + queries = await stubEvents(page, (query) => { + if (query.get("before") === null) return { events: stubbedRange(1, 30) }; + return failing ? { status } : { events: stubbedRange(31, 40) }; + }); + await page.reload(); + await expect(page.getByText("Older events are not available right now.")).toBeVisible(); + expect(older(queries)).toHaveLength(1); + failing = false; + await page.getByRole("button", { name: "Try again" }).click(); + await expect(page.getByText("Start of the history (", { exact: false })).toBeVisible(); + expect(older(queries)).toHaveLength(2); + } + + queries = await stubEvents(page, () => ({ events: stubbedRange(1, 100) })); + await page.reload(); + await expect.poll(() => eventsHeld(page)).toBe(100); + await feed(page).focus(); + await page.keyboard.press("End"); + await expect(page.getByText("Start of the history (", { exact: false })).toBeVisible(); + expect(older(queries)).toEqual(["?before=evt_0100&limit=100"]); + expect(await eventsHeld(page)).toBe(100); + } finally { + await host.dispose(); + } + }); + test("on a gateway, a worker's event shows that worker's label", async ({ page }) => { const fleet = await startFleet([{ driverScript: { ios: IOS }, label: "worker-a" }]); try { From 8e4e4328f79e6fce02998617c4fa3333b016c84f Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Tue, 20 Oct 2026 21:17:31 +0200 Subject: [PATCH 06/28] feat(console): Activity's last row says why the list stops, and Try again asks again (#767) --- ui/src/data/event-feed.ts | 32 +++++++++++---- ui/src/ds/feed.css | 12 ++++++ ui/src/ds/feed.tsx | 4 ++ ui/src/model/events.ts | 50 +++++++++++++++++++++++ ui/src/screens/activity/activity.test.tsx | 1 + ui/src/screens/activity/index.tsx | 19 +++++++++ ui/src/state/events.ts | 16 ++++++-- 7 files changed, 122 insertions(+), 12 deletions(-) diff --git a/ui/src/data/event-feed.ts b/ui/src/data/event-feed.ts index c666e196c..a698095ac 100644 --- a/ui/src/data/event-feed.ts +++ b/ui/src/data/event-feed.ts @@ -1,4 +1,4 @@ -import type { ApiPath } from "./api"; +import { ApiError, type ApiPath } from "./api"; import { type Clock, isRefusal, @@ -8,9 +8,12 @@ import { } from "./live/connection"; import { type ConsoleEvent, + type HistoryState, + MAX_EVENTS, mergeEvents, OLDER_PAGE as PAGE, readEvent, + readOlder, readReplay, RECENT, sinceFor, @@ -30,6 +33,7 @@ export class EventFeed { #gapFrom: number | undefined; #loading = false; #loadingOlder = false; + #history: HistoryState = "more"; // why: counts the stream's opens, so a load knows whether one happened while it was out. #opens = 0; #retryTimer: unknown; @@ -117,9 +121,13 @@ export class EventFeed { ); } - // why: one page at a time; a second signal before the answer is dropped. + readonly history = (): HistoryState => this.#history; + + // why: one page at a time, none once the history has ended, and none at the cap: a second signal + // before the answer is dropped. readonly loadOlder = (): void => { - if (!this.#active || this.#loadingOlder) return; + if (!this.#active || this.#loadingOlder || this.#events.length >= MAX_EVENTS) return; + if (this.#history !== "more" && this.#history !== "failed") return; const oldest = this.#events.at(-1); const query = oldest === undefined @@ -127,20 +135,28 @@ export class EventFeed { : `before=${encodeURIComponent(oldest.id)}&limit=${PAGE}`; this.#loadingOlder = true; this.#get(`/v1/events?${query}`) - .then(readReplay) + .then(readOlder) .then( - (events) => { + (page) => { this.#loadingOlder = false; if (!this.#active) return; - this.#events = mergeEvents(this.#events, events); - this.#publish({ ...this.#state, data: this.#events }); + const current = this.#events; + this.#events = mergeEvents(current, page.events); + this.#setHistory(page.full && this.#events !== current ? "more" : "start"); }, - () => { + (error: unknown) => { this.#loadingOlder = false; + if (!this.#active) return; + this.#setHistory(error instanceof ApiError && error.status === 422 ? "gone" : "failed"); }, ); }; + #setHistory(history: HistoryState): void { + this.#history = history; + this.#publish({ ...this.#state, data: this.#events }); + } + #retryLater(): void { const delay = RETRY_BACKOFF_MS[this.#retryAttempt] ?? RETRY_INTERVAL_MS; this.#retryAttempt += 1; diff --git a/ui/src/ds/feed.css b/ui/src/ds/feed.css index b7f8455fc..2834435bb 100644 --- a/ui/src/ds/feed.css +++ b/ui/src/ds/feed.css @@ -39,3 +39,15 @@ background: var(--bg); transform: translateX(-50%); } + +/* The last row: why the list stops, below the scrolling box and outside the list. */ +.feed-end { + display: flex; + flex-wrap: wrap; + align-items: center; + gap: var(--space-3); + margin: 0; + padding: var(--space-3) var(--space-4); + border-top: 1px solid var(--border); + font-size: var(--text-sm); +} diff --git a/ui/src/ds/feed.tsx b/ui/src/ds/feed.tsx index ceda6a7a6..0eaa092b1 100644 --- a/ui/src/ds/feed.tsx +++ b/ui/src/ds/feed.tsx @@ -27,10 +27,13 @@ export function Feed(props: { readonly newText: (count: number) => string; readonly startAt?: number; readonly onNearEnd?: () => void; + // why: below the scrolling box, outside the list, so it never counts as a row. + readonly footer?: ReactNode; readonly renderRow: (index: number) => ReactNode; }) { const { count, + footer, keyAt, label, listLabel, @@ -86,6 +89,7 @@ export function Feed(props: { ))} + {footer} ); } diff --git a/ui/src/model/events.ts b/ui/src/model/events.ts index d7191c28b..40be873f6 100644 --- a/ui/src/model/events.ts +++ b/ui/src/model/events.ts @@ -40,6 +40,56 @@ export function readReplay(body: unknown): readonly ConsoleEvent[] { return events.flatMap((data: unknown) => readEvent(data) ?? []); } +export interface OlderPage { + readonly events: readonly ConsoleEvent[]; + // why: counted on the raw reply, before malformed events are dropped, so a page that was full on + // the wire is not taken for the history's end. + readonly full: boolean; +} + +export function readOlder(body: unknown): OlderPage { + const events = readReplay(body); + const raw = (body as { readonly events: readonly unknown[] }).events.length; + return { events, full: raw >= OLDER_PAGE }; +} + +// why: where the older events stand: more may come, the history has started, the daemon no longer +// keeps older events, or the last ask failed and may be repeated. +export type HistoryState = "more" | "start" | "gone" | "failed"; + +export interface HistoryEnd { + readonly text: string; + readonly retry: boolean; +} + +function localMinute(timestamp: number): string { + const date = new Date(timestamp); + const part = (value: number) => String(value).padStart(2, "0"); + return `${date.getFullYear()}-${part(date.getMonth() + 1)}-${part(date.getDate())} ${part(date.getHours())}:${part(date.getMinutes())}`; +} + +// why: the last row says why the list stops; nothing is said while more may still load. +export function historyEnd( + state: HistoryState, + held: readonly ConsoleEvent[], +): HistoryEnd | undefined { + if (held.length >= MAX_EVENTS) { + return { + retry: false, + text: `Showing the newest ${MAX_EVENTS.toLocaleString("en-US")} events.`, + }; + } + const oldest = held.at(-1); + if (state === "start" && oldest !== undefined) { + return { retry: false, text: `Start of the history (${localMinute(oldest.timestamp)})` }; + } + if (state === "gone") return { retry: false, text: "Older events are no longer kept." }; + if (state === "failed") { + return { retry: true, text: "Older events are not available right now." }; + } + return undefined; +} + // why: identity is the `id` alone, so an event seen twice, by the stream and by the `since` window, // is shown once. function keyOf(event: ConsoleEvent): string { diff --git a/ui/src/screens/activity/activity.test.tsx b/ui/src/screens/activity/activity.test.tsx index 70464a645..b96905076 100644 --- a/ui/src/screens/activity/activity.test.tsx +++ b/ui/src/screens/activity/activity.test.tsx @@ -47,6 +47,7 @@ function page(over: Partial = {}): EventsPage { }, chosen: { detail: DETAIL, kind: "event" }, chosenIndex: 0, + end: undefined, held: 1, loadOlder: () => {}, query: "", diff --git a/ui/src/screens/activity/index.tsx b/ui/src/screens/activity/index.tsx index db0280494..cce71b416 100644 --- a/ui/src/screens/activity/index.tsx +++ b/ui/src/screens/activity/index.tsx @@ -1,6 +1,7 @@ import "./activity.css"; import { + Button, ButtonLink, ChoiceChips, Drawer, @@ -24,6 +25,7 @@ import { type EventRow, type EventsChart, type EventsPage, + type HistoryEnd, SUBJECT_CHOICES, setQuery, setSubject, @@ -119,6 +121,9 @@ function EventList({ page }: { readonly page: EventsPage }) { newText={(count) => (count === 1 ? "1 new event" : `${count} new events`)} startAt={page.chosenIndex} onNearEnd={page.loadOlder} + footer={ + page.end === undefined ? undefined : + } renderRow={(index) => { const row = rows[index]; return row === undefined ? null : ; @@ -127,6 +132,20 @@ function EventList({ page }: { readonly page: EventsPage }) { ); } +function EndRow(props: { readonly end: HistoryEnd; readonly onRetry: () => void }) { + const { end, onRetry } = props; + return ( +

+ {end.text} + {end.retry ? ( + + ) : null} +

+ ); +} + function PerMinute({ chart }: { readonly chart: EventsChart }) { return (
diff --git a/ui/src/state/events.ts b/ui/src/state/events.ts index ed0e74d32..25f5fae48 100644 --- a/ui/src/state/events.ts +++ b/ui/src/state/events.ts @@ -17,7 +17,7 @@ import { type SubjectFilter, writeSubject, } from "../model/event-list"; -import type { ConsoleEvent } from "../model/events"; +import { type ConsoleEvent, type HistoryEnd, type HistoryState, historyEnd } from "../model/events"; import { readQuery, writeQuery } from "../model/paging"; import type { LeaseList, LeaseRecord } from "../model/leases"; import { itemIdFrom } from "../model/paths"; @@ -28,7 +28,7 @@ import { loadView, mapView } from "./resource"; import { setSearch, usePath, useSearch } from "./router"; import { useApi } from "./services"; -export type { Chosen, EventDetail, EventRow, EventsChart, SubjectFilter }; +export type { Chosen, EventDetail, EventRow, EventsChart, HistoryEnd, SubjectFilter }; export { SUBJECT_CHOICES }; // why: each screen that reads events holds its own feed, filled from the last hour and then the @@ -36,13 +36,18 @@ export { SUBJECT_CHOICES }; export function useEventFeed(): { readonly feed: EventFeed; readonly state: ResourceState; + readonly history: HistoryState; } { const api = useApi(); const [feed] = useState(() => new EventFeed((path) => api.getJson(path), browserClock)); useLiveEvents(feed.streamEvent); useStreamOpened(feed.streamOpened); useEffect(() => feed.start(), [feed]); - return { feed, state: useSyncExternalStore(feed.subscribe, feed.snapshot) }; + return { + feed, + history: useSyncExternalStore(feed.subscribe, feed.history), + state: useSyncExternalStore(feed.subscribe, feed.snapshot), + }; } export function useRecentEvents(): ResourceState { @@ -65,12 +70,14 @@ export interface EventsPage { // why: the row the chosen event sits at, so the box opens with it in view. readonly chosenIndex: number; readonly loadOlder: () => void; + // why: the last row says why the list stops; none while more may still load. + readonly end: HistoryEnd | undefined; // why: the id in the URL stands before the list has loaded, so the drawer can open at once. readonly urlId: string | undefined; } export function useEvents(): LoadView { - const { feed: source, state: feed } = useEventFeed(); + const { feed: source, history, state: feed } = useEventFeed(); const events = feed.data; // why: the places an event links to are read for the links only; a route that is slow, refused // or not served here costs the feed nothing, only the link. @@ -95,6 +102,7 @@ export function useEvents(): LoadView { return { chart, chosen, + end: historyEnd(history, held), held: held.length, loadOlder: source.loadOlder, chosenIndex: Math.max( From 450b8e26e66dcb7a10e9d8168c15341728120754 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Tue, 20 Oct 2026 21:18:21 +0200 Subject: [PATCH 07/28] test: a daemon with no events in the last hour shows older history at once, and an empty history says No events yet (#767) --- e2e/console/activity.spec.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/e2e/console/activity.spec.ts b/e2e/console/activity.spec.ts index 1a1359786..c27c4815e 100644 --- a/e2e/console/activity.spec.ts +++ b/e2e/console/activity.spec.ts @@ -428,6 +428,30 @@ test.describe("the Activity page", () => { } }); + test("a daemon with no events in the last hour but older history shows them at once, and an empty history says No events yet", async ({ + page, + }) => { + const host = await startDaemon("worker", { driverScript: { ios: IOS } }); + try { + await openEvents(page, host); + + let queries = await stubEvents(page, (query) => + query.has("since") ? {} : { events: stubbedRange(1, 40) }, + ); + await page.reload(); + await expect.poll(() => eventsHeld(page)).toBe(40); + await expect(rows(page).first()).toBeVisible(); + expect(older(queries)).toEqual(["?limit=100"]); + + queries = await stubEvents(page, () => ({})); + await page.reload(); + await expect(page.getByText("No events yet.")).toBeVisible(); + expect(older(queries)).toEqual(["?limit=100"]); + } finally { + await host.dispose(); + } + }); + test("on a gateway, a worker's event shows that worker's label", async ({ page }) => { const fleet = await startFleet([{ driverScript: { ios: IOS }, label: "worker-a" }]); try { From 23ce2c190ab74f579e90731271d2be0a4e6649d0 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Tue, 20 Oct 2026 21:21:36 +0200 Subject: [PATCH 08/28] feat(console): a quiet last hour shows the newest older events at once, and an empty history says so (#767) --- ui/src/data/event-feed.ts | 2 ++ ui/src/model/events.ts | 10 ++++++++-- ui/src/screens/activity/activity.test.tsx | 14 +++++++++++--- ui/src/screens/activity/index.tsx | 9 ++++++--- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/ui/src/data/event-feed.ts b/ui/src/data/event-feed.ts index a698095ac..b753d6e79 100644 --- a/ui/src/data/event-feed.ts +++ b/ui/src/data/event-feed.ts @@ -107,6 +107,8 @@ export class EventFeed { this.#events = mergeEvents(this.#events, events); this.#publish({ data: this.#events }); this.#loadMissing(); + // why: a quiet last hour still shows the older history, so the newest page is asked for at once. + if (this.#events.length === 0) this.loadOlder(); }, (error: unknown) => { this.#loading = false; diff --git a/ui/src/model/events.ts b/ui/src/model/events.ts index 40be873f6..17c26a5ca 100644 --- a/ui/src/model/events.ts +++ b/ui/src/model/events.ts @@ -80,8 +80,14 @@ export function historyEnd( }; } const oldest = held.at(-1); - if (state === "start" && oldest !== undefined) { - return { retry: false, text: `Start of the history (${localMinute(oldest.timestamp)})` }; + if (state === "start") { + return { + retry: false, + text: + oldest === undefined + ? "No events yet." + : `Start of the history (${localMinute(oldest.timestamp)})`, + }; } if (state === "gone") return { retry: false, text: "Older events are no longer kept." }; if (state === "failed") { diff --git a/ui/src/screens/activity/activity.test.tsx b/ui/src/screens/activity/activity.test.tsx index b96905076..682ca6451 100644 --- a/ui/src/screens/activity/activity.test.tsx +++ b/ui/src/screens/activity/activity.test.tsx @@ -141,9 +141,17 @@ describe("the events page", () => { }); it("says why an empty list is empty", () => { - expect(text(ready({ chosen: { kind: "none" }, held: 0, rows: [] }))).toContain( - "No events in the last hour.", - ); + expect(text(ready({ chosen: { kind: "none" }, held: 0, rows: [] }))).toContain("Loading…"); + expect( + text( + ready({ + chosen: { kind: "none" }, + end: { retry: false, text: "No events yet." }, + held: 0, + rows: [], + }), + ), + ).toContain("No events yet."); expect( text(ready({ chosen: { kind: "none" }, held: 5, rows: [], subject: "device" })), ).toContain("No events of this kind."); diff --git a/ui/src/screens/activity/index.tsx b/ui/src/screens/activity/index.tsx index cce71b416..eb365b639 100644 --- a/ui/src/screens/activity/index.tsx +++ b/ui/src/screens/activity/index.tsx @@ -105,11 +105,14 @@ export function ActivityContent(props: { function EventList({ page }: { readonly page: EventsPage }) { const { rows } = page; const chosenId = page.chosen.kind === "event" ? page.chosen.detail.id : undefined; - if (rows.length === 0) { - return ( - {page.held === 0 ? "No events in the last hour." : "No events of this kind."} + if (page.held === 0) { + return page.end === undefined ? ( +

Loading…

+ ) : ( + ); } + if (rows.length === 0) return No events of this kind.; return ( Date: Tue, 20 Oct 2026 21:22:27 +0200 Subject: [PATCH 09/28] test: with a chip or a search on nothing loads by itself, and Load older events loads one page per press (#767) --- e2e/console/activity.spec.ts | 37 +++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/e2e/console/activity.spec.ts b/e2e/console/activity.spec.ts index c27c4815e..15c1f385d 100644 --- a/e2e/console/activity.spec.ts +++ b/e2e/console/activity.spec.ts @@ -51,7 +51,7 @@ async function openEvents(page: Page, daemon: RunningDaemon, path = "/activity") await page.goto(new URL(path, daemon.url).href); await signIn(page, daemon.tokens.operator); // why: a drawer over the page hides the page's heading from the accessibility tree. - if (path === "/activity") { + if (new URL(path, daemon.url).pathname === "/activity") { await expect(page.getByRole("heading", { level: 1, name: "Activity" })).toBeVisible(); } else await expect(page.getByRole("dialog")).toBeVisible(); } @@ -452,6 +452,41 @@ test.describe("the Activity page", () => { } }); + test("with a chip or a search on, nothing loads by itself, and Load older events loads one page per press", async ({ + page, + }) => { + const host = await startDaemon("worker", { driverScript: { ios: IOS } }); + try { + await openEvents(page, host); + for (const address of ["/activity?subject=lease", "/activity?q=RENEWED"]) { + const queries = await stubEvents(page, (query) => { + if (query.get("before") === null) return { events: stubbedRange(1, 30) }; + if (query.get("before") === "evt_0030") return { events: stubbedRange(31, 130) }; + return query.get("before") === "evt_0130" ? { events: stubbedRange(131, 230) } : {}; + }); + await page.goto(new URL(address, host.url).href); + await expect(page.getByRole("heading", { level: 1, name: "Activity" })).toBeVisible(); + await expect.poll(() => eventsHeld(page)).toBe(30); + const more = page.getByRole("button", { name: "Load older events" }); + await expect(more).toBeVisible(); + await page.waitForTimeout(500); + expect(older(queries)).toEqual([]); + + await more.click(); + await expect.poll(() => eventsHeld(page)).toBe(130); + expect(older(queries)).toEqual(["?before=evt_0030&limit=100"]); + await page.waitForTimeout(500); + expect(older(queries)).toHaveLength(1); + + await more.click(); + await expect.poll(() => eventsHeld(page)).toBe(230); + expect(older(queries)).toHaveLength(2); + } + } finally { + await host.dispose(); + } + }); + test("on a gateway, a worker's event shows that worker's label", async ({ page }) => { const fleet = await startFleet([{ driverScript: { ios: IOS }, label: "worker-a" }]); try { From 557979113adcb800272616488901eed11ec610b6 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Tue, 20 Oct 2026 21:23:32 +0200 Subject: [PATCH 10/28] feat(console): with a chip or a search on, Activity loads older events only when asked (#767) --- ui/src/ds/feed.tsx | 2 +- ui/src/screens/activity/index.tsx | 22 ++++++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/ui/src/ds/feed.tsx b/ui/src/ds/feed.tsx index 0eaa092b1..775913a58 100644 --- a/ui/src/ds/feed.tsx +++ b/ui/src/ds/feed.tsx @@ -26,7 +26,7 @@ export function Feed(props: { readonly keyAt: (index: number) => string; readonly newText: (count: number) => string; readonly startAt?: number; - readonly onNearEnd?: () => void; + readonly onNearEnd?: (() => void) | undefined; // why: below the scrolling box, outside the list, so it never counts as a row. readonly footer?: ReactNode; readonly renderRow: (index: number) => ReactNode; diff --git a/ui/src/screens/activity/index.tsx b/ui/src/screens/activity/index.tsx index eb365b639..18091f2e9 100644 --- a/ui/src/screens/activity/index.tsx +++ b/ui/src/screens/activity/index.tsx @@ -105,6 +105,9 @@ export function ActivityContent(props: { function EventList({ page }: { readonly page: EventsPage }) { const { rows } = page; const chosenId = page.chosen.kind === "event" ? page.chosen.detail.id : undefined; + // why: a chip or a search shows few of the events held, so scrolling would not tell how many + // more are worth loading; the reader asks for each page. + const narrowed = page.subject !== "all" || page.query !== ""; if (page.held === 0) { return page.end === undefined ? (

Loading…

@@ -123,10 +126,8 @@ function EventList({ page }: { readonly page: EventsPage }) { keyAt={(index) => rows[index]?.id ?? String(index)} newText={(count) => (count === 1 ? "1 new event" : `${count} new events`)} startAt={page.chosenIndex} - onNearEnd={page.loadOlder} - footer={ - page.end === undefined ? undefined : - } + onNearEnd={narrowed ? undefined : page.loadOlder} + footer={