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.

Split infrastructure selector runtime owners

rcourtman9c8d4df5d8c4
diff --git a/docs/release-control/v6/internal/subsystems/frontend-primitives.md b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
index e23dbae271..306ed02655 100644
--- a/docs/release-control/v6/internal/subsystems/frontend-primitives.md
+++ b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
@@ -179,6 +179,16 @@ owns sorting, count, identity-alias, and linked-agent derivation, and
owns the per-row render/runtime surface. Future work should extend those
owners instead of pushing websocket, alert, or identity plumbing back into the
shared table shell.
+The shared infrastructure selector now follows that same owner split.
+`frontend-modern/src/components/shared/InfrastructureSelector.tsx` stays the
+render shell, `frontend-modern/src/components/shared/useInfrastructureSelectorState.ts`
+owns selected-node state, tab-reset and escape-key lifecycle, plus hook-backed
+resource and recovery composition, and
+`frontend-modern/src/components/shared/infrastructureSelectorModel.ts` owns
+resource-family counts, agent-backed node-summary projection, unified-node and
+PBS-instance projection, and recovery backup-count derivation. Future
+infrastructure-selector work should extend those owners instead of pushing
+resource aggregation or selection lifecycle back into the shared shell.
The shared interactive sparkline now follows that same split.
`frontend-modern/src/components/shared/InteractiveSparkline.tsx` stays the
render shell, `frontend-modern/src/components/shared/useInteractiveSparklineState.ts`
diff --git a/docs/release-control/v6/internal/subsystems/registry.json b/docs/release-control/v6/internal/subsystems/registry.json
index b0933250f9..286faaef0f 100644
--- a/docs/release-control/v6/internal/subsystems/registry.json
+++ b/docs/release-control/v6/internal/subsystems/registry.json
@@ -2197,6 +2197,7 @@
"frontend-modern/src/components/shared/__tests__/Dialog.test.tsx",
"frontend-modern/src/components/shared/__tests__/HelpIcon.test.tsx",
"frontend-modern/src/components/shared/__tests__/HistoryChart.test.tsx",
+ "frontend-modern/src/components/shared/__tests__/InfrastructureSelector.test.tsx",
"frontend-modern/src/components/shared/__tests__/InfrastructureSummaryTable.test.tsx",
"frontend-modern/src/components/shared/__tests__/PulseDataGrid.test.tsx",
"frontend-modern/src/components/shared/__tests__/SearchField.test.tsx",
diff --git a/frontend-modern/src/components/Settings/__tests__/monitoredSystemModelGuardrails.test.ts b/frontend-modern/src/components/Settings/__tests__/monitoredSystemModelGuardrails.test.ts
index 39fcb9124a..5a8f9cc29a 100644
--- a/frontend-modern/src/components/Settings/__tests__/monitoredSystemModelGuardrails.test.ts
+++ b/frontend-modern/src/components/Settings/__tests__/monitoredSystemModelGuardrails.test.ts
@@ -19,6 +19,7 @@ import agentLedgerPanelSource from '../MonitoredSystemLedgerPanel.tsx?raw';
import alertsPageSource from '@/pages/Alerts.tsx?raw';
import setupCompletionPanelSource from '@/components/SetupWizard/SetupCompletionPanel.tsx?raw';
import infrastructureSelectorSource from '@/components/shared/InfrastructureSelector.tsx?raw';
+import infrastructureSelectorModelSource from '@/components/shared/infrastructureSelectorModel.ts?raw';
import aiChatSource from '@/components/AI/Chat/index.tsx?raw';
import aiChatPresentationSource from '@/utils/aiChatPresentation.ts?raw';
import diagnosticsPanelSource from '../DiagnosticsPanel.tsx?raw';
@@ -32,7 +33,9 @@ import settingsPanelRegistrySource from '../useSettingsPanelRegistry.tsx?raw';
import settingsSystemPanelsSource from '../useSettingsSystemPanels.tsx?raw';
import infrastructureSummarySource from '@/components/Infrastructure/InfrastructureSummary.tsx?raw';
import infrastructureSelectorComponentSource from '@/components/shared/InfrastructureSelector.tsx?raw';
+import infrastructureSelectorStateSource from '@/components/shared/useInfrastructureSelectorState.ts?raw';
import workloadsLinkSource from '@/components/Infrastructure/workloadsLink.ts?raw';
+import unifiedResourceHostTableCardSource from '@/components/Infrastructure/UnifiedResourceHostTableCard.tsx?raw';
import unifiedResourceTableSource from '@/components/Infrastructure/UnifiedResourceTable.tsx?raw';
import thresholdsTableSource from '@/components/Alerts/ThresholdsTable.tsx?raw';
import thresholdsTableAgentDisksSectionSource from '@/components/Alerts/ThresholdsTableAgentDisksSection.tsx?raw';
@@ -871,11 +874,19 @@ describe('monitored-system model guardrails', () => {
expect(setupCompletionPanelSource).not.toContain(
'(state.hosts || []).length > 0\n ? state.hosts\n : resources',
);
- expect(infrastructureSelectorSource).toContain(
+ expect(infrastructureSelectorSource).toContain('useInfrastructureSelectorState');
+ expect(infrastructureSelectorSource).not.toContain(
'const hasAgentFacet = (resource: Resource): boolean =>',
);
- expect(infrastructureSelectorSource).toContain("resource.type === 'truenas'");
- expect(infrastructureSelectorSource).not.toContain('if (hostLikeResources.length === 0');
+ expect(infrastructureSelectorSource).not.toContain("resource.type === 'truenas'");
+ expect(infrastructureSelectorStateSource).toContain('useResources');
+ expect(infrastructureSelectorModelSource).toContain(
+ 'hasInfrastructureSelectorAgentFacet',
+ );
+ expect(infrastructureSelectorModelSource).toContain("resource.type === 'truenas'");
+ expect(infrastructureSelectorModelSource).not.toContain(
+ 'if (hostLikeResources.length === 0',
+ );
expect(guestRowCellsSource).toContain('getDashboardGuestBackupStatusPresentation');
expect(guestRowCellsSource).toContain('getDashboardGuestBackupTooltip');
expect(guestRowCellsSource).toContain('getDashboardGuestNetworkEmptyState');
@@ -949,8 +960,10 @@ describe('monitored-system model guardrails', () => {
expect(infrastructureSummarySource).not.toContain("resource.type === 'host'");
expect(infrastructureSelectorComponentSource).not.toContain("resource.type === 'host'");
expect(workloadsLinkSource).not.toContain("resource.type === 'host'");
- expect(unifiedResourceTableSource).toContain('buildMetricKeyForUnifiedResource');
+ expect(unifiedResourceTableSource).not.toContain('buildMetricKeyForUnifiedResource');
expect(unifiedResourceTableSource).not.toContain("buildMetricKey('host', resource.id)");
+ expect(unifiedResourceHostTableCardSource).toContain('buildMetricKeyForUnifiedResource');
+ expect(unifiedResourceHostTableCardSource).not.toContain("buildMetricKey('host', resource.id)");
expect(resourceBadgesSource).not.toContain("host: 'Agent'");
expect(problemResourcesTableSource).not.toContain("host: 'Agent'");
});
diff --git a/frontend-modern/src/components/shared/InfrastructureSelector.tsx b/frontend-modern/src/components/shared/InfrastructureSelector.tsx
index 49e65b923f..0327a78b9e 100644
--- a/frontend-modern/src/components/shared/InfrastructureSelector.tsx
+++ b/frontend-modern/src/components/shared/InfrastructureSelector.tsx
@@ -1,281 +1,37 @@
-import {
- Component,
- Show,
- createSignal,
- createEffect,
- createMemo,
- onMount,
- onCleanup,
-} from 'solid-js';
-import { unwrap } from 'solid-js/store';
+import { Component, Show } from 'solid-js';
import { InfrastructureSummaryTable } from './InfrastructureSummaryTable';
-import { useResources } from '@/hooks/useResources';
-import type { Agent, Node } from '@/types/api';
-import type { Resource } from '@/types/resource';
-import { useRecoveryRollups } from '@/hooks/useRecoveryRollups';
-import { nodeFromResource, pbsInstanceFromResource } from '@/utils/resourceStateAdapters';
-import {
- getPreferredResourceDisplayName,
- getPreferredResourceHostname,
-} from '@/utils/resourceIdentity';
import {
- getActionableAgentIdFromResource,
- hasAgentFacet as resourceHasAgentFacet,
-} from '@/utils/agentResources';
+ type InfrastructureSelectorProps,
+ useInfrastructureSelectorState,
+} from './useInfrastructureSelectorState';
-interface InfrastructureSelectorProps {
- currentTab: 'dashboard' | 'storage' | 'recovery';
- globalTemperatureMonitoringEnabled?: boolean;
- onNodeSelect?: (nodeId: string | null, nodeType: 'pve' | 'pbs' | null) => void;
- onNamespaceSelect?: (namespace: string) => void;
- nodes?: Node[];
- searchTerm?: string;
- showNodeSummary?: boolean;
-}
+export type { InfrastructureSelectorProps } from './useInfrastructureSelectorState';
export const InfrastructureSelector: Component<InfrastructureSelectorProps> = (props) => {
- const { byType, resources } = useResources();
- const recovery = useRecoveryRollups();
- const [selectedNode, setSelectedNode] = createSignal<string | null>(null);
- const pd = (r: Resource) =>
- r.platformData ? (unwrap(r.platformData) as Record<string, unknown>) : undefined;
- const asRecord = (value: unknown): Record<string, unknown> | undefined =>
- value && typeof value === 'object' ? (value as Record<string, unknown>) : undefined;
- const asString = (value: unknown): string | undefined =>
- typeof value === 'string' && value.trim().length > 0 ? value.trim() : undefined;
- const asNumber = (value: unknown): number | undefined =>
- typeof value === 'number' && Number.isFinite(value) ? value : undefined;
- const asBoolean = (value: unknown): boolean | undefined =>
- typeof value === 'boolean' ? value : undefined;
- const hasAgentFacet = (resource: Resource): boolean => resourceHasAgentFacet(resource);
-
- // Handle ESC key to deselect node
- const handleKeyDown = (e: KeyboardEvent) => {
- if (e.key === 'Escape' && selectedNode()) {
- setSelectedNode(null);
- props.onNodeSelect?.(null, null);
- }
- };
-
- onMount(() => {
- document.addEventListener('keydown', handleKeyDown);
- });
-
- onCleanup(() => {
- document.removeEventListener('keydown', handleKeyDown);
- });
-
- // Reset selection when tab changes
- createEffect(() => {
- props.currentTab;
- setSelectedNode(null);
- });
-
- // Compute per-node VM counts from unified resources
- const vmCounts = createMemo(() => {
- const counts: Record<string, number> = {};
- byType('vm').forEach((r) => {
- if (r.parentId) counts[r.parentId] = (counts[r.parentId] || 0) + 1;
- });
- return counts;
- });
-
- // Compute per-node container counts (LXC + OCI containers)
- const containerCounts = createMemo(() => {
- const counts: Record<string, number> = {};
- const containers = [...byType('system-container'), ...byType('oci-container')];
- containers.forEach((r) => {
- if (r.parentId) counts[r.parentId] = (counts[r.parentId] || 0) + 1;
- });
- return counts;
- });
-
- // Compute per-node storage counts from unified resources
- const storageCounts = createMemo(() => {
- const counts: Record<string, number> = {};
- byType('storage').forEach((r) => {
- if (r.parentId) counts[r.parentId] = (counts[r.parentId] || 0) + 1;
- });
- return counts;
- });
-
- // Physical disks now come from unified resources
- const diskCounts = createMemo(() => {
- const counts: Record<string, number> = {};
- byType('physical_disk').forEach((disk) => {
- if (disk.parentId) {
- counts[disk.parentId] = (counts[disk.parentId] || 0) + 1;
- }
- });
- return counts;
- });
-
- const agentsForNodeSummary = createMemo<Agent[]>(() => {
- const agentFacetResources = resources().filter(
- (resource) =>
- (resource.type === 'agent' ||
- resource.type === 'pbs' ||
- resource.type === 'pmg' ||
- resource.type === 'truenas') &&
- hasAgentFacet(resource),
- );
-
- const agentsById = new Map<string, Agent>();
- for (const resource of agentFacetResources) {
- const platformData = pd(resource);
- const agent = {
- ...(asRecord(platformData?.agent) || {}),
- ...(resource.agent || {}),
- } as Record<string, unknown>;
- const agentMemory = asRecord(agent.memory);
- const totalMemory = asNumber(agentMemory?.total) ?? resource.memory?.total ?? 0;
- const usedMemory = asNumber(agentMemory?.used) ?? resource.memory?.used ?? 0;
- const freeMemory =
- asNumber(agentMemory?.free) ??
- (totalMemory > 0 ? Math.max(0, totalMemory - usedMemory) : 0);
- const usageMemory =
- asNumber(agentMemory?.usage) ??
- (totalMemory > 0 ? (usedMemory / totalMemory) * 100 : (resource.memory?.current ?? 0));
-
- const rawDisks = Array.isArray(agent.disks) ? agent.disks : [];
- const disks = rawDisks
- .map((disk) => {
- const d = asRecord(disk);
- if (!d) return null;
- const total = asNumber(d.total) ?? 0;
- const used = asNumber(d.used) ?? 0;
- const free = asNumber(d.free) ?? Math.max(0, total - used);
- const usage = total > 0 ? (used / total) * 100 : 0;
- return {
- total,
- used,
- free,
- usage,
- mountpoint: asString(d.mountpoint),
- type: asString(d.type),
- device: asString(d.device),
- };
- })
- .filter((disk): disk is NonNullable<typeof disk> => Boolean(disk));
-
- const hostId = getActionableAgentIdFromResource(resource) || resource.id;
- const hostname = getPreferredResourceHostname(resource) || hostId;
-
- if (agentsById.has(hostId)) continue;
- agentsById.set(hostId, {
- id: hostId,
- hostname,
- displayName: getPreferredResourceDisplayName(resource),
- platform: asString(agent.platform),
- osName: asString(agent.osName),
- osVersion: asString(agent.osVersion),
- kernelVersion: asString(agent.kernelVersion),
- architecture: asString(agent.architecture),
- cpuCount: asNumber(agent.cpuCount),
- memory: {
- total: totalMemory,
- used: usedMemory,
- free: freeMemory,
- usage: usageMemory,
- swapUsed: asNumber(agentMemory?.swapUsed),
- swapTotal: asNumber(agentMemory?.swapTotal),
- },
- disks,
- networkInterfaces: Array.isArray(agent.networkInterfaces)
- ? (agent.networkInterfaces as Agent['networkInterfaces'])
- : [],
- sensors: asRecord(agent.sensors) as Agent['sensors'],
- raid: Array.isArray(agent.raid) ? (agent.raid as Agent['raid']) : [],
- status: resource.status || 'unknown',
- uptimeSeconds: asNumber(agent.uptimeSeconds) ?? resource.uptime,
- lastSeen: resource.lastSeen,
- agentVersion: asString(agent.agentVersion),
- commandsEnabled: asBoolean(agent.commandsEnabled),
- tokenId: asString(agent.tokenId),
- tokenName: asString(agent.tokenName),
- tokenHint: asString(agent.tokenHint),
- tokenLastUsedAt: asNumber(agent.tokenLastUsedAt),
- tags: resource.tags,
- isLegacy: asBoolean(platformData?.isLegacy),
- linkedNodeId: asString(platformData?.linkedNodeId),
- });
- }
-
- return Array.from(agentsById.values());
- });
-
- const unifiedNodes = createMemo<Node[]>(() =>
- resources()
- .filter((resource) => resource.type === 'agent')
- .map(nodeFromResource)
- .filter((node): node is Node => Boolean(node)),
- );
-
- const pbsInstances = createMemo(() =>
- resources()
- .filter((resource) => resource.type === 'pbs')
- .map(pbsInstanceFromResource)
- .filter((instance): instance is NonNullable<typeof instance> => Boolean(instance)),
- );
-
- // Calculate rollup counts for PVE nodes (best-effort based on subjectRef).
- // PBS-per-instance counts require repository attribution (not currently exposed in rollups).
- const backupCounts = createMemo(() => {
- const counts: Record<string, number> = {};
-
- const nodes = props.nodes || unifiedNodes();
- if (nodes) {
- nodes.forEach((node) => {
- counts[node.id] = 0;
- });
- }
-
- const rollups = recovery.rollups() || [];
- for (const rollup of rollups) {
- const ref = rollup.subjectRef || null;
- if (!ref?.namespace || !ref?.class) continue;
-
- const node = (nodes || []).find((n) => n.instance === ref.namespace && n.name === ref.class);
- if (!node) continue;
- counts[node.id] = (counts[node.id] || 0) + 1;
- }
-
- return counts;
- });
-
- const handleNodeClick = (nodeId: string, nodeType: 'pve' | 'pbs') => {
- // Toggle selection
- if (selectedNode() === nodeId) {
- setSelectedNode(null);
- props.onNodeSelect?.(null, null);
- } else {
- setSelectedNode(nodeId);
- props.onNodeSelect?.(nodeId, nodeType);
- }
- };
-
- // Parent components now handle conditional rendering, so we can render directly
- const nodes = createMemo(() => props.nodes || unifiedNodes() || []);
- const showNodeSummary = () => props.showNodeSummary ?? true;
+ const infrastructureSelector = useInfrastructureSelectorState(props);
return (
- <Show when={showNodeSummary()}>
- <div class="space-y-2 mb-4">
+ <Show when={infrastructureSelector.showNodeSummary()}>
+ <div class="mb-4 space-y-2">
<InfrastructureSummaryTable
- nodes={nodes()}
- pbsInstances={props.currentTab === 'recovery' ? pbsInstances() : undefined}
- vmCounts={vmCounts()}
- containerCounts={containerCounts()}
- storageCounts={storageCounts()}
- diskCounts={diskCounts()}
- agents={agentsForNodeSummary()}
- backupCounts={backupCounts()}
+ nodes={infrastructureSelector.nodes()}
+ pbsInstances={
+ props.currentTab === 'recovery' ? infrastructureSelector.pbsInstances() : undefined
+ }
+ vmCounts={infrastructureSelector.vmCounts()}
+ containerCounts={infrastructureSelector.containerCounts()}
+ storageCounts={infrastructureSelector.storageCounts()}
+ diskCounts={infrastructureSelector.diskCounts()}
+ agents={infrastructureSelector.agentsForNodeSummary()}
+ backupCounts={infrastructureSelector.backupCounts()}
currentTab={props.currentTab}
- selectedNode={selectedNode()}
+ selectedNode={infrastructureSelector.selectedNode()}
globalTemperatureMonitoringEnabled={props.globalTemperatureMonitoringEnabled}
- onNodeClick={handleNodeClick}
+ onNodeClick={infrastructureSelector.handleNodeClick}
/>
</div>
</Show>
);
};
+
+export default InfrastructureSelector;
diff --git a/frontend-modern/src/components/shared/SharedPrimitives.guardrails.test.ts b/frontend-modern/src/components/shared/SharedPrimitives.guardrails.test.ts
index 072153aae9..f512cd5bfe 100644
--- a/frontend-modern/src/components/shared/SharedPrimitives.guardrails.test.ts
+++ b/frontend-modern/src/components/shared/SharedPrimitives.guardrails.test.ts
@@ -9,10 +9,12 @@ import helpIconSource from '@/components/shared/HelpIcon.tsx?raw';
import helpIconModelSource from '@/components/shared/helpIconModel.ts?raw';
import historyChartSource from '@/components/shared/HistoryChart.tsx?raw';
import historyChartModelSource from '@/components/shared/historyChartModel.ts?raw';
+import infrastructureSelectorSource from '@/components/shared/InfrastructureSelector.tsx?raw';
import interactiveSparklineSource from '@/components/shared/InteractiveSparkline.tsx?raw';
import interactiveSparklineModelSource from '@/components/shared/interactiveSparklineModel.ts?raw';
import infrastructureSummaryTableSource from '@/components/shared/InfrastructureSummaryTable.tsx?raw';
import infrastructureSummaryTableRowSource from '@/components/shared/InfrastructureSummaryTableRow.tsx?raw';
+import infrastructureSelectorModelSource from '@/components/shared/infrastructureSelectorModel.ts?raw';
import infrastructureSummaryTableModelSource from '@/components/shared/infrastructureSummaryTableModel.ts?raw';
import infrastructureSummaryTableStateSource from '@/components/shared/useInfrastructureSummaryTableState.ts?raw';
import monitoredSystemLimitWarningBannerSource from '@/components/shared/MonitoredSystemLimitWarningBanner.tsx?raw';
@@ -22,6 +24,7 @@ import containerUpdateButtonStateSource from '@/components/shared/useContainerUp
import densityMapStateSource from '@/components/shared/useDensityMapState.ts?raw';
import helpIconStateSource from '@/components/shared/useHelpIconState.ts?raw';
import historyChartStateSource from '@/components/shared/useHistoryChartState.ts?raw';
+import infrastructureSelectorStateSource from '@/components/shared/useInfrastructureSelectorState.ts?raw';
import interactiveSparklineStateSource from '@/components/shared/useInteractiveSparklineState.ts?raw';
import webInterfaceUrlFieldSource from '@/components/shared/WebInterfaceUrlField.tsx?raw';
import webInterfaceUrlFieldModelSource from '@/components/shared/webInterfaceUrlFieldModel.ts?raw';
@@ -158,6 +161,27 @@ describe('shared primitive guardrails', () => {
expect(infrastructureSummaryTableRowSource).not.toContain('useAlertsActivation');
});
+ it('keeps infrastructure selector on shell, runtime, and model owners', () => {
+ expect(infrastructureSelectorSource).toContain('useInfrastructureSelectorState');
+ expect(infrastructureSelectorSource).toContain('InfrastructureSummaryTable');
+ expect(infrastructureSelectorSource).not.toContain('useResources');
+ expect(infrastructureSelectorSource).not.toContain('createSignal');
+ expect(infrastructureSelectorSource).not.toContain("resource.type === 'truenas'");
+
+ expect(infrastructureSelectorStateSource).toContain('useResources');
+ expect(infrastructureSelectorStateSource).toContain('useRecoveryRollups');
+ expect(infrastructureSelectorStateSource).toContain('createSignal');
+ expect(infrastructureSelectorStateSource).toContain('document.addEventListener');
+ expect(infrastructureSelectorStateSource).toContain(
+ 'export function useInfrastructureSelectorState',
+ );
+
+ expect(infrastructureSelectorModelSource).toContain('buildInfrastructureSelectorAgents');
+ expect(infrastructureSelectorModelSource).toContain('buildInfrastructureSelectorBackupCounts');
+ expect(infrastructureSelectorModelSource).toContain('buildInfrastructureSelectorUnifiedNodes');
+ expect(infrastructureSelectorModelSource).toContain("resource.type === 'truenas'");
+ });
+
it('keeps interactive sparkline on shell, runtime, and model owners', () => {
expect(interactiveSparklineSource).toContain('useInteractiveSparklineState');
expect(interactiveSparklineSource).not.toContain('createEffect');
diff --git a/frontend-modern/src/components/shared/__tests__/InfrastructureSelector.test.tsx b/frontend-modern/src/components/shared/__tests__/InfrastructureSelector.test.tsx
new file mode 100644
index 0000000000..bbb84347e0
--- /dev/null
+++ b/frontend-modern/src/components/shared/__tests__/InfrastructureSelector.test.tsx
@@ -0,0 +1,112 @@
+import { fireEvent, render, screen, waitFor } from '@solidjs/testing-library';
+import { describe, expect, it, vi } from 'vitest';
+import infrastructureSelectorSource from '@/components/shared/InfrastructureSelector.tsx?raw';
+import infrastructureSelectorModelSource from '@/components/shared/infrastructureSelectorModel.ts?raw';
+import infrastructureSelectorStateSource from '@/components/shared/useInfrastructureSelectorState.ts?raw';
+import { InfrastructureSelector } from '@/components/shared/InfrastructureSelector';
+
+const infrastructureSummaryTableMock = vi.fn(
+ (props: { onNodeClick: (nodeId: string, nodeType: 'pve' | 'pbs') => void; selectedNode: string | null }) => (
+ <button
+ type="button"
+ data-testid="infrastructure-selector-table"
+ onClick={() => props.onNodeClick('node-1', 'pve')}
+ >
+ {props.selectedNode ?? 'none'}
+ </button>
+ ),
+);
+
+vi.mock('@/components/shared/InfrastructureSummaryTable', () => ({
+ InfrastructureSummaryTable: (props: {
+ onNodeClick: (nodeId: string, nodeType: 'pve' | 'pbs') => void;
+ selectedNode: string | null;
+ }) => infrastructureSummaryTableMock(props),
+}));
+
+vi.mock('@/hooks/useResources', () => ({
+ useResources: () => ({
+ resources: () => [
+ {
+ id: 'node-1',
+ type: 'agent',
+ name: 'pve1',
+ status: 'online',
+ instance: 'main',
+ uptime: 120,
+ platformData: {
+ type: 'node',
+ node: 'pve1',
+ instance: 'main',
+ pveVersion: '8.0',
+ cpu: 0.2,
+ memory: { total: 8, used: 4, free: 4, usage: 50 },
+ disk: { total: 100, used: 25, free: 75, usage: 25 },
+ loadAverage: [0.1, 0.2, 0.3],
+ },
+ memory: { total: 8, used: 4, free: 4, current: 50 },
+ agent: {
+ platform: 'linux',
+ memory: { total: 8, used: 4, free: 4, usage: 50 },
+ disks: [],
+ networkInterfaces: [],
+ raid: [],
+ },
+ },
+ ],
+ }),
+}));
+
+vi.mock('@/hooks/useRecoveryRollups', () => ({
+ useRecoveryRollups: () => ({
+ rollups: () => [],
+ }),
+}));
+
+describe('InfrastructureSelector', () => {
+ it('keeps the selector on shell, runtime, and model owners', () => {
+ expect(infrastructureSelectorSource).toContain('useInfrastructureSelectorState');
+ expect(infrastructureSelectorSource).toContain('InfrastructureSummaryTable');
+ expect(infrastructureSelectorSource).not.toContain('useResources');
+ expect(infrastructureSelectorSource).not.toContain('createSignal');
+ expect(infrastructureSelectorSource).not.toContain("resource.type === 'truenas'");
+
+ expect(infrastructureSelectorStateSource).toContain('useResources');
+ expect(infrastructureSelectorStateSource).toContain('useRecoveryRollups');
+ expect(infrastructureSelectorStateSource).toContain('createSignal');
+ expect(infrastructureSelectorStateSource).toContain('document.addEventListener');
+ expect(infrastructureSelectorStateSource).toContain(
+ 'export function useInfrastructureSelectorState',
+ );
+
+ expect(infrastructureSelectorModelSource).toContain(
+ 'buildInfrastructureSelectorAgents',
+ );
+ expect(infrastructureSelectorModelSource).toContain(
+ 'buildInfrastructureSelectorBackupCounts',
+ );
+ expect(infrastructureSelectorModelSource).toContain(
+ 'buildInfrastructureSelectorUnifiedNodes',
+ );
+ expect(infrastructureSelectorModelSource).toContain("resource.type === 'truenas'");
+ });
+
+ it('toggles node selection and clears it on escape', async () => {
+ const onNodeSelect = vi.fn();
+
+ render(() => (
+ <InfrastructureSelector currentTab="dashboard" showNodeSummary onNodeSelect={onNodeSelect} />
+ ));
+
+ const table = screen.getByTestId('infrastructure-selector-table');
+ expect(table).toHaveTextContent('none');
+
+ fireEvent.click(table);
+ expect(onNodeSelect).toHaveBeenLastCalledWith('node-1', 'pve');
+ await waitFor(() => expect(table).toHaveTextContent('node-1'));
+
+ fireEvent.keyDown(document, { key: 'Escape' });
+ expect(onNodeSelect).toHaveBeenLastCalledWith(null, null);
+ await waitFor(() => expect(table).toHaveTextContent('none'));
+ });
+});
diff --git a/frontend-modern/src/components/shared/infrastructureSelectorModel.ts b/frontend-modern/src/components/shared/infrastructureSelectorModel.ts
new file mode 100644
index 0000000000..2a296d60b8
--- /dev/null
+++ b/frontend-modern/src/components/shared/infrastructureSelectorModel.ts
@@ -0,0 +1,201 @@
+import { unwrap } from 'solid-js/store';
+import type { Agent, Node } from '@/types/api';
+import type { Resource } from '@/types/resource';
+import { nodeFromResource, pbsInstanceFromResource } from '@/utils/resourceStateAdapters';
+import {
+ getPreferredResourceDisplayName,
+ getPreferredResourceHostname,
+} from '@/utils/resourceIdentity';
+import {
+ getActionableAgentIdFromResource,
+ hasAgentFacet as resourceHasAgentFacet,
+} from '@/utils/agentResources';
+
+export interface InfrastructureSelectorProps {
+ currentTab: 'dashboard' | 'storage' | 'recovery';
+ globalTemperatureMonitoringEnabled?: boolean;
+ onNodeSelect?: (nodeId: string | null, nodeType: 'pve' | 'pbs' | null) => void;
+ onNamespaceSelect?: (namespace: string) => void;
+ nodes?: Node[];
+ searchTerm?: string;
+ showNodeSummary?: boolean;
+}
+
+export interface InfrastructureSelectorRecoveryRollup {
+ subjectRef?: {
+ namespace?: string;
+ class?: string;
+ } | null;
+}
+
+export type InfrastructureSelectorPBSInstance = NonNullable<
+ ReturnType<typeof pbsInstanceFromResource>
+>;
+
+const asRecord = (value: unknown): Record<string, unknown> | undefined =>
+ value && typeof value === 'object' ? (value as Record<string, unknown>) : undefined;
+
+const asString = (value: unknown): string | undefined =>
+ typeof value === 'string' && value.trim().length > 0 ? value.trim() : undefined;
+
+const asNumber = (value: unknown): number | undefined =>
+ typeof value === 'number' && Number.isFinite(value) ? value : undefined;
+
+const asBoolean = (value: unknown): boolean | undefined =>
+ typeof value === 'boolean' ? value : undefined;
+
+export const hasInfrastructureSelectorAgentFacet = (resource: Resource): boolean =>
+ resourceHasAgentFacet(resource);
+
+export function buildInfrastructureSelectorCounts(
+ resources: Resource[],
+ resourceTypes: Resource['type'] | Resource['type'][],
+): Record<string, number> {
+ const counts: Record<string, number> = {};
+ const typeSet = new Set(Array.isArray(resourceTypes) ? resourceTypes : [resourceTypes]);
+
+ resources.forEach((resource) => {
+ if (!typeSet.has(resource.type) || !resource.parentId) return;
+ counts[resource.parentId] = (counts[resource.parentId] || 0) + 1;
+ });
+
+ return counts;
+}
+
+export function buildInfrastructureSelectorAgents(resources: Resource[]): Agent[] {
+ const agentFacetResources = resources.filter(
+ (resource) =>
+ (resource.type === 'agent' ||
+ resource.type === 'pbs' ||
+ resource.type === 'pmg' ||
+ resource.type === 'truenas') &&
+ hasInfrastructureSelectorAgentFacet(resource),
+ );
+
+ const agentsById = new Map<string, Agent>();
+ for (const resource of agentFacetResources) {
+ const platformData = resource.platformData
+ ? (unwrap(resource.platformData) as Record<string, unknown>)
+ : undefined;
+ const agent = {
+ ...(asRecord(platformData?.agent) || {}),
+ ...(resource.agent || {}),
+ } as Record<string, unknown>;
+ const agentMemory = asRecord(agent.memory);
+ const totalMemory = asNumber(agentMemory?.total) ?? resource.memory?.total ?? 0;
+ const usedMemory = asNumber(agentMemory?.used) ?? resource.memory?.used ?? 0;
+ const freeMemory =
+ asNumber(agentMemory?.free) ??
+ (totalMemory > 0 ? Math.max(0, totalMemory - usedMemory) : 0);
+ const usageMemory =
+ asNumber(agentMemory?.usage) ??
+ (totalMemory > 0 ? (usedMemory / totalMemory) * 100 : (resource.memory?.current ?? 0));
+
+ const rawDisks = Array.isArray(agent.disks) ? agent.disks : [];
+ const disks = rawDisks
+ .map((disk) => {
+ const normalizedDisk = asRecord(disk);
+ if (!normalizedDisk) return null;
+ const total = asNumber(normalizedDisk.total) ?? 0;
+ const used = asNumber(normalizedDisk.used) ?? 0;
+ const free = asNumber(normalizedDisk.free) ?? Math.max(0, total - used);
+ const usage = total > 0 ? (used / total) * 100 : 0;
+ return {
+ total,
+ used,
+ free,
+ usage,
+ mountpoint: asString(normalizedDisk.mountpoint),
+ type: asString(normalizedDisk.type),
+ device: asString(normalizedDisk.device),
+ };
+ })
+ .filter((disk): disk is NonNullable<typeof disk> => Boolean(disk));
+
+ const hostId = getActionableAgentIdFromResource(resource) || resource.id;
+ const hostname = getPreferredResourceHostname(resource) || hostId;
+
+ if (agentsById.has(hostId)) continue;
+
+ agentsById.set(hostId, {
+ id: hostId,
+ hostname,
+ displayName: getPreferredResourceDisplayName(resource),
+ platform: asString(agent.platform),
+ osName: asString(agent.osName),
+ osVersion: asString(agent.osVersion),
+ kernelVersion: asString(agent.kernelVersion),
+ architecture: asString(agent.architecture),
+ cpuCount: asNumber(agent.cpuCount),
+ memory: {
+ total: totalMemory,
+ used: usedMemory,
+ free: freeMemory,
+ usage: usageMemory,
+ swapUsed: asNumber(agentMemory?.swapUsed),
+ swapTotal: asNumber(agentMemory?.swapTotal),
+ },
+ disks,
+ networkInterfaces: Array.isArray(agent.networkInterfaces)
+ ? (agent.networkInterfaces as Agent['networkInterfaces'])
+ : [],
+ sensors: asRecord(agent.sensors) as Agent['sensors'],
+ raid: Array.isArray(agent.raid) ? (agent.raid as Agent['raid']) : [],
+ status: resource.status || 'unknown',
+ uptimeSeconds: asNumber(agent.uptimeSeconds) ?? resource.uptime,
+ lastSeen: resource.lastSeen,
+ agentVersion: asString(agent.agentVersion),
+ commandsEnabled: asBoolean(agent.commandsEnabled),
+ tokenId: asString(agent.tokenId),
+ tokenName: asString(agent.tokenName),
+ tokenHint: asString(agent.tokenHint),
+ tokenLastUsedAt: asNumber(agent.tokenLastUsedAt),
+ tags: resource.tags,
+ isLegacy: asBoolean(platformData?.isLegacy),
+ linkedNodeId: asString(platformData?.linkedNodeId),
+ });
+ }
+
+ return Array.from(agentsById.values());
+}
+
+export function buildInfrastructureSelectorUnifiedNodes(resources: Resource[]): Node[] {
+ return resources
+ .filter((resource) => resource.type === 'agent')
+ .map(nodeFromResource)
+ .filter((node): node is Node => Boolean(node));
+}
+
+export function buildInfrastructureSelectorPbsInstances(
+ resources: Resource[],
+): InfrastructureSelectorPBSInstance[] {
+ return resources
+ .filter((resource) => resource.type === 'pbs')
+ .map(pbsInstanceFromResource)
+ .filter((instance): instance is InfrastructureSelectorPBSInstance => Boolean(instance));
+}
+
+export function buildInfrastructureSelectorBackupCounts(options: {
+ nodes: Node[];
+ rollups: InfrastructureSelectorRecoveryRollup[];
+}): Record<string, number> {
+ const counts: Record<string, number> = {};
+
+ options.nodes.forEach((node) => {
+ counts[node.id] = 0;
+ });
+
+ for (const rollup of options.rollups) {
+ const ref = rollup.subjectRef || null;
+ if (!ref?.namespace || !ref?.class) continue;
+
+ const node = options.nodes.find(
+ (candidate) => candidate.instance === ref.namespace && candidate.name === ref.class,
+ );
+ if (!node) continue;
+
+ counts[node.id] = (counts[node.id] || 0) + 1;
+ }
+
+ return counts;
+}
diff --git a/frontend-modern/src/components/shared/useInfrastructureSelectorState.ts b/frontend-modern/src/components/shared/useInfrastructureSelectorState.ts
new file mode 100644
index 0000000000..dad71e362a
--- /dev/null
+++ b/frontend-modern/src/components/shared/useInfrastructureSelectorState.ts
@@ -0,0 +1,91 @@
+import { createEffect, createMemo, createSignal, onCleanup } from 'solid-js';
+import { useRecoveryRollups } from '@/hooks/useRecoveryRollups';
+import { useResources } from '@/hooks/useResources';
+import {
+ buildInfrastructureSelectorAgents,
+ buildInfrastructureSelectorBackupCounts,
+ buildInfrastructureSelectorCounts,
+ buildInfrastructureSelectorPbsInstances,
+ buildInfrastructureSelectorUnifiedNodes,
+ type InfrastructureSelectorProps,
+} from './infrastructureSelectorModel';
+
+export type { InfrastructureSelectorProps } from './infrastructureSelectorModel';
+
+export function useInfrastructureSelectorState(props: InfrastructureSelectorProps) {
+ const { resources } = useResources();
+ const recovery = useRecoveryRollups();
+ const [selectedNode, setSelectedNode] = createSignal<string | null>(null);
+
+ const unifiedNodes = createMemo(() => buildInfrastructureSelectorUnifiedNodes(resources()));
+ const nodes = createMemo(() => props.nodes ?? unifiedNodes());
+ const pbsInstances = createMemo(() => buildInfrastructureSelectorPbsInstances(resources()));
+
+ const vmCounts = createMemo(() => buildInfrastructureSelectorCounts(resources(), 'vm'));
+ const containerCounts = createMemo(() =>
+ buildInfrastructureSelectorCounts(resources(), ['system-container', 'oci-container']),
+ );
+ const storageCounts = createMemo(() =>
+ buildInfrastructureSelectorCounts(resources(), 'storage'),
+ );
+ const diskCounts = createMemo(() =>
+ buildInfrastructureSelectorCounts(resources(), 'physical_disk'),
+ );
+
+ const agentsForNodeSummary = createMemo(() => buildInfrastructureSelectorAgents(resources()));
+ const backupCounts = createMemo(() =>
+ buildInfrastructureSelectorBackupCounts({
+ nodes: nodes(),
+ rollups: (recovery.rollups() || []) as Parameters<
+ typeof buildInfrastructureSelectorBackupCounts
+ >[0]['rollups'],
+ }),
+ );
+
+ const handleNodeClick = (nodeId: string, nodeType: 'pve' | 'pbs') => {
+ if (selectedNode() === nodeId) {
+ setSelectedNode(null);
+ props.onNodeSelect?.(null, null);
+ return;
+ }
+
+ setSelectedNode(nodeId);
+ props.onNodeSelect?.(nodeId, nodeType);
+ };
+
+ createEffect(() => {
+ props.currentTab;
+ setSelectedNode(null);
+ });
+
+ createEffect(() => {
+ if (typeof document === 'undefined') return;
+
+ const handleKeyDown = (event: KeyboardEvent) => {
+ if (event.key !== 'Escape' || !selectedNode()) return;
+ setSelectedNode(null);
+ props.onNodeSelect?.(null, null);
+ };
+
+ document.addEventListener('keydown', handleKeyDown);
+ onCleanup(() => document.removeEventListener('keydown', handleKeyDown));
+ });
+
+ const showNodeSummary = () => props.showNodeSummary ?? true;
+
+ return {
+ agentsForNodeSummary,
+ backupCounts,
+ containerCounts,
+ diskCounts,
+ handleNodeClick,
+ nodes,
+ pbsInstances,
+ selectedNode,
+ showNodeSummary,
+ storageCounts,
+ vmCounts,
+ };
+}
+
+export type InfrastructureSelectorState = ReturnType<typeof useInfrastructureSelectorState>;
diff --git a/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts b/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts
index ee8956ebe9..f84d89bb19 100644
--- a/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts
+++ b/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts
@@ -16,14 +16,17 @@ import helpIconSource from '@/components/shared/HelpIcon.tsx?raw';
import helpIconModelSource from '@/components/shared/helpIconModel.ts?raw';
import historyChartSource from '@/components/shared/HistoryChart.tsx?raw';
import historyChartModelSource from '@/components/shared/historyChartModel.ts?raw';
+import infrastructureSelectorSource from '@/components/shared/InfrastructureSelector.tsx?raw';
import infrastructureSummaryTableSource from '@/components/shared/InfrastructureSummaryTable.tsx?raw';
import infrastructureSummaryTableRowSource from '@/components/shared/InfrastructureSummaryTableRow.tsx?raw';
import interactiveSparklineSource from '@/components/shared/InteractiveSparkline.tsx?raw';
import interactiveSparklineModelSource from '@/components/shared/interactiveSparklineModel.ts?raw';
+import infrastructureSelectorModelSource from '@/components/shared/infrastructureSelectorModel.ts?raw';
import sharedInfrastructureSummaryTableModelSource from '@/components/shared/infrastructureSummaryTableModel.ts?raw';
import containerUpdateButtonStateSource from '@/components/shared/useContainerUpdateButtonState.ts?raw';
import helpIconStateSource from '@/components/shared/useHelpIconState.ts?raw';
import historyChartStateSource from '@/components/shared/useHistoryChartState.ts?raw';
+import infrastructureSelectorStateSource from '@/components/shared/useInfrastructureSelectorState.ts?raw';
import interactiveSparklineStateSource from '@/components/shared/useInteractiveSparklineState.ts?raw';
import infrastructureSummaryTableStateSource from '@/components/shared/useInfrastructureSummaryTableState.ts?raw';
import resourceBadgePresentationSource from '@/utils/resourceBadgePresentation.ts?raw';
@@ -2638,6 +2641,23 @@ describe('frontend resource type boundaries', () => {
expect(sharedInfrastructureSummaryTableModelSource).toContain(
'resolveInfrastructureSummaryLinkedAgent',
);
+ expect(infrastructureSelectorSource).toContain('useInfrastructureSelectorState');
+ expect(infrastructureSelectorSource).toContain('InfrastructureSummaryTable');
+ expect(infrastructureSelectorSource).not.toContain('useResources');
+ expect(infrastructureSelectorSource).not.toContain('createSignal');
+ expect(infrastructureSelectorSource).not.toContain("resource.type === 'truenas'");
+ expect(infrastructureSelectorStateSource).toContain('useResources');
+ expect(infrastructureSelectorStateSource).toContain('useRecoveryRollups');
+ expect(infrastructureSelectorStateSource).toContain('createSignal');
+ expect(infrastructureSelectorStateSource).toContain('document.addEventListener');
+ expect(infrastructureSelectorModelSource).toContain('buildInfrastructureSelectorAgents');
+ expect(infrastructureSelectorModelSource).toContain(
+ 'buildInfrastructureSelectorBackupCounts',
+ );
+ expect(infrastructureSelectorModelSource).toContain(
+ 'buildInfrastructureSelectorUnifiedNodes',
+ );
+ expect(infrastructureSelectorModelSource).toContain("resource.type === 'truenas'");
expect(interactiveSparklineSource).toContain('useInteractiveSparklineState');
expect(interactiveSparklineSource).not.toContain('scheduleSparkline');
expect(interactiveSparklineSource).not.toContain('downsampleLTTB');