diff --git a/e2e/events.spec.ts b/e2e/events.spec.ts index 7891e2f2..aca14838 100644 --- a/e2e/events.spec.ts +++ b/e2e/events.spec.ts @@ -1,4 +1,4 @@ -import {downloadText, expect, expectLoadFailures, fulfillStream, mockBackend, test} from './fixtures'; +import {downloadText, expect, expectLoadFailures, fulfillStream, mockBackend, scrollTableToEnd, test} from './fixtures'; test('event kind selection exports only the visible records', async ({page}) => { const {api, capabilities} = await mockBackend(page); @@ -47,6 +47,8 @@ test('runtime heartbeats cannot evict other events from the default feed or expo await page.setViewportSize({width: 390, height: 844}); await page.goto('/#/events'); const grid = page.getByRole('grid', {name: 'Events', exact: true}); + await expect(grid.locator('[role=row][data-key]').first()).toBeVisible(); + await scrollTableToEnd(grid); const summary = grid.getByRole('columnheader', {name: /^Summary /}); await expect(summary).toBeInViewport({ratio: 1}); await expect(grid.getByRole('rowheader')).toHaveText([data.instance_id]); @@ -97,7 +99,10 @@ test('a long gap summary on a phone keeps its help button in view', async ({page ); await page.setViewportSize({width: 390, height: 844}); await page.goto('/#/events'); - const cell = page.getByRole('grid', {name: 'Events', exact: true}).getByRole('rowheader'); + const grid = page.getByRole('grid', {name: 'Events', exact: true}); + await expect(grid.locator('[role=row][data-key]').first()).toBeVisible(); + await scrollTableToEnd(grid); + const cell = grid.getByRole('rowheader'); await expect(cell).toContainText(id); const help = cell.getByRole('button', {name: 'About records reached the retention limit', exact: true}); await expect(help).toBeInViewport({ratio: 1}); diff --git a/e2e/fixtures.ts b/e2e/fixtures.ts index 3b9ae587..0e781e98 100644 --- a/e2e/fixtures.ts +++ b/e2e/fixtures.ts @@ -83,6 +83,15 @@ export const test = base.extend<{storage: Record; signedIn: stri export const faults = {'doona-mock-scenario': 'faults'}; // The selected item's detail: an aside beside the list on wide screens, a drawer below 1200px. +// A phone keeps every column and scrolls the table sideways, the container around a native table and the grid itself +// once virtualised; this brings the trailing columns into view. +export async function scrollTableToEnd(grid: Locator) { + await grid.evaluate(el => { + const scroller = el.tagName === 'TABLE' ? el.parentElement! : el; + scroller.scrollLeft = scroller.scrollWidth; + }); +} + export const detail = (page: Page) => page.locator('.rp-panel, .rp-drawer'); // The language and scheme the page takes from its next load. export const setAppearance = (page: Page, lang: string, scheme: string) => diff --git a/e2e/logs.spec.ts b/e2e/logs.spec.ts index 58c86fa7..0dadf231 100644 --- a/e2e/logs.spec.ts +++ b/e2e/logs.spec.ts @@ -1,4 +1,4 @@ -import {downloadText, expect, expectLoadFailures, fulfillStream, mockBackend, test} from './fixtures'; +import {downloadText, expect, expectLoadFailures, fulfillStream, mockBackend, scrollTableToEnd, test} from './fixtures'; test('logs filter the stream, pause incoming rows, export and clear', async ({page}) => { const {api} = await mockBackend(page); @@ -80,6 +80,8 @@ test('phone logs keep the message visible and reveal its full text and fields', const grid = page.getByRole('grid', {name: 'Logs', exact: true}); // The activity heatmap sits above the list; on a phone the list starts below it. await grid.scrollIntoViewIfNeeded(); + await expect(grid.locator('[role=row][data-key]').first()).toBeVisible(); + await scrollTableToEnd(grid); await expect(grid.getByRole('columnheader', {name: /^Message /})).toBeInViewport({ratio: 1}); // The truncated cell carries the tooltip once it has measured its overflow. const cell = grid.getByRole('rowheader').locator('.rp-truncate'); diff --git a/e2e/phone-table-scroll.spec.ts b/e2e/phone-table-scroll.spec.ts new file mode 100644 index 00000000..a4cd8d19 --- /dev/null +++ b/e2e/phone-table-scroll.spec.ts @@ -0,0 +1,61 @@ +import {expect, fulfillStream, mockBackend, test} from './fixtures'; + +// On a phone a table keeps its columns' minimum widths and scrolls sideways (src/ui/Table.tsx); wider screens fit the +// columns to the table as before. +const message = 'Health check failed. node=jp-01 error=connect timeout after 5000 ms while dialing the upstream'; + +async function logs(page: import('@playwright/test').Page) { + const {api} = await mockBackend(page); + const runtime = await api.runtime(); + await page.route('**/api/v1/logs?*', route => + fulfillStream(route, [ + {id: 'ready:0', event: 'stream.ready', data: {instance_id: runtime.instance_id, observed_at: runtime.observed_at}}, + {id: 'log:1', event: 'log', data: {ts: runtime.observed_at, level: 'warn', target: 'health', message, fields: null}} + ]) + ); + await page.goto('/#/logs'); + const grid = page.getByRole('grid', {name: 'Logs', exact: true}); + await grid.scrollIntoViewIfNeeded(); + await expect(grid.locator('[role=row][data-key]').first()).toBeVisible(); + return grid; +} + +test.describe('390px', () => { + test.use({viewport: {width: 390, height: 844}, hasTouch: true}); + + test('the logs table scrolls sideways to its whole message column', async ({page}) => { + const grid = await logs(page); + // A virtualised grid is its own scroller. + const scroll = () => grid.evaluate(el => ({width: el.scrollWidth, client: el.clientWidth, left: el.scrollLeft})); + await expect.poll(async () => (await scroll()).width - (await scroll()).client).toBeGreaterThan(0); + expect(await page.evaluate(() => document.documentElement.scrollWidth)).toBe(390); + for (const name of [/^Time /, /^Level /, /^Module /]) await expect(grid.getByRole('columnheader', {name})).toBeVisible(); + expect((await scroll()).left).toBe(0); + const box = (await grid.boundingBox())!; + await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2); + await page.mouse.wheel(2000, 0); + await expect.poll(async () => (await scroll()).left).toBeGreaterThan(0); + const cell = grid.getByRole('rowheader'); + await expect(cell).toContainText(message.slice(0, 20)); + // The message cell and its header sit wholly inside the scrolled grid, the header over its column. + const [cellBox, gridBox, headerBox] = [ + (await cell.boundingBox())!, + (await grid.boundingBox())!, + (await grid.getByRole('columnheader', {name: /^Message /}).boundingBox())! + ]; + expect(cellBox.x).toBeGreaterThanOrEqual(gridBox.x); + expect(cellBox.x + cellBox.width).toBeLessThanOrEqual(gridBox.x + gridBox.width + 1); + expect(Math.round(headerBox.x)).toBe(Math.round(cellBox.x)); + expect(Math.round(headerBox.width)).toBe(Math.round(cellBox.width)); + // What the column still cuts, a tap discloses under the table. + await cell.tap(); + await expect(page.locator('.rp-table-detail')).toContainText(message); + }); +}); + +test('at 1440px the logs table fits its columns without scrolling', async ({page}) => { + await page.setViewportSize({width: 1440, height: 900}); + const grid = await logs(page); + await expect.poll(() => grid.evaluate(el => el.scrollWidth - el.clientWidth)).toBe(0); + for (const name of [/^Time /, /^Level /, /^Module /, /^Message /]) await expect(grid.getByRole('columnheader', {name})).toBeInViewport({ratio: 1}); +}); diff --git a/e2e/phone-tables.spec.ts b/e2e/phone-tables.spec.ts index 3ff0199a..f033c217 100644 --- a/e2e/phone-tables.spec.ts +++ b/e2e/phone-tables.spec.ts @@ -1,44 +1,57 @@ -import {expect, test} from './fixtures'; +import type {Locator} from '@playwright/test'; +import {expect, scrollTableToEnd, test} from './fixtures'; -// A table's row actions must stay reachable at 320px: lower-priority columns give way before Actions does, per the -// DataTable's drop-priority mechanism (see fitColumns in src/ui/Table.tsx). ProviderTable sits inside the Nodes page's +// A virtualised grid draws only the columns in view, so the headers are gathered while scrolling across it. +const columnNames = (grid: Locator) => + grid.evaluate(async el => { + const scroller = el.tagName === 'TABLE' ? el.parentElement! : el; + const names = new Set(); + for (let x = 0; ; x += scroller.clientWidth / 2) { + scroller.scrollLeft = x; + await new Promise(resolve => setTimeout(resolve, 100)); + for (const header of el.querySelectorAll('[role=columnheader]')) names.add(header.textContent!.trim()); + if (x >= scroller.scrollWidth - scroller.clientWidth) return [...names]; + } + }); + +// A phone keeps every column at its minimum width and scrolls the table sideways, so row actions sit at the end of the +// row rather than taking the place of other columns (src/ui/Table.tsx). ProviderTable sits inside the Nodes page's // "Nodes" tab, above the node list, so its own `.rp-table` is the first one there. -for (const [width, url, heading, actionName] of [ - [320, '/#/nodes?tab=list', 'Nodes', 'Actions'], - [360, '/#/nodes?tab=list', 'Nodes', 'Actions'], - [320, '/#/rules?tab=list', 'Rule list', 'Actions'], - [360, '/#/rules?tab=list', 'Rule list', 'Actions'] +for (const [width, url, heading, columns] of [ + [320, '/#/nodes?tab=list', 'Nodes', ['Source', 'Kind', 'Nodes', 'Usage', 'Updated', 'Auto-refresh', 'Expires', 'State', 'Actions']], + [360, '/#/nodes?tab=list', 'Nodes', ['Source', 'Kind', 'Nodes', 'Usage', 'Updated', 'Auto-refresh', 'Expires', 'State', 'Actions']], + [320, '/#/rules?tab=list', 'Rule list', ['#', 'Expression', 'Outbound', 'Where', 'Hits', 'Actions']], + [360, '/#/rules?by=client&tab=list', 'Rule list', ['#', 'Expression', 'Outbound', 'Where', 'Hits', 'Actions']] ] as const) { test.describe(`${width}px`, () => { test.use({viewport: {width, height: 800}}); - test(`${url}: the ${actionName} column stays inside the table`, async ({page}) => { + test(`${url}: every column stays and the Actions column scrolls into the table`, async ({page}) => { await page.goto(url); const panel = page.getByRole('tabpanel', {name: heading}); - const grid = panel.locator('.rp-table').first(); - // Columns fit to the container's measured width once a ResizeObserver callback runs after mount; a row - // rendering means the (slower) data fetch has already resolved well after that settles. - await expect(grid.locator('[role=row][data-key]').first()).toBeVisible(); - const actions = grid.getByRole('columnheader', {name: actionName}); - await expect(actions).toBeVisible(); - const gridBox = await grid.boundingBox(); + const table = panel.locator('.rp-table').first(); + await expect(table.locator('[role=row][data-key]').first()).toBeVisible(); + expect((await columnNames(table.locator('[role=grid]'))).sort()).toEqual([...columns].sort()); + await scrollTableToEnd(table.locator('[role=grid]')); + const actions = table.getByRole('columnheader', {name: 'Actions'}); + await expect(actions).toBeInViewport({ratio: 1}); + const tableBox = await table.boundingBox(); const actionsBox = await actions.boundingBox(); - expect(gridBox && actionsBox && actionsBox.x + actionsBox.width).toBeLessThanOrEqual(gridBox!.x + gridBox!.width + 1); + expect(actionsBox!.x + actionsBox!.width).toBeLessThanOrEqual(tableBox!.x + tableBox!.width + 1); }); }); } -// DNS cache keeps its domain, its resolved state and the delete action; the columns between them give way first. -test('the DNS cache table drops Type, Expires and Stale until before Domain, State or Delete at 320px', async ({page}) => { +// The DNS cache keeps every column on the narrowest phone and scrolls to its Delete column. +test('the DNS cache table keeps every column at 320px and scrolls to Delete', async ({page}) => { await page.setViewportSize({width: 320, height: 800}); await page.goto('/#/dns?tab=cache'); const panel = page.getByRole('tabpanel', {name: 'Cache'}); - const grid = panel.locator('.rp-table').first(); - await expect(grid.locator('[role=row][data-key]').first()).toBeVisible(); - await expect(grid.getByRole('columnheader', {name: 'Domain'})).toBeVisible(); - await expect(grid.getByRole('columnheader', {name: 'State'})).toBeVisible(); - await expect(grid.getByRole('columnheader', {name: 'Delete'})).toBeVisible(); - for (const dropped of ['Type', 'Expires', 'Stale until']) await expect(grid.getByRole('columnheader', {name: dropped})).toHaveCount(0); + const table = panel.locator('.rp-table').first(); + await expect(table.locator('[role=row][data-key]').first()).toBeVisible(); + expect((await columnNames(table.locator('[role=grid]'))).sort()).toEqual(['Delete', 'Domain', 'Expires', 'Stale until', 'State', 'Type']); + await scrollTableToEnd(table.locator('[role=grid]')); + await expect(table.getByRole('columnheader', {name: 'Delete'})).toBeInViewport({ratio: 1}); }); // A finger needs a bigger hit target on the column resizer than a mouse does, without moving the visible line at the diff --git a/e2e/phone-truncation.spec.ts b/e2e/phone-truncation.spec.ts index 8ca2fa3b..7340a453 100644 --- a/e2e/phone-truncation.spec.ts +++ b/e2e/phone-truncation.spec.ts @@ -1,13 +1,16 @@ import type {Locator, Page} from '@playwright/test'; -import {expect, fulfillStream, mockBackend, test} from './fixtures'; +import {expect, fulfillStream, mockBackend, scrollTableToEnd, test} from './fixtures'; -// At phone width the Events and Logs tables keep one text column and cut it; a pressed row discloses the whole record +// A column still cuts text wider than itself, on a phone as elsewhere; a pressed row discloses the whole record // under the table (DataTable `detail`), by pointer or by Enter and Space on the focused row. test.use({viewport: {width: 390, height: 844}, storage: {'doona-lang': 'en'}}); const cut = (cell: Locator) => cell.locator('.rp-truncate').evaluate(el => el.scrollWidth > el.clientWidth); async function disclose(page: Page, grid: Locator, text: string) { + // The text column comes last; a phone scrolls to it before the grid renders it. + await expect(grid.locator('[role=row][data-key]').first()).toBeVisible(); + await scrollTableToEnd(grid); const row = grid.getByRole('row').filter({hasText: text.slice(0, 20)}); await expect(row).toHaveCount(1); expect(await cut(row.getByRole('rowheader')), 'the message is cut in the table').toBe(true); @@ -90,18 +93,19 @@ test.describe('by touch', () => { test.use({viewport: {width: 320, height: 640}, hasTouch: true, isMobile: true, storage: {'doona-lang': 'zh-CN'}}); test('a tapped Logs row discloses its whole message', async ({page}) => { await logRow(page); - const row = page - .getByRole('grid', {name: '日志', exact: true}) - .getByRole('row') - .filter({hasText: logText.slice(0, 20)}); + const grid = page.getByRole('grid', {name: '日志', exact: true}); + await expect(grid.locator('[role=row][data-key]').first()).toBeVisible(); + await scrollTableToEnd(grid); + const row = grid.getByRole('row').filter({hasText: logText.slice(0, 20)}); await expect(row).toHaveCount(1); expect(await cut(row.getByRole('rowheader')), 'the message is cut in the table').toBe(true); const detail = page.locator('.rp-table-detail'); await expect(detail).toBeEmpty(); - await row.tap(); + // Tap the message itself: a tap on the row's middle would scroll the grid back to where the message is not drawn. + await row.getByRole('rowheader').tap(); await expect(row).toHaveAttribute('aria-selected', 'true'); await expect(detail).toContainText(logText); - await row.tap(); + await row.getByRole('rowheader').tap(); await expect(detail).toBeEmpty(); }); }); diff --git a/e2e/routes.spec.ts b/e2e/routes.spec.ts index 7fbf6614..ea9012c4 100644 --- a/e2e/routes.spec.ts +++ b/e2e/routes.spec.ts @@ -55,11 +55,17 @@ test('narrow tables retain readable columns and stop scrolling after a desktop r const table = page.locator('.rp-table'); const domain = table.getByRole('rowheader').first(); await expect(domain).toBeVisible(); - await expect.poll(() => table.evaluate(el => el.scrollWidth - el.clientWidth)).toBeGreaterThan(0); + // Once virtualised, the grid scrolls itself rather than its container. + const overflow = () => + table.evaluate(el => { + const scroller = el.querySelector(':scope > div[role=grid]') ?? el; + return scroller.scrollWidth - scroller.clientWidth; + }); + await expect.poll(overflow).toBeGreaterThan(0); expect(await domain.evaluate(el => el.getBoundingClientRect().width)).toBeGreaterThanOrEqual(160); expect(await page.evaluate(() => document.documentElement.scrollWidth)).toBe(390); await page.setViewportSize({width: 1024, height: 1400}); - await expect.poll(() => table.evaluate(el => el.scrollWidth - el.clientWidth)).toBe(0); + await expect.poll(overflow).toBe(0); expect(await domain.evaluate(el => el.getBoundingClientRect().width)).toBeGreaterThanOrEqual(160); }); diff --git a/src/features/connections/view.ts b/src/features/connections/view.ts index 3d2de547..189ddf81 100644 --- a/src/features/connections/view.ts +++ b/src/features/connections/view.ts @@ -42,7 +42,7 @@ export function connectionDetails(c: Connection, locale: string): Array<[Key, st ]; } -// `drop` orders which columns give way first when the table is narrower than the minima (see fitColumns); +// `drop` orders which columns give way first when a table wider than a phone is narrower than the minima (see fitColumns); // the target column always stays. export const columns: Array<{id: string; label: Key; minWidth: number; sortable?: boolean; align?: 'end'; drop?: number}> = [ {id: 'dst', label: 'ui.target', minWidth: 200, sortable: true}, diff --git a/src/features/events/Events.tsx b/src/features/events/Events.tsx index dbd53025..fe60ce72 100644 --- a/src/features/events/Events.tsx +++ b/src/features/events/Events.tsx @@ -39,7 +39,7 @@ export function Events() { ], [t] ); - // A phone keeps only the summary column and cuts it; a pressed row shows the whole event. + // The summary column cuts a long summary; a pressed row shows the whole event. const detail = useCallback( (event: EventRow) => ( ( = Col & {render: (row: T) => ReactNode}; @@ -199,7 +200,10 @@ export function DataTable({ // A tree fits its columns to the grid, which scrolls it, so its width excludes the scrollbar gutter. const [treeGridRef, gridWidth] = useContentWidth(); const width = tree ? gridWidth : containerWidth; - const shown = useMemo(() => fitColumns(cols, width), [cols, width]); + // Fitting a phone's width would leave one or two columns and put the rest of each row out of reach, so there every + // column keeps its minimum and the table scrolls sideways; wider screens drop columns rather than scroll. + const phone = useMediaQuery(phoneQuery); + const shown = useMemo(() => fitColumns(cols, phone ? null : width), [cols, phone, width]); // Groups count as rows for the height, the virtual row count and the reveal offset; a folded group's children do not. const flat = useMemo( () => (tree ? rows.flatMap(row => (isGroup(row) ? (tree.collapsed(row.group) ? [row] : [row, ...row.children]) : [row])) : rows), @@ -245,8 +249,10 @@ export function DataTable({ ); const table = ( sum + column.minWidth, 0)}} + // A native table overflows its container, which scrolls it. A virtualised grid scrolls itself and lays its columns + // out wider than itself; a minimum width would make the container scroll it instead, vertical scrollbar and all. + // A tree measures the grid, so a minimum width would also feed back into that measure. + style={tree || virtual ? undefined : {minWidth: shown.reduce((sum, column) => sum + column.minWidth, 0)}} ref={element => { grid.current = element; if (tree) treeGridRef.current = element;