From fe54cf4e174bdc39bb9277cc2d39560dbc4f3772 Mon Sep 17 00:00:00 2001 From: Zakk Date: Tue, 29 Sep 2026 16:30:44 +1000 Subject: [PATCH] feat(connections): open the traffic tab first again Traffic gives the overview before the list, so it is again the first tab and the default for a bare #/connections. This reverts fb48fb66; tab=list and tab=traffic links keep working. --- e2e/charts.spec.ts | 17 ++++++------ e2e/connections.spec.ts | 22 ++------------- e2e/keyboard.spec.ts | 4 ++- e2e/phone-busiest.spec.ts | 18 ++++++------- e2e/routes.spec.ts | 3 ++- e2e/search.spec.ts | 2 +- src/features/connections/Connections.tsx | 4 +-- .../connections/useConnectionsPage.ts | 27 ++++++++++++------- 8 files changed, 45 insertions(+), 52 deletions(-) diff --git a/e2e/charts.spec.ts b/e2e/charts.spec.ts index a8f2c086..bda87205 100644 --- a/e2e/charts.spec.ts +++ b/e2e/charts.spec.ts @@ -51,22 +51,23 @@ test('node latency groups two ways, shortens long groups and shows a tip on hove await expect(plot.getByRole('region', {name: 'shadowsocks'})).toBeVisible(); }); -test('a traffic point opens its connection in the list', async ({page}) => { - await page.goto('/#/connections?tab=traffic'); +test('traffic is the first connections tab, and a point opens its connection in the list', async ({page}) => { + await page.goto('/#/connections'); await expect(page.getByRole('tab', {name: 'Traffic'})).toHaveAttribute('aria-selected', 'true'); await expect(fact(page, 'Heaviest connection').locator('.rp-big')).toHaveText('cdn.bilibili.com'); await expect(fact(page, 'Heaviest connection').locator('.rp-fact-caption')).toHaveText('direct'); await expect(fact(page, 'Download')).toHaveText('1.2 GB'); await expect(page.getByText(/^Connections: \d+(?:, without byte totals: \d+)?$/)).toBeVisible(); await page.locator('.rp-scatter circle').first().click(); - await expect(page).toHaveURL(/#\/connections\?id=[^&]+$/); + await expect(page).toHaveURL(/[?&]tab=list/); + await expect(page).toHaveURL(/[?&]id=/); await expect(page.getByRole('tab', {name: 'Connections'})).toHaveAttribute('aria-selected', 'true'); }); const nodeLatency = (page: import('@playwright/test').Page) => page.getByRole('region', {name: 'Node latency', exact: true}); test('the traffic tab plots every node latency and marks the nodes current connections use', async ({page}) => { - await page.goto('/#/connections?tab=traffic'); + await page.goto('/#/connections'); const card = nodeLatency(page); await expect(card.getByText(/^Nodes with a latency: \d+, without: \d+$/)).toBeVisible(); await expect(card.getByText(/^All nodes, P50: \d+ ms, P90: \d+ ms$/)).toBeVisible(); @@ -91,7 +92,7 @@ test('the weighted median counts the connections whose node has no latency', asy const failed = (node: (typeof list.nodes)[number]) => ({...node, health: node.health.map(h => ({...h, state: 'unavailable' as const, latency_ms: null}))}); return {...list, nodes: list.nodes.map(node => (node.id === 'hk-02' ? failed(node) : node))}; }; - await page.goto('/#/connections?tab=traffic'); + await page.goto('/#/connections'); await expect(nodeLatency(page).getByText(/^Nodes in use, weighted by connections, P50: \d+ ms, connections without a latency: [1-9]\d*$/)).toBeVisible(); }); @@ -101,7 +102,7 @@ test('without connection chains the latency card plots every node alike', async const list = await backend.api.connections({detail: 'full', limit: 1000}); return {...list, tcp: list.tcp.map(row => ({...row, chain: []})), udp: list.udp.map(row => ({...row, chain: []}))}; }; - await page.goto('/#/connections?tab=traffic'); + await page.goto('/#/connections'); const card = nodeLatency(page); await expect(card.getByText(/^All nodes, P50: \d+ ms, P90: \d+ ms$/)).toBeVisible(); await expect(card.getByText(/weighted/)).toHaveCount(0); @@ -116,7 +117,7 @@ test('the latency card waits for a latency, and stays out without health samples return {...list, nodes: list.nodes.map(node => ({...node, ...health(node)}))}; }; backend.handlers['GET nodes'] = () => nodes(node => ({health: node.health.map(h => ({...(h as object), state: 'unavailable', latency_ms: null}))})); - await page.goto('/#/connections?tab=traffic'); + await page.goto('/#/connections'); await expect(nodeLatency(page).getByText('No node has a latency sample yet.', {exact: true})).toBeVisible(); await expect(nodeLatency(page).locator('.rp-swarm')).toHaveCount(0); for (const health of [() => ({health: []}), () => ({health: undefined})]) { @@ -141,7 +142,7 @@ test('a failed node read keeps the latency card with the reason and a retry', as if (fail) throw new ApiError(500, 'internal', 'Node list failed', null, null, null); return backend.api.nodes({limit: 1000}); }; - await page.goto('/#/connections?tab=traffic'); + await page.goto('/#/connections'); await expect(page.locator('.rp-scatter')).toBeVisible(); const alert = nodeLatency(page).getByRole('alert'); await expect(alert).toBeVisible(); diff --git a/e2e/connections.spec.ts b/e2e/connections.spec.ts index 303e7bed..c028a04b 100644 --- a/e2e/connections.spec.ts +++ b/e2e/connections.spec.ts @@ -393,7 +393,7 @@ test('closing a connection removes it from the list and clears the selection', a await expect(panel.getByRole('heading', {name: 'api.telegram.org'})).toBeVisible(); await panel.getByRole('button', {name: 'Close connection', exact: true}).click(); await expect(page.locator('.rp-toast.positive')).toContainText('Closed api.telegram.org'); - await expect(page).toHaveURL(/#\/connections$/); + await expect(page).toHaveURL(/#\/connections\?tab=list$/); await expect(page.locator('.rp-table [data-key="c-0001"]')).toHaveCount(0); // A kernel-forwarded connection has no userspace transport to cancel, so Close says why before it is pressed. await page.goto('/#/connections?id=c-0002'); @@ -646,7 +646,7 @@ test('clearing the filter that opened the table keeps the table open', async ({p await page.goto('/#/connections?q=no-such-connection'); await expect(page.getByRole('grid').first()).toBeVisible(); await page.getByRole('button', {name: 'Clear filters', exact: true}).first().click(); - await expect(page).toHaveURL(/#\/connections$/); + await expect(page).toHaveURL(/#\/connections\?tab=list$/); await expect(page.getByRole('grid').first()).toBeVisible(); }); @@ -692,21 +692,3 @@ test.describe('with motion', () => { expect(running).toBe(0); }); }); - -test('the connection list is the first tab and opens by default, and tab links keep their tab', async ({page}) => { - await page.goto('/#/connections'); - const tabs = page.getByRole('tablist', {name: 'Connections', exact: true}).getByRole('tab'); - await expect(tabs).toHaveText(['Connections', 'Traffic']); - await expect(page.getByRole('tab', {name: 'Connections', exact: true})).toHaveAttribute('aria-selected', 'true'); - await page.getByRole('tab', {name: 'Traffic', exact: true}).click(); - await expect(page).toHaveURL(/#\/connections\?tab=traffic$/); - await page.getByRole('tab', {name: 'Connections', exact: true}).click(); - await expect(page).toHaveURL(/#\/connections$/); - for (const [link, tab] of [ - ['tab=traffic', 'Traffic'], - ['tab=list', 'Connections'] - ] as const) { - await page.goto(`/#/connections?${link}`); - await expect(page.getByRole('tab', {name: tab, exact: true})).toHaveAttribute('aria-selected', 'true'); - } -}); diff --git a/e2e/keyboard.spec.ts b/e2e/keyboard.spec.ts index a8b4007d..4d55186f 100644 --- a/e2e/keyboard.spec.ts +++ b/e2e/keyboard.spec.ts @@ -40,11 +40,13 @@ test('shortcut help and page sequences respect focus and the sequence deadline', await page.keyboard.press('g'); await page.keyboard.press('c'); await expect(page).toHaveURL(/#\/connections$/); + // The shortcut opens the traffic tab; the filter lives in the list. + await page.getByRole('tab', {name: 'Connections', exact: true}).click(); const input = page.getByRole('searchbox', {name: 'Filter'}); await input.focus(); await page.keyboard.type('g a?'); await expect(input).toHaveValue('g a?'); - await expect(page).toHaveURL(/#\/connections$/); + await expect(page).toHaveURL(/#\/connections\?tab=list$/); await expect(help).toBeHidden(); }); diff --git a/e2e/phone-busiest.spec.ts b/e2e/phone-busiest.spec.ts index a0ff262c..d8fcc1b3 100644 --- a/e2e/phone-busiest.spec.ts +++ b/e2e/phone-busiest.spec.ts @@ -46,7 +46,7 @@ test.describe('390px', () => { test.use({viewport: {width: 390, height: 844}, hasTouch: true, isMobile: true}); test('the busiest connection takes the first row whole, download and upload share the second', async ({page}) => { - await page.goto('/#/connections?tab=traffic'); + await page.goto('/#/connections'); const busiest = tile(page, 'Heaviest connection'); const down = tile(page, 'Download'); const up = tile(page, 'Upload'); @@ -71,7 +71,7 @@ test.describe('390px', () => { test('a host too long for the row loses its start, keeps its end and shows whole on a tap', async ({page}) => { await longHost(page); - await page.goto('/#/connections?tab=traffic'); + await page.goto('/#/connections'); const value = tile(page, 'Heaviest connection').locator('.rp-big'); await expect(value).toHaveText(long); await expect(value).toHaveAttribute('data-tip', ''); @@ -85,7 +85,7 @@ test.describe('390px', () => { test('a hover on a cut host shows it whole', async ({page}) => { await longHost(page); - await page.goto('/#/connections?tab=traffic'); + await page.goto('/#/connections'); const value = tile(page, 'Heaviest connection').locator('.rp-big'); await expect(value).toHaveAttribute('data-tip', ''); await expect(async () => { @@ -101,7 +101,7 @@ test.describe('390px', () => { test.use({storage: {'doona-lang': 'en', 'doona-mirror': 'on'}}); test('the host sits at the start, on the right', async ({page}) => { - await page.goto('/#/connections?tab=traffic'); + await page.goto('/#/connections'); await expect(page.locator('html')).toHaveAttribute('dir', 'rtl'); const busiest = tile(page, 'Heaviest connection'); await expect(busiest.locator('.rp-big')).toHaveText('cdn.bilibili.com'); @@ -112,7 +112,7 @@ test.describe('390px', () => { test('a long host still loses its start, not its end', async ({page}) => { await longHost(page); - await page.goto('/#/connections?tab=traffic'); + await page.goto('/#/connections'); const value = tile(page, 'Heaviest connection').locator('.rp-big'); await expect(value).toHaveAttribute('data-tip', ''); await expect.poll(() => edges(value)).toEqual({cut: true, first: false, last: true}); @@ -124,7 +124,7 @@ test.describe('1440px', () => { test.use({viewport: {width: 1440, height: 900}}); test('the three tiles share one row with the same values, the busiest taking two shares', async ({page}) => { - await page.goto('/#/connections?tab=traffic'); + await page.goto('/#/connections'); const busiest = tile(page, 'Heaviest connection'); await expect(busiest.locator('.rp-big')).toHaveText('cdn.bilibili.com'); await expect(busiest.locator('.rp-big')).not.toHaveAttribute('data-tip'); @@ -140,7 +140,7 @@ test.describe('1440px', () => { test('a long host loses its start and keeps its end, as on a phone', async ({page}) => { await longHost(page); - await page.goto('/#/connections?tab=traffic'); + await page.goto('/#/connections'); const value = tile(page, 'Heaviest connection').locator('.rp-big'); await expect(value).toHaveText(long); await expect(value).toHaveAttribute('data-tip', ''); @@ -153,7 +153,7 @@ test.describe('740px', () => { test.use({viewport: {width: 740, height: 900}}); test('the busiest host fits its tile uncut', async ({page}) => { - await page.goto('/#/connections?tab=traffic'); + await page.goto('/#/connections'); const value = tile(page, 'Heaviest connection').locator('.rp-big'); await expect(value).toHaveText('cdn.bilibili.com'); expect(await value.evaluate(el => el.scrollWidth <= el.clientWidth)).toBe(true); @@ -161,7 +161,7 @@ test.describe('740px', () => { test('a host too long for two shares loses its start, keeps its end and shows whole on focus', async ({page}) => { await longHost(page); - await page.goto('/#/connections?tab=traffic'); + await page.goto('/#/connections'); const value = tile(page, 'Heaviest connection').locator('.rp-big'); await expect(value).toHaveText(long); await expect(value).toHaveAttribute('data-tip', ''); diff --git a/e2e/routes.spec.ts b/e2e/routes.spec.ts index cda28905..ea9012c4 100644 --- a/e2e/routes.spec.ts +++ b/e2e/routes.spec.ts @@ -5,7 +5,8 @@ for (const width of [1024, 1280, 1440]) { test(`desktop tables fit their scrollports at ${width}px`, async ({page}) => { await page.setViewportSize({width, height: 1400}); for (const route of ['dns', 'rules', 'connections', 'events', 'overview']) { - await page.goto(`/#/${route}`); + // The connections table sits behind the traffic tab. + await page.goto(`/#/${route}${route === 'connections' ? '?tab=list' : ''}`); if (!(await offered(page, route))) continue; await expect(page.locator('.rp-content > .rp-page')).toBeVisible(); await expect(page.locator('.rp-content .rp-empty[role=status]')).toHaveCount(0); diff --git a/e2e/search.spec.ts b/e2e/search.spec.ts index 3eded87c..fe1b64ec 100644 --- a/e2e/search.spec.ts +++ b/e2e/search.spec.ts @@ -103,7 +103,7 @@ test('search respects destination capabilities, preserves loose-node ownership a await expect(dialog.getByRole('status')).toContainText('truncated'); await dialog.getByRole('button', {name: 'Connections', exact: true}).click(); await expect(page).toHaveURL(/#\/connections$/); - await expect(page.getByRole('tab', {name: 'Connections', exact: true})).toHaveAttribute('aria-selected', 'true'); + await expect(page.getByRole('tab', {name: 'Traffic', exact: true})).toHaveAttribute('aria-selected', 'true'); }); test('search results are reached with arrow keys while the field keeps focus', async ({page}) => { diff --git a/src/features/connections/Connections.tsx b/src/features/connections/Connections.tsx index 3f0633cd..ac90601a 100644 --- a/src/features/connections/Connections.tsx +++ b/src/features/connections/Connections.tsx @@ -155,7 +155,6 @@ export function Connections(props: PageProps) { value={vm.tab} onChange={vm.setTab} items={[ - {id: 'list', label: t('conn.tab.list'), content: list}, { id: 'traffic', label: t('conn.tab.traffic'), @@ -170,7 +169,8 @@ export function Connections(props: PageProps) { onSelect={vm.openInList} /> ) - } + }, + {id: 'list', label: t('conn.tab.list'), content: list} ]} /> diff --git a/src/features/connections/useConnectionsPage.ts b/src/features/connections/useConnectionsPage.ts index 1f832302..da4b4888 100644 --- a/src/features/connections/useConnectionsPage.ts +++ b/src/features/connections/useConnectionsPage.ts @@ -30,8 +30,14 @@ import {offered} from '../../api/capabilities'; import {pathLatency} from './latency'; import {useConnectionRule} from './useConnectionRule'; -// The connection list is the first tab and the default, so a link with no tab, or with a filter or selection, opens it. -const connectionTabs = ['list', 'traffic'] as const; +const connectionTabs = ['traffic', 'list'] as const; +// The traffic chart comes first; a link into the table (a connection, a source, a filter) opens the table. +const connectionsFallback = (query: string) => + ['id', 'src', 'network', 'out', 'rule', 'q'].some(key => new URLSearchParams(query).has(key)) ? 'list' : 'traffic'; +// While the link decides the tab, a change within the page writes it, so clearing the filter or selection that opened +// the table keeps the table. +const stay = (query: string, patch: Record) => + within(query, connectionsFallback(query) === 'list' ? {tab: pickTab(query, connectionTabs, 'list'), ...patch} : patch); export function useConnectionsPage({go, query}: PageProps) { const t = useT(); @@ -64,7 +70,7 @@ export function useConnectionsPage({go, query}: PageProps) { const network = q.get('network') ?? 'all'; const out = q.get('out') ?? 'all'; const rule = q.get('rule') ?? 'all'; - const setFilter = (key: 'network' | 'out' | 'rule', value: string) => go('connections', within(query, {[key]: value === 'all' ? null : value})); + const setFilter = (key: 'network' | 'out' | 'rule', value: string) => go('connections', stay(query, {[key]: value === 'all' ? null : value})); const sel = q.get('id'); const [confirmed, setConfirmed] = useState(null); useLinked(q.get('q'), value => setText(value ?? '')); @@ -74,7 +80,7 @@ export function useConnectionsPage({go, query}: PageProps) { useEffect(() => { latest.current = query; }); - const select = (id: string | null) => go('connections', within(latest.current, {id})); + const select = (id: string | null) => go('connections', stay(latest.current, {id})); // Filtering follows typing at React's pace, not a fixed delay, so an export or close right after typing sees it. const settledText = useDeferredValue(text); const src = ipLiteral(q.get('src') ?? ''); @@ -155,7 +161,7 @@ export function useConnectionsPage({go, query}: PageProps) { const picked = readTag(String(key), ['src', 'rule'] as const); if (picked?.kind === 'src') { setText(''); - go('connections', within(query, {src: !picked.value || src === picked.value ? null : picked.value, q: null})); + go('connections', stay(query, {src: !picked.value || src === picked.value ? null : picked.value, q: null})); } else if (picked?.kind === 'rule') setFilter('rule', rule === picked.value ? 'all' : picked.value); }; const menu = filterMenu(lists, {network, out, src, rule}, t); @@ -167,11 +173,12 @@ export function useConnectionsPage({go, query}: PageProps) { sections: submenu.sections.map(section => ({...section, onChange: pickFor[filter]})) })) }; - const openInList = useCallback((id: string) => go('connections', within(query, {tab: null, id})), [go, query]); + const fallback = connectionsFallback(query); + const openInList = useCallback((id: string) => go('connections', within(query, {tab: 'list', id})), [go, query]); return { ...model, - tab: pickTab(query, connectionTabs, 'list'), - setTab: (next: string) => go('connections', tabQuery(query, next, 'list')), + tab: pickTab(query, connectionTabs, fallback), + setTab: (next: string) => go('connections', tabQuery(query, next, fallback === 'traffic' ? fallback : null)), openInList, view, updateView, @@ -208,7 +215,7 @@ export function useConnectionsPage({go, query}: PageProps) { filtered: network !== 'all' || out !== 'all' || rule !== 'all' || !!src || text.trim() !== '', clear: () => { setText(''); - go('connections', within(query, {network: null, out: null, rule: null, q: null, src: null})); + go('connections', stay(query, {network: null, out: null, rule: null, q: null, src: null})); }, error: resource.error, retry: resource.refetch, @@ -257,7 +264,7 @@ export function useConnectionsPage({go, query}: PageProps) { onlyClient: () => { if (model.detail?.source) { setText(''); - go('connections', within(query, {src: model.detail.source, q: null})); + go('connections', stay(query, {src: model.detail.source, q: null})); } }, canExport: shown.length > 0,