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.
This commit is contained in:
Zakk committed 2026-10-01 03:19:38 +10:00
1 parent 1aca313732
commit 41bd366fdf
9 files changed
+66 -3

No files matched your search

+13
View File
@@ -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();
});
+11
View File
@@ -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);
});
+5
View File
@@ -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<Node, 'protocol'>): 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<Provider, 'kind'>[] | undefined, nodes: readonly Pick<Node, 'protocol'>[] | 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 += '-';
+24 -3
View File
@@ -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) {
<>
<p className="rp-note">{t('nodes.note')}</p>
<ErrorMessage error={error} onRetry={reload} />
<ProviderTable model={providerTable} />
<NodeTable model={nodeTable} />
{noSources ? (
<Empty>
{t('nodes.noSources')}
{(addProvider || addNode) && (
<span className="rp-cluster">
{addProvider && (
<Button accent onPress={addProvider}>
{t('nodes.addProvider')}
</Button>
)}
{addNode && <Button onPress={addNode}>{t('nodes.addNode')}</Button>}
</span>
)}
</Empty>
) : (
<>
<ProviderTable model={providerTable} />
<NodeTable model={nodeTable} />
</>
)}
</>
);
const content = {list, latency: <NodeLatency />};
+5
View File
@@ -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,
+1
View File
@@ -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}",
+1
View File
@@ -784,6 +784,7 @@
"nodes.newGroupHelp": "在 group 区段新建组,使用 name 筛选纳入 {name};策略可在策略页面修改。",
"nodes.noMatch": "没有匹配的节点",
"nodes.noProviders": "暂无节点来源",
"nodes.noSources": "尚无订阅或节点。添加订阅后即可获取节点。",
"nodes.node": "节点",
"nodes.note": "节点来源包括订阅、文件与配置内的节点。后端支持时,可在此添加订阅或粘贴节点链接;更改会写入主配置并重载。",
"nodes.of": "{name} 的节点",
+1
View File
@@ -784,6 +784,7 @@
"nodes.newGroupHelp": "在 group 區段新增群組,使用 name 篩選納入 {name};策略可於策略頁面修改。",
"nodes.noMatch": "沒有符合的節點",
"nodes.noProviders": "沒有節點來源",
"nodes.noSources": "尚無訂閱或節點。新增訂閱後即可取得節點。",
"nodes.node": "節點",
"nodes.note": "節點來源包括訂閱、檔案與組態內的節點。後端支援時,可在此新增訂閱或貼上節點連結;變更會寫入主組態並重載。",
"nodes.of": "{name} 的節點",
+5
View File
@@ -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;
}