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.

Fix infrastructure source manager live resize

rcourtman0dae66e9c7da
diff --git a/frontend-modern/src/components/Settings/InfrastructureSourceManager.tsx b/frontend-modern/src/components/Settings/InfrastructureSourceManager.tsx
index 9dac29ca84..fdfa89c51d 100644
--- a/frontend-modern/src/components/Settings/InfrastructureSourceManager.tsx
+++ b/frontend-modern/src/components/Settings/InfrastructureSourceManager.tsx
@@ -54,6 +54,7 @@ const utilityToolbarButtonClass =
const discoveryRowClass =
'border-b border-border-subtle bg-blue-50/30 hover:bg-blue-50/40 dark:bg-blue-950/10 dark:hover:bg-blue-950/20';
const wrappedFieldClass = 'whitespace-normal break-words leading-4';
+const CARD_LAYOUT_MAX_WIDTH_PX = 767;
const sortRows = (rows: readonly InfrastructureSystemRow[]): InfrastructureSystemRow[] =>
[...rows].sort((left, right) => left.name.localeCompare(right.name));
@@ -124,6 +125,7 @@ const memberMethodTitleFor = (row: InfrastructureSystemRow, memberIndex: number)
};
export const InfrastructureSourceManager: Component<InfrastructureSourceManagerProps> = (props) => {
+ let layoutContainerRef: HTMLDivElement | undefined;
const products = createMemo(() => getInfrastructureSourceManagerProducts());
const productRank = createMemo(() => {
const next = new Map<InfrastructureOnboardingConnectionType, number>();
@@ -204,15 +206,44 @@ export const InfrastructureSourceManager: Component<InfrastructureSourceManagerP
formatRelativeTimestamp(props.discoveryScanStatus().lastResultAt),
);
- const [viewportWidth, setViewportWidth] = createSignal(
+ const [layoutWidth, setLayoutWidth] = createSignal(
typeof window !== 'undefined' ? window.innerWidth : 1024,
);
+
+ const updateLayoutWidth = (width: number) => {
+ if (!Number.isFinite(width) || width <= 0) return;
+ setLayoutWidth(Math.round(width));
+ };
+
+ const measureLayoutWidth = () => {
+ const width = layoutContainerRef?.getBoundingClientRect().width;
+ if (typeof width === 'number') {
+ updateLayoutWidth(width);
+ }
+ };
+
onMount(() => {
- const handler = () => setViewportWidth(window.innerWidth);
- window.addEventListener('resize', handler);
- onCleanup(() => window.removeEventListener('resize', handler));
+ measureLayoutWidth();
+
+ if (typeof ResizeObserver === 'undefined' || !layoutContainerRef) {
+ const handleResize = () => measureLayoutWidth();
+ window.addEventListener('resize', handleResize);
+ onCleanup(() => window.removeEventListener('resize', handleResize));
+ return;
+ }
+
+ const observer = new ResizeObserver((entries) => {
+ const entryWidth = entries[0]?.contentRect.width;
+ if (typeof entryWidth === 'number') {
+ updateLayoutWidth(entryWidth);
+ return;
+ }
+ measureLayoutWidth();
+ });
+ observer.observe(layoutContainerRef);
+ onCleanup(() => observer.disconnect());
});
- const useCardLayout = createMemo(() => viewportWidth() < 768);
+ const useCardLayout = createMemo(() => layoutWidth() <= CARD_LAYOUT_MAX_WIDTH_PX);
const headerActions = () => (
<Show when={!props.readOnly}>
@@ -250,12 +281,13 @@ export const InfrastructureSourceManager: Component<InfrastructureSourceManagerP
);
return (
- <SettingsPanel
- title="Infrastructure systems"
- description="Configured systems and discovered candidates grouped by platform or host type. Install Pulse Agent on each machine where you want full node-local telemetry."
- noPadding
- action={headerActions()}
- >
+ <div ref={layoutContainerRef} class="min-w-0">
+ <SettingsPanel
+ title="Infrastructure systems"
+ description="Configured systems and discovered candidates grouped by platform or host type. Install Pulse Agent on each machine where you want full node-local telemetry."
+ noPadding
+ action={headerActions()}
+ >
<Show when={!useCardLayout()}>
<Table class="w-full table-fixed text-sm">
<TableHeader class="bg-surface-alt/60">
@@ -918,7 +950,8 @@ export const InfrastructureSourceManager: Component<InfrastructureSourceManagerP
</Show>
</div>
</Show>
- </SettingsPanel>
+ </SettingsPanel>
+ </div>
);
};
diff --git a/frontend-modern/src/components/Settings/__tests__/InfrastructureWorkspace.test.tsx b/frontend-modern/src/components/Settings/__tests__/InfrastructureWorkspace.test.tsx
index ece09debb6..b63587053f 100644
--- a/frontend-modern/src/components/Settings/__tests__/InfrastructureWorkspace.test.tsx
+++ b/frontend-modern/src/components/Settings/__tests__/InfrastructureWorkspace.test.tsx
@@ -38,6 +38,47 @@ const createInfrastructureOnboardingMetricsTrackerMock = vi.hoisted(() =>
}),
);
+const originalResizeObserver = globalThis.ResizeObserver;
+let latestResizeObserverCallback: ResizeObserverCallback | null = null;
+
+const installResizeObserverMock = () => {
+ latestResizeObserverCallback = null;
+ class MockResizeObserver {
+ constructor(callback: ResizeObserverCallback) {
+ latestResizeObserverCallback = callback;
+ }
+
+ observe() {}
+ unobserve() {}
+ disconnect() {}
+ }
+
+ Object.defineProperty(globalThis, 'ResizeObserver', {
+ configurable: true,
+ writable: true,
+ value: MockResizeObserver,
+ });
+};
+
+const emitResizeObserverWidth = (width: number) => {
+ latestResizeObserverCallback?.(
+ [{ contentRect: { width } } as ResizeObserverEntry],
+ {} as ResizeObserver,
+ );
+};
+
+const restoreResizeObserver = () => {
+ if (originalResizeObserver) {
+ Object.defineProperty(globalThis, 'ResizeObserver', {
+ configurable: true,
+ writable: true,
+ value: originalResizeObserver,
+ });
+ return;
+ }
+ delete (globalThis as any).ResizeObserver;
+};
+
vi.mock('@solidjs/router', async () => {
const actual = await vi.importActual<typeof import('@solidjs/router')>('@solidjs/router');
return {
@@ -227,10 +268,16 @@ describe('InfrastructureWorkspace', () => {
routeState.search = '';
connectionState.connections = [connectionFixture()];
connectionState.rows = null;
+ Object.defineProperty(window, 'innerWidth', {
+ configurable: true,
+ writable: true,
+ value: 1024,
+ });
});
afterEach(() => {
cleanup();
+ restoreResizeObserver();
});
const renderWorkspace = (propOverrides: Record<string, unknown> = {}) =>
@@ -256,6 +303,30 @@ describe('InfrastructureWorkspace', () => {
expect(screen.queryByRole('heading', { name: 'Monitored systems' })).not.toBeInTheDocument();
});
+ it('switches the source manager layout from measured container width during live resize', async () => {
+ installResizeObserverMock();
+ Object.defineProperty(window, 'innerWidth', {
+ configurable: true,
+ writable: true,
+ value: 1180,
+ });
+
+ renderWorkspace();
+
+ await waitFor(() =>
+ expect(screen.getByRole('columnheader', { name: 'System' })).toBeInTheDocument(),
+ );
+
+ emitResizeObserverWidth(640);
+
+ await waitFor(() =>
+ expect(screen.queryByRole('columnheader', { name: 'System' })).not.toBeInTheDocument(),
+ );
+ expect(screen.getByText('Proxmox VE')).toBeInTheDocument();
+ expect(screen.getByText('zeus')).toBeInTheDocument();
+ expect(screen.getByText('Active')).toBeInTheDocument();
+ });
+
it('routes discovery actions from the manager and shows discovered candidates in the matching platform group', async () => {
const triggerDiscoveryScan = vi.fn();
renderWorkspace({