From 41bd366fdfdffdc7121772ff571266707b7fc056 Mon Sep 17 00:00:00 2001 From: Zakk Date: Thu, 1 Oct 2026 01:16:48 +1000 Subject: [PATCH] feat(nodes): show an empty state with no subscription or node When both lists load with no subscription and no node beyond the built-in outbounds, the Nodes list gives way to the kit empty state: one sentence, Add subscription as the primary action and Paste node link beside it, so the two ways in stay reachable without the tables. --- e2e/nodes.spec.ts | 13 +++++++++++++ src/api/selectors.test.ts | 11 +++++++++++ src/api/selectors.ts | 5 +++++ src/features/nodes/Nodes.tsx | 27 ++++++++++++++++++++++++--- src/features/nodes/useNodesPage.ts | 5 +++++ src/i18n/locales/en.json | 1 + src/i18n/locales/zh-CN.json | 1 + src/i18n/locales/zh-TW.json | 1 + src/ui/styles/interaction-states.css | 5 +++++ 9 files changed, 66 insertions(+), 3 deletions(-) diff --git a/e2e/nodes.spec.ts b/e2e/nodes.spec.ts index 29f5a763..9a916dd9 100644 --- a/e2e/nodes.spec.ts +++ b/e2e/nodes.spec.ts @@ -893,3 +893,16 @@ test('an edit refused because the entry left its file says so on the next save', await apply.click(); await expect(dialog.getByRole('alert')).toContainText('This subscription is no longer in its source file'); }); + +test('with no subscription and no node the page says so and offers Add subscription', async ({page}) => { + const backend = await mockBackend(page); + backend.handlers['GET providers'] = async () => ({providers: [], next_cursor: null}); + backend.handlers['GET nodes'] = async () => ({observed_at: new Date().toISOString(), nodes: [], next_cursor: null}); + await page.goto('/#/nodes'); + const empty = page.locator('.rp-empty', {hasText: 'No subscriptions or nodes yet.'}); + await expect(empty).toBeVisible(); + await expect(page.locator('.rp-table')).toHaveCount(0); + await expect(empty.getByRole('button', {name: 'Paste node link', exact: true})).toBeVisible(); + await empty.getByRole('button', {name: 'Add subscription', exact: true}).click(); + await expect(page.getByRole('dialog', {name: 'Add subscription'})).toBeVisible(); +}); diff --git a/src/api/selectors.test.ts b/src/api/selectors.test.ts index 2b7e3d79..95c52dc8 100644 --- a/src/api/selectors.test.ts +++ b/src/api/selectors.test.ts @@ -8,6 +8,7 @@ import { logLevelLabels, logLevels, memoryTone, + noNodeSources, nodeOwner, resolveSelectedLeaf, routineGap, @@ -120,3 +121,13 @@ it('lists every labelled event kind', () => { expect(eventKinds).toEqual(Object.keys(eventKindLabels)); expect(eventKinds).toEqual(['stream.ready', 'runtime.updated', 'flow.updated', 'flow.gap', 'operation.updated', 'generation.changed']); }); + +it('counts a backend as without node sources only once both lists load empty of subscriptions and own nodes', () => { + const builtin = {protocol: 'direct'}; + expect(noNodeSources(undefined, [])).toBe(false); + expect(noNodeSources([], undefined)).toBe(false); + expect(noNodeSources([], [builtin])).toBe(true); + expect(noNodeSources([{kind: 'inline'}], [builtin])).toBe(true); + expect(noNodeSources([{kind: 'subscription'}], [])).toBe(false); + expect(noNodeSources([], [builtin, {protocol: 'vless'}])).toBe(false); +}); diff --git a/src/api/selectors.ts b/src/api/selectors.ts index 0140c819..4941c864 100644 --- a/src/api/selectors.ts +++ b/src/api/selectors.ts @@ -12,6 +12,7 @@ import type { HealthObservation, LogLevel, Node, + Provider, Runtime, RuntimeOutbounds } from './model'; @@ -97,6 +98,10 @@ export function ipLiteral(text: string): string | undefined { // nodes. The owner's id is its kind, lengthened while a real provider already uses that id. export type PseudoOwner = 'builtin' | 'unattributed'; export const pseudoOwner = (node: Pick): PseudoOwner => (isBuiltinOutbound(node.protocol) ? 'builtin' : 'unattributed'); +// Whether the backend, once both lists have loaded, has no subscription and no node beyond the built-in outbounds. +export function noNodeSources(providers: readonly Pick[] | undefined, nodes: readonly Pick[] | undefined): boolean { + return !!providers && !!nodes && !providers.some(provider => provider.kind === 'subscription') && nodes.every(node => pseudoOwner(node) === 'builtin'); +} export function pseudoOwnerId(kind: PseudoOwner, providers: ReadonlyArray<{id: string}>): string { let id: string = kind; while (providers.some(provider => provider.id === id)) id += '-'; diff --git a/src/features/nodes/Nodes.tsx b/src/features/nodes/Nodes.tsx index 308f5a5a..d306b2f1 100644 --- a/src/features/nodes/Nodes.tsx +++ b/src/features/nodes/Nodes.tsx @@ -1,5 +1,5 @@ import {useT} from '../../i18n'; -import {Button, ConfirmDialog, ErrorMessage, InlineAlert, Link, ModalDialog, StaticField, Switch, Tabs, TextField} from '../../ui/ui'; +import {Button, ConfirmDialog, Empty, ErrorMessage, InlineAlert, Link, ModalDialog, StaticField, Switch, Tabs, TextField} from '../../ui/ui'; import {NodeLatency} from './Latency'; import type {PageProps} from '../../shell/routes'; import {ProviderTable} from './ProviderTable'; @@ -15,6 +15,9 @@ export function Nodes(props: PageProps) { setTab, providerTable, nodeTable, + noSources, + addProvider, + addNode, error, reload, dialog, @@ -50,8 +53,26 @@ export function Nodes(props: PageProps) { <>

{t('nodes.note')}

- - + {noSources ? ( + + {t('nodes.noSources')} + {(addProvider || addNode) && ( + + {addProvider && ( + + )} + {addNode && } + + )} + + ) : ( + <> + + + + )} ); const content = {list, latency: }; diff --git a/src/features/nodes/useNodesPage.ts b/src/features/nodes/useNodesPage.ts index 37859b9a..7f43bbeb 100644 --- a/src/features/nodes/useNodesPage.ts +++ b/src/features/nodes/useNodesPage.ts @@ -31,6 +31,7 @@ import {useNodeTable} from './useNodeTable'; import {useDraftGuard} from '../../shell/draft'; import {errorText, noticeText, requestIdOf, type Notice} from '../../api/error'; import {href, pickTab, tabQuery, within} from '../../shell/route'; +import {noNodeSources} from '../../api/selectors'; import {openGroup} from '../shared/openGroup'; import {offered} from '../../api/capabilities'; import {nodesTabs} from './nav'; @@ -408,6 +409,10 @@ export function useNodesPage({go, query}: PageProps) { setTab: (next: string) => go('nodes', tabQuery(query, next, 'list')), providerTable, nodeTable, + // No subscription and no node yet: the list gives way to a line saying so and Add subscription. + noSources: noNodeSources(providers.data?.providers, nodes.data), + addProvider: resources?.providers.can_manage ? () => open({kind: 'provider'}) : null, + addNode: resources?.nodes.can_manage ? addNode : null, error: providers.error ?? nodes.error, reload, dialog, diff --git a/src/i18n/locales/en.json b/src/i18n/locales/en.json index 8b572f61..5e953f7a 100644 --- a/src/i18n/locales/en.json +++ b/src/i18n/locales/en.json @@ -943,6 +943,7 @@ "nodes.newGroupHelp": "Adds a group to the group section and includes {name} using a name filter. Its policy can be changed on the policies page.", "nodes.noMatch": "No matching nodes", "nodes.noProviders": "No node sources", + "nodes.noSources": "No subscriptions or nodes yet. Add a subscription to get nodes.", "nodes.node": "Node", "nodes.note": "Sources are subscriptions, files and the nodes in the configuration. When the backend allows it, subscriptions and share links are added here; changes are written to the main configuration and reloaded.", "nodes.of": "Nodes of {name}", diff --git a/src/i18n/locales/zh-CN.json b/src/i18n/locales/zh-CN.json index a6191084..59427a6a 100644 --- a/src/i18n/locales/zh-CN.json +++ b/src/i18n/locales/zh-CN.json @@ -784,6 +784,7 @@ "nodes.newGroupHelp": "在 group 区段新建组,使用 name 筛选纳入 {name};策略可在策略页面修改。", "nodes.noMatch": "没有匹配的节点", "nodes.noProviders": "暂无节点来源", + "nodes.noSources": "尚无订阅或节点。添加订阅后即可获取节点。", "nodes.node": "节点", "nodes.note": "节点来源包括订阅、文件与配置内的节点。后端支持时,可在此添加订阅或粘贴节点链接;更改会写入主配置并重载。", "nodes.of": "{name} 的节点", diff --git a/src/i18n/locales/zh-TW.json b/src/i18n/locales/zh-TW.json index 0fec51fd..35526d3c 100644 --- a/src/i18n/locales/zh-TW.json +++ b/src/i18n/locales/zh-TW.json @@ -784,6 +784,7 @@ "nodes.newGroupHelp": "在 group 區段新增群組,使用 name 篩選納入 {name};策略可於策略頁面修改。", "nodes.noMatch": "沒有符合的節點", "nodes.noProviders": "沒有節點來源", + "nodes.noSources": "尚無訂閱或節點。新增訂閱後即可取得節點。", "nodes.node": "節點", "nodes.note": "節點來源包括訂閱、檔案與組態內的節點。後端支援時,可在此新增訂閱或貼上節點連結;變更會寫入主組態並重載。", "nodes.of": "{name} 的節點", diff --git a/src/ui/styles/interaction-states.css b/src/ui/styles/interaction-states.css index 9e540ed6..3d151671 100644 --- a/src/ui/styles/interaction-states.css +++ b/src/ui/styles/interaction-states.css @@ -124,6 +124,11 @@ margin: 16px auto 0; width: max-content; } +/* Two actions under the message share a centred row. */ +.rp-empty > .rp-cluster { + justify-content: center; + margin-top: 16px; +} .rp-btn[data-pending] { cursor: progress; }