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

+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 += '-';