Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

v6(settings): phase 7 — ConnectionsTable sources from the unified aggregator

rcourtmanbc2cf8d4000b
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
index 918b72044b..696849b94c 100644
--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
@@ -343,7 +343,24 @@ an add-only capacity posture.
card, configured nodes table, node-modal stack; TrueNAS/VMware
connection list with headers and row actions) into the credential
slot, because that previously showed the ledger-of-other-systems in
- the middle of entering one system's credentials.
+ the middle of entering one system's credentials. The configured
+ connections table reads exclusively from the unified aggregator: the
+ `ConnectionsTable` rows are produced by
+ `frontend-modern/src/components/Settings/useConnectionsLedger.ts`,
+ which polls `GET /api/connections` and maps the aggregator-derived
+ state (active/paused/unauthorized/unreachable/stale/pending) and
+ active scope keys into the table's display. `InfrastructureWorkspace`
+ must not reconstruct per-type health, scope, or last-seen columns
+ from `useInfrastructureReportingState` for configured connection
+ rows; the legacy reporting-state path is retained only for
+ monitoring-stopped inventory rows pending phase 9 cleanup. Drill-in
+ from a unified row opens
+ `frontend-modern/src/components/Settings/ConnectionDetailDrawer.tsx`,
+ which renders the aggregator fields directly (type, address, state,
+ state reason, enabled flag, surfaces with active scope, last seen,
+ last error) rather than the legacy `InfrastructureActiveRowDetails`
+ surface-breakdown drawer; the active-row drawer is no longer mounted
+ by the workspace for unified rows.
## Forbidden Paths
diff --git a/docs/release-control/v6/internal/subsystems/frontend-primitives.md b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
index de67630321..b116ec416c 100644
--- a/docs/release-control/v6/internal/subsystems/frontend-primitives.md
+++ b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
@@ -255,6 +255,19 @@ work extends shared components instead of creating new local variants.
editor shell — no connection list, no row actions, no surrounding
panel chrome. Showing a ledger of other systems inside the credential
slot is exactly the ledger-inside-editor drift this contract forbids.
+ The configured-connections ledger itself must render exclusively from
+ the aggregator. `InfrastructureWorkspace.tsx` composes the default
+ table rows from
+ `frontend-modern/src/components/Settings/useConnectionsLedger.ts`
+ (polling `GET /api/connections`) and the unified row click opens
+ `frontend-modern/src/components/Settings/ConnectionDetailDrawer.tsx`,
+ which reads the aggregator fields directly. The workspace must not
+ reconstruct the table's state, coverage, or last-seen columns from
+ `useInfrastructureReportingState` for configured connection rows, and
+ the legacy `InfrastructureActiveRowDetails` drawer must not be
+ mounted for those rows. Monitoring-stopped inventory still routes to
+ `InfrastructureIgnoredRowDetails` pending phase 9 cleanup, but that
+ fallback must not be extended to cover configured connections.
6. Keep Proxmox deep-link route selection on the shared settings-navigation boundary. `frontend-modern/src/components/Settings/settingsNavigationModel.ts` and `frontend-modern/src/components/Settings/useSettingsNavigation.ts` must treat the canonical PBS and PMG Proxmox deep links as agent-selection authority even though those URLs resolve to the shared `infrastructure-operations` tab. Reloading or remounting on a PBS or PMG deep link must not silently fall back to the PVE selector state.
7. Keep shared storage feature presenters on canonical platform truth. When reusable storage presenters under `frontend-modern/src/features/storageBackups/` classify canonical resources for the shared storage route, API-backed virtualization datastores such as VMware must stay inventory-only datastores instead of inheriting PBS-specific backup-repository or protected-target copy from older fallback branches.
8. Keep shared source/platform vocabulary on the governed manifest boundary. `frontend-modern/src/utils/platformSupportManifest.generated.ts` must be the tracked frontend projection of `docs/release-control/v6/internal/PLATFORM_SUPPORT_MANIFEST.json`, `frontend-modern/src/utils/platformSupportManifest.ts`, `frontend-modern/src/utils/sourcePlatforms.ts`, and `frontend-modern/src/utils/sourcePlatformOptions.ts` must consume that generated projection instead of embedding divergent future-label lists, setup/onboarding path allowlists, or presentation-only guesses, and `frontend-modern/scripts/canonical-platform-audit.mjs` must fail when the generated projection drifts from the governed manifest.
diff --git a/frontend-modern/src/components/Settings/ConnectionDetailDrawer.tsx b/frontend-modern/src/components/Settings/ConnectionDetailDrawer.tsx
new file mode 100644
index 0000000000..18b0e7d525
--- /dev/null
+++ b/frontend-modern/src/components/Settings/ConnectionDetailDrawer.tsx
@@ -0,0 +1,164 @@
+import { Component, For, Show } from 'solid-js';
+import { Dialog } from '@/components/shared/Dialog';
+import type { Connection } from '@/api/connections';
+import { CONNECTION_TYPE_LABELS, surfaceLabel } from './useConnectionsLedger';
+
+interface ConnectionDetailDrawerProps {
+ connection: () => Connection | undefined;
+ onClose: () => void;
+}
+
+const formatLastSeen = (value: string | null): string => {
+ if (!value) return 'No activity yet';
+ const ts = Date.parse(value);
+ if (Number.isNaN(ts)) return value;
+ return new Date(ts).toLocaleString();
+};
+
+const formatErrorAt = (value: string): string => {
+ const ts = Date.parse(value);
+ if (Number.isNaN(ts)) return value;
+ return new Date(ts).toLocaleString();
+};
+
+export const ConnectionDetailDrawer: Component<ConnectionDetailDrawerProps> = (props) => {
+ return (
+ <Dialog
+ isOpen={Boolean(props.connection())}
+ onClose={props.onClose}
+ layout="drawer-right"
+ panelClass="max-w-[560px]"
+ ariaLabel="Connection details"
+ >
+ <Show when={props.connection()}>
+ {(accessor) => {
+ const connection = accessor();
+ const typeLabel = CONNECTION_TYPE_LABELS[connection.type] ?? connection.type;
+ const activeScopeKeys = Object.keys(connection.scope ?? {}).filter(
+ (key) => connection.scope?.[key],
+ );
+ const inactiveScopeKeys = (connection.surfaces ?? []).filter(
+ (key) => !activeScopeKeys.includes(key),
+ );
+ return (
+ <div class="flex h-full flex-col">
+ <div class="flex items-start justify-between gap-4 border-b border-border px-5 py-4">
+ <div class="min-w-0 space-y-1">
+ <div class="break-words text-base font-semibold text-base-content">
+ {connection.name || connection.address || connection.id}
+ </div>
+ <div class="text-xs text-muted">{typeLabel}</div>
+ </div>
+ <button
+ type="button"
+ onClick={props.onClose}
+ class="inline-flex items-center rounded-md border border-border px-2.5 py-1 text-xs font-medium text-base-content transition-colors hover:bg-surface-hover"
+ >
+ Close
+ </button>
+ </div>
+
+ <div class="flex-1 overflow-y-auto px-5 py-4">
+ <dl class="space-y-4 text-sm">
+ <div>
+ <dt class="text-xs font-semibold uppercase tracking-wide text-muted">
+ Address
+ </dt>
+ <dd class="mt-1 break-all text-base-content">{connection.address || '—'}</dd>
+ </div>
+
+ <div>
+ <dt class="text-xs font-semibold uppercase tracking-wide text-muted">State</dt>
+ <dd class="mt-1 text-base-content">
+ <div class="font-medium capitalize">{connection.state}</div>
+ <Show when={connection.stateReason}>
+ <div class="mt-0.5 text-xs text-muted">{connection.stateReason}</div>
+ </Show>
+ </dd>
+ </div>
+
+ <div>
+ <dt class="text-xs font-semibold uppercase tracking-wide text-muted">
+ Enabled
+ </dt>
+ <dd class="mt-1 text-base-content">
+ {connection.enabled ? 'Yes' : 'No (paused)'}
+ </dd>
+ </div>
+
+ <div>
+ <dt class="text-xs font-semibold uppercase tracking-wide text-muted">
+ Surfaces collected
+ </dt>
+ <dd class="mt-1 flex flex-wrap gap-1.5">
+ <Show
+ when={activeScopeKeys.length > 0}
+ fallback={
+ <span class="text-xs text-muted">
+ No surfaces currently enabled for collection.
+ </span>
+ }
+ >
+ <For each={activeScopeKeys}>
+ {(key) => (
+ <span class="inline-flex items-center rounded-full border border-border bg-surface px-2 py-0.5 text-xs font-medium text-base-content">
+ {surfaceLabel(key)}
+ </span>
+ )}
+ </For>
+ </Show>
+ </dd>
+ <Show when={inactiveScopeKeys.length > 0}>
+ <dd class="mt-2 flex flex-wrap gap-1.5">
+ <For each={inactiveScopeKeys}>
+ {(key) => (
+ <span class="inline-flex items-center rounded-full border border-dashed border-border bg-surface-alt px-2 py-0.5 text-xs font-medium text-muted">
+ {surfaceLabel(key)} (paused)
+ </span>
+ )}
+ </For>
+ </dd>
+ </Show>
+ </div>
+
+ <div>
+ <dt class="text-xs font-semibold uppercase tracking-wide text-muted">
+ Last activity
+ </dt>
+ <dd class="mt-1 text-base-content">{formatLastSeen(connection.lastSeen)}</dd>
+ </div>
+
+ <Show when={connection.lastError}>
+ {(errorAccessor) => {
+ const err = errorAccessor();
+ return (
+ <div>
+ <dt class="text-xs font-semibold uppercase tracking-wide text-muted">
+ Last error
+ </dt>
+ <dd class="mt-1 space-y-1">
+ <div class="break-words text-rose-700 dark:text-rose-300">
+ {err.message}
+ </div>
+ <div class="text-xs text-muted">{formatErrorAt(err.at)}</div>
+ </dd>
+ </div>
+ );
+ }}
+ </Show>
+
+ <div>
+ <dt class="text-xs font-semibold uppercase tracking-wide text-muted">
+ Source
+ </dt>
+ <dd class="mt-1 text-base-content capitalize">{connection.source}</dd>
+ </div>
+ </dl>
+ </div>
+ </div>
+ );
+ }}
+ </Show>
+ </Dialog>
+ );
+};
diff --git a/frontend-modern/src/components/Settings/InfrastructureWorkspace.tsx b/frontend-modern/src/components/Settings/InfrastructureWorkspace.tsx
index c9d8908788..cbdba36b20 100644
--- a/frontend-modern/src/components/Settings/InfrastructureWorkspace.tsx
+++ b/frontend-modern/src/components/Settings/InfrastructureWorkspace.tsx
@@ -3,6 +3,7 @@ import { useLocation, useNavigate } from '@solidjs/router';
import { Dialog } from '@/components/shared/Dialog';
import { presentationPolicyIsReadOnly } from '@/stores/sessionPresentationPolicy';
import { AgentProfilesPanel } from './AgentProfilesPanel';
+import { ConnectionDetailDrawer } from './ConnectionDetailDrawer';
import { ConnectionsTable, type ConnectionsTableHeaderAction } from './ConnectionsTable';
import {
buildInfrastructureSystemRows,
@@ -14,7 +15,6 @@ import { NodeCredentialSlot } from './ConnectionEditor/CredentialSlots/NodeCrede
import { TrueNASCredentialSlot } from './ConnectionEditor/CredentialSlots/TrueNASCredentialSlot';
import { VMwareCredentialSlot } from './ConnectionEditor/CredentialSlots/VMwareCredentialSlot';
import type { ConnectionType } from '@/api/connections';
-import { InfrastructureActiveRowDetails } from './InfrastructureActiveRowDetails';
import { InfrastructureInstallerSection } from './InfrastructureInstallerSection';
import { InfrastructureIgnoredRowDetails } from './InfrastructureIgnoredRowDetails';
import { InfrastructureStopMonitoringDialog } from './InfrastructureStopMonitoringDialog';
@@ -24,6 +24,7 @@ import {
type InfrastructureAddStep,
} from './infrastructureWorkspaceModel';
import type { InfrastructurePlatformSettingsProps } from './proxmoxSettingsModel';
+import { useConnectionsLedger } from './useConnectionsLedger';
import {
InfrastructureOperationsStateProvider,
useInfrastructureOperationsContext,
@@ -44,11 +45,17 @@ const InfrastructureWorkspaceContent: Component<InfrastructureWorkspaceProps> =
const navigate = useNavigate();
const location = useLocation();
const state = useInfrastructureOperationsContext();
+ const ledger = useConnectionsLedger();
const [addMode, setAddMode] = createSignal(false);
const [initialAddType, setInitialAddType] = createSignal<ConnectionType | null>(null);
const [showAgentProfiles, setShowAgentProfiles] = createSignal(false);
+ const [selectedConnectionId, setSelectedConnectionId] = createSignal<string | null>(null);
const readOnly = createMemo(() => presentationPolicyIsReadOnly());
+ const selectedConnection = createMemo(() => {
+ const id = selectedConnectionId();
+ return id ? ledger.findById(id) : undefined;
+ });
// Redirect legacy deep links and pre-select the matching type in the editor.
createEffect(() => {
@@ -82,12 +89,13 @@ const InfrastructureWorkspaceContent: Component<InfrastructureWorkspaceProps> =
}
});
- const rows = createMemo<InfrastructureSystemRow[]>(() =>
- buildInfrastructureSystemRows({
- activeRows: state.activeRows(),
+ const rows = createMemo<InfrastructureSystemRow[]>(() => [
+ ...ledger.rows(),
+ ...buildInfrastructureSystemRows({
+ activeRows: [],
monitoringStoppedRows: state.monitoringStoppedRows(),
}),
- );
+ ]);
const headerActions = createMemo<ConnectionsTableHeaderAction[]>(() =>
readOnly()
@@ -107,14 +115,17 @@ const InfrastructureWorkspaceContent: Component<InfrastructureWorkspaceProps> =
const handleManageAction = (action: SystemManageAction) => {
switch (action.kind) {
- case 'inventory-active':
- state.setExpandedRowKey(action.rowKey);
+ case 'connection':
state.setSelectedIgnoredRowKey(null);
+ setSelectedConnectionId(action.connectionId);
return;
case 'inventory-ignored':
- state.setExpandedRowKey(null);
+ setSelectedConnectionId(null);
state.setSelectedIgnoredRowKey(action.rowKey);
return;
+ case 'inventory-active':
+ // Legacy active-row path retired; unified rows use the connection drawer.
+ return;
default:
return;
}
@@ -234,20 +245,12 @@ const InfrastructureWorkspaceContent: Component<InfrastructureWorkspaceProps> =
</div>
</Show>
- {/* Active system detail drawer */}
- <Dialog
- isOpen={Boolean(state.selectedActiveRow())}
- onClose={() => state.setExpandedRowKey(null)}
- layout="drawer-right"
- panelClass="max-w-[760px]"
- ariaLabel="Reporting item details"
- >
- <Show when={state.selectedActiveRow()}>
- {(rowAccessor) => <InfrastructureActiveRowDetails rowAccessor={rowAccessor} />}
- </Show>
- </Dialog>
+ <ConnectionDetailDrawer
+ connection={selectedConnection}
+ onClose={() => setSelectedConnectionId(null)}
+ />
- {/* Ignored system detail drawer */}
+ {/* Ignored system detail drawer (retires with phase 9). */}
<Dialog
isOpen={Boolean(state.selectedIgnoredRow())}
onClose={() => state.setSelectedIgnoredRowKey(null)}
diff --git a/frontend-modern/src/components/Settings/__tests__/InfrastructureWorkspace.test.tsx b/frontend-modern/src/components/Settings/__tests__/InfrastructureWorkspace.test.tsx
index e60efda731..2a9f65bcc1 100644
--- a/frontend-modern/src/components/Settings/__tests__/InfrastructureWorkspace.test.tsx
+++ b/frontend-modern/src/components/Settings/__tests__/InfrastructureWorkspace.test.tsx
@@ -1,6 +1,7 @@
import { cleanup, fireEvent, render, screen, waitFor } from '@solidjs/testing-library';
import { createSignal } from 'solid-js';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import type { Connection } from '@/api/connections';
import type { UnifiedAgentRow } from '../infrastructureOperationsModel';
import { InfrastructureWorkspace } from '../InfrastructureWorkspace';
@@ -13,6 +14,7 @@ const setSelectedIgnoredRowKeySpy = vi.hoisted(() => vi.fn());
let mockActiveRows: UnifiedAgentRow[] = [];
let mockIgnoredRows: UnifiedAgentRow[] = [];
+let mockConnections: Connection[] = [];
const [selectedActiveRowKey, setSelectedActiveRowKey] = createSignal<string | null>(null);
const [selectedIgnoredRowKey, setSelectedIgnoredRowKey] = createSignal<string | null>(null);
@@ -70,10 +72,6 @@ vi.mock('../ConnectionEditor/CredentialSlots/VMwareCredentialSlot', () => ({
VMwareCredentialSlot: () => <div data-testid="vmware-section">vmware</div>,
}));
-vi.mock('../InfrastructureActiveRowDetails', () => ({
- InfrastructureActiveRowDetails: () => <div data-testid="active-details">active details</div>,
-}));
-
vi.mock('../InfrastructureIgnoredRowDetails', () => ({
InfrastructureIgnoredRowDetails: () => <div data-testid="ignored-details">ignored details</div>,
}));
@@ -91,12 +89,29 @@ vi.mock('@/api/connections', async () => {
return {
...actual,
ConnectionsAPI: {
- list: vi.fn(),
+ list: vi.fn(() => Promise.resolve(mockConnections)),
probe: vi.fn().mockResolvedValue({ candidates: [], probedMs: 0 }),
},
};
});
+const connectionFixture = (overrides: Partial<Connection> = {}): Connection => ({
+ id: 'pve:zeus',
+ type: 'pve',
+ name: 'zeus',
+ address: 'https://10.0.0.1:8006',
+ state: 'active',
+ stateReason: '',
+ enabled: true,
+ surfaces: ['vms', 'containers', 'storage', 'backups'],
+ scope: { vms: true, containers: true, storage: true, backups: true },
+ lastSeen: new Date().toISOString(),
+ lastError: null,
+ source: 'manual',
+ capabilities: { supportsPause: true, supportsScope: true, supportsTest: true },
+ ...overrides,
+});
+
const reportingRow = (overrides: Partial<UnifiedAgentRow> = {}): UnifiedAgentRow =>
({
rowKey: 'agent:tower',
@@ -172,6 +187,7 @@ describe('InfrastructureWorkspace', () => {
mockSearch = '';
mockActiveRows = [reportingRow()];
mockIgnoredRows = [];
+ mockConnections = [connectionFixture()];
setSelectedActiveRowKey(null);
setSelectedIgnoredRowKey(null);
});
@@ -193,13 +209,23 @@ describe('InfrastructureWorkspace', () => {
expect(screen.queryByTestId('agent-profiles')).toBeNull();
});
- it('shows only monitored agents in the inventory table', () => {
+ it('renders unified connection rows from the aggregator', async () => {
+ mockConnections = [
+ connectionFixture({ id: 'pve:zeus', name: 'zeus', type: 'pve', state: 'active' }),
+ connectionFixture({
+ id: 'truenas:tn-1',
+ name: 'tower-nas',
+ type: 'truenas',
+ state: 'paused',
+ enabled: false,
+ }),
+ ];
renderWorkspace();
- expect(screen.getByText('tower')).toBeInTheDocument();
- expect(screen.queryByText('zeus')).toBeNull();
- expect(screen.queryByText('Tower NAS')).toBeNull();
- expect(screen.queryByText('lab-vcenter')).toBeNull();
+ await waitFor(() => expect(screen.getByText('zeus')).toBeInTheDocument());
+ expect(screen.getByText('tower-nas')).toBeInTheDocument();
+ expect(screen.getByText('Active')).toBeInTheDocument();
+ expect(screen.getByText('Paused')).toBeInTheDocument();
});
it('opens the unified add drawer with the probe step when Add infrastructure is clicked', () => {
@@ -288,13 +314,15 @@ describe('InfrastructureWorkspace', () => {
expect(setModalResetKeySpy).not.toHaveBeenCalled();
});
- it('opens reporting details from the inventory in a drawer', () => {
+ it('opens the connection detail drawer when a unified row is viewed', async () => {
+ mockConnections = [connectionFixture({ id: 'pve:zeus', name: 'zeus' })];
renderWorkspace();
+ await waitFor(() => expect(screen.getByText('zeus')).toBeInTheDocument());
fireEvent.click(screen.getByRole('button', { name: 'View details' }));
- expect(setExpandedRowKeySpy).toHaveBeenCalledWith('agent:tower');
- expect(screen.getByTestId('active-details')).toBeInTheDocument();
+ expect(screen.getByRole('dialog', { name: 'Connection details' })).toBeInTheDocument();
+ expect(setExpandedRowKeySpy).not.toHaveBeenCalled();
});
it('redirects legacy install deep link and pre-selects the agent credential slot', async () => {
diff --git a/frontend-modern/src/components/Settings/connectionsTableModel.ts b/frontend-modern/src/components/Settings/connectionsTableModel.ts
index 9001e85907..b9e621f939 100644
--- a/frontend-modern/src/components/Settings/connectionsTableModel.ts
+++ b/frontend-modern/src/components/Settings/connectionsTableModel.ts
@@ -6,6 +6,7 @@ import {
import type { UnifiedAgentRow } from './infrastructureOperationsModel';
export type SystemManageAction =
+ | { kind: 'connection'; connectionId: string }
| { kind: 'inventory-active'; rowKey: string }
| { kind: 'inventory-ignored'; rowKey: string };
diff --git a/frontend-modern/src/components/Settings/useConnectionsLedger.ts b/frontend-modern/src/components/Settings/useConnectionsLedger.ts
new file mode 100644
index 0000000000..c17a182d1c
--- /dev/null
+++ b/frontend-modern/src/components/Settings/useConnectionsLedger.ts
@@ -0,0 +1,170 @@
+import { createEffect, createMemo, createResource, onCleanup } from 'solid-js';
+import {
+ ConnectionsAPI,
+ type Connection,
+ type ConnectionState,
+ type ConnectionType,
+} from '@/api/connections';
+import type { InfrastructureSystemRow } from './connectionsTableModel';
+
+const POLL_INTERVAL_MS = 15000;
+
+export const CONNECTION_TYPE_LABELS: Record<ConnectionType, string> = {
+ pve: 'Proxmox VE',
+ pbs: 'Proxmox Backup Server',
+ pmg: 'Proxmox Mail Gateway',
+ vmware: 'VMware vCenter',
+ truenas: 'TrueNAS',
+ agent: 'Pulse agent',
+ docker: 'Docker',
+ kubernetes: 'Kubernetes',
+};
+
+const STATE_PRESENTATION: Record<ConnectionState, { label: string; badgeClass: string }> = {
+ active: {
+ label: 'Active',
+ badgeClass: 'bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-300',
+ },
+ paused: {
+ label: 'Paused',
+ badgeClass: 'bg-amber-100 text-amber-800 dark:bg-amber-900 dark:text-amber-200',
+ },
+ unauthorized: {
+ label: 'Unauthorized',
+ badgeClass: 'bg-rose-100 text-rose-800 dark:bg-rose-900 dark:text-rose-200',
+ },
+ unreachable: {
+ label: 'Unreachable',
+ badgeClass: 'bg-rose-100 text-rose-800 dark:bg-rose-900 dark:text-rose-200',
+ },
+ stale: {
+ label: 'Stale',
+ badgeClass: 'bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-200',
+ },
+ pending: {
+ label: 'Pending',
+ badgeClass: 'bg-surface-alt text-base-content',
+ },
+};
+
+const SURFACE_LABELS: Record<string, string> = {
+ vms: 'VMs',
+ containers: 'Containers',
+ storage: 'Storage',
+ backups: 'Backups',
+ datastores: 'Datastores',
+ syncJobs: 'Sync jobs',
+ verifyJobs: 'Verify jobs',
+ pruneJobs: 'Prune jobs',
+ garbageJobs: 'GC jobs',
+ mailStats: 'Mail stats',
+ queues: 'Queues',
+ quarantine: 'Quarantine',
+ domainStats: 'Domain stats',
+ hosts: 'Hosts',
+ datasets: 'Datasets',
+ pools: 'Pools',
+ replication: 'Replication',
+};
+
+export const surfaceLabel = (key: string): string => SURFACE_LABELS[key] ?? key;
+
+const collectionLabelFor = (type: ConnectionType): string => {
+ switch (type) {
+ case 'pve':
+ case 'pbs':
+ case 'pmg':
+ case 'vmware':
+ case 'truenas':
+ return 'API';
+ case 'agent':
+ return 'Agent';
+ case 'docker':
+ return 'Docker';
+ case 'kubernetes':
+ return 'Kubernetes';
+ default:
+ return 'Runtime';
+ }
+};
+
+const lastActivityText = (connection: Connection): string => {
+ if (!connection.lastSeen) return 'No activity yet';
+ const ts = Date.parse(connection.lastSeen);
+ if (Number.isNaN(ts)) return 'Unknown';
+ const diff = Math.max(0, Date.now() - ts);
+ const sec = Math.floor(diff / 1000);
+ if (sec < 60) return `${sec}s ago`;
+ const min = Math.floor(sec / 60);
+ if (min < 60) return `${min}m ago`;
+ const hr = Math.floor(min / 60);
+ if (hr < 24) return `${hr}h ago`;
+ const days = Math.floor(hr / 24);
+ return `${days}d ago`;
+};
+
+const subtitleFor = (connection: Connection): string | undefined => {
+ if (connection.stateReason) return connection.stateReason;
+ return CONNECTION_TYPE_LABELS[connection.type] ?? connection.type;
+};
+
+export const connectionToRow = (connection: Connection): InfrastructureSystemRow => {
+ const presentation = STATE_PRESENTATION[connection.state] ?? STATE_PRESENTATION.pending;
+ const activeScopeKeys = Object.keys(connection.scope ?? {}).filter(
+ (key) => connection.scope?.[key],
+ );
+ const coverage =
+ activeScopeKeys.length > 0
+ ? activeScopeKeys.map(surfaceLabel)
+ : connection.surfaces.map(surfaceLabel);
+ return {
+ id: connection.id,
+ name: connection.name || connection.address || connection.id,
+ subtitle: subtitleFor(connection),
+ host: connection.address,
+ coverageLabels: coverage,
+ collectionLabel: collectionLabelFor(connection.type),
+ statusLabel: presentation.label,
+ statusClassName: presentation.badgeClass,
+ lastActivityText: lastActivityText(connection),
+ manageLabel: 'View details',
+ manage: { kind: 'connection', connectionId: connection.id },
+ };
+};
+
+export interface ConnectionsLedger {
+ connections: () => Connection[];
+ rows: () => InfrastructureSystemRow[];
+ findById: (id: string) => Connection | undefined;
+ reload: () => void;
+ loading: () => boolean;
+ error: () => unknown;
+}
+
+export const useConnectionsLedger = (): ConnectionsLedger => {
+ const [resource, { refetch }] = createResource<Connection[]>(() => ConnectionsAPI.list(), {
+ initialValue: [],
+ });
+
+ createEffect(() => {
+ const handle = window.setInterval(() => {
+ void refetch();
+ }, POLL_INTERVAL_MS);
+ onCleanup(() => window.clearInterval(handle));
+ });
+
+ const connections = () => resource() ?? [];
+ const rows = createMemo<InfrastructureSystemRow[]>(() => connections().map(connectionToRow));
+ const findById = (id: string) => connections().find((conn) => conn.id === id);
+
+ return {
+ connections,
+ rows,
+ findById,
+ reload: () => {
+ void refetch();
+ },
+ loading: () => resource.loading,
+ error: () => resource.error,
+ };
+};