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.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
Split shared dialog runtime owners
rcourtman035f68e029a6
diff --git a/docs/release-control/v6/internal/subsystems/frontend-primitives.md b/docs/release-control/v6/internal/subsystems/frontend-primitives.mdindex 6e9cb997d2..5977d7fce4 100644--- a/docs/release-control/v6/internal/subsystems/frontend-primitives.md+++ b/docs/release-control/v6/internal/subsystems/frontend-primitives.md@@ -214,6 +214,14 @@ signals, canvas draw lifecycle, and resize handling, andmath, hover target selection, tooltip time formatting, and density-cellopacity rules. Future density-map work should extend those owners instead ofpushing canvas lifecycle or chart math back into the shared shell.+The shared dialog now follows that same owner split.+`frontend-modern/src/components/shared/Dialog.tsx` stays the render shell,+`frontend-modern/src/components/shared/useDialogState.ts` owns focus trap,+body-scroll lock, previous-focus restoration, and backdrop-close runtime, and+`frontend-modern/src/components/shared/dialogModel.ts` owns focusable-element+lookup plus layout and panel class policy. Future dialog work should extend+those owners instead of pushing focus-trap lifecycle or layout policy back into+the shared shell.The shared history chart now follows the same owner shape.`frontend-modern/src/components/shared/HistoryChart.tsx` stays the rendershell, `frontend-modern/src/components/shared/useHistoryChartState.ts` ownsdiff --git a/frontend-modern/src/components/shared/Dialog.tsx b/frontend-modern/src/components/shared/Dialog.tsxindex 8b28d9e66d..aa1041ee46 100644--- a/frontend-modern/src/components/shared/Dialog.tsx+++ b/frontend-modern/src/components/shared/Dialog.tsx@@ -1,120 +1,28 @@-import { Show, createEffect, onCleanup } from 'solid-js';+import { Show } from 'solid-js';import type { Component, JSX } from 'solid-js';import { Portal } from 'solid-js/web';+import {+ getDialogAlignmentClass,+ getDialogPanelClass,+ getDialogViewportClass,+ type DialogLayout,+} from './dialogModel';+import { useDialogState } from './useDialogState';interface DialogProps {isOpen: boolean;onClose: () => void;children: JSX.Element;panelClass?: string;- layout?: 'modal' | 'drawer-right';+ layout?: DialogLayout;closeOnBackdrop?: boolean;ariaLabel?: string;ariaLabelledBy?: string;ariaDescribedBy?: string;}-const FOCUSABLE_SELECTOR =- 'a[href],area[href],button:not([disabled]),input:not([disabled]):not([type="hidden"]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])';--let openDialogCount = 0;-let previousBodyOverflow = '';--const lockBodyScroll = () => {- if (typeof document === 'undefined') return;- if (openDialogCount === 0) {- previousBodyOverflow = document.body.style.overflow;- document.body.style.overflow = 'hidden';- }- openDialogCount += 1;-};--const unlockBodyScroll = () => {- if (typeof document === 'undefined') return;- openDialogCount = Math.max(0, openDialogCount - 1);- if (openDialogCount === 0) {- document.body.style.overflow = previousBodyOverflow;- }-};--const getFocusableElements = (container: HTMLElement): HTMLElement[] =>- Array.from(container.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR)).filter(- (element) =>- !element.hasAttribute('disabled') && element.getAttribute('aria-hidden') !== 'true',- );-export const Dialog: Component<DialogProps> = (props) => {- let panelRef: HTMLDivElement | undefined;-- createEffect(() => {- if (!props.isOpen || typeof document === 'undefined') return;-- const previousFocus =- document.activeElement instanceof HTMLElement ? document.activeElement : null;- lockBodyScroll();-- queueMicrotask(() => {- if (!panelRef) return;- const focusable = getFocusableElements(panelRef);- if (focusable.length > 0) {- focusable[0].focus();- return;- }- panelRef.focus();- });-- const onKeyDown = (event: KeyboardEvent) => {- if (!panelRef) return;- if (event.key === 'Escape') {- event.preventDefault();- props.onClose();- return;- }- if (event.key !== 'Tab') return;-- const focusable = getFocusableElements(panelRef);- if (focusable.length === 0) {- event.preventDefault();- panelRef.focus();- return;- }-- const first = focusable[0];- const last = focusable[focusable.length - 1];- const active = document.activeElement as HTMLElement | null;- const isOutside = !active || !panelRef.contains(active);-- if (event.shiftKey) {- if (active === first || isOutside) {- event.preventDefault();- last.focus();- }- return;- }-- if (active === last || isOutside) {- event.preventDefault();- first.focus();- }- };-- document.addEventListener('keydown', onKeyDown);- onCleanup(() => {- document.removeEventListener('keydown', onKeyDown);- unlockBodyScroll();- if (previousFocus && document.contains(previousFocus)) {- previousFocus.focus();- }- });- });-- const handleBackdropClick = () => {- if (props.closeOnBackdrop ?? true) {- props.onClose();- }- };-- const layout = () => props.layout ?? 'modal';+ const state = useDialogState(props);return (<Show when={props.isOpen}>@@ -123,37 +31,19 @@ export const Dialog: Component<DialogProps> = (props) => {<divclass="absolute inset-0 bg-black/60 backdrop-blur-sm transition-opacity duration-300"data-dialog-backdrop- onClick={handleBackdropClick}+ onClick={state.handleBackdropClick}/>- <div- class={`relative h-full overflow-y-auto pointer-events-none ${- layout() === 'drawer-right' ? 'p-0' : 'p-4 sm:p-6'- }`}- >- <div- class={`flex min-h-full ${- layout() === 'drawer-right'- ? 'items-stretch justify-end'- : 'items-start justify-center sm:items-center'- }`}- >+ <div class={getDialogViewportClass(state.layout())}>+ <div class={getDialogAlignmentClass(state.layout())}><div- ref={(el) => {- panelRef = el;- }}+ ref={state.setPanelRef}role="dialog"aria-modal="true"aria-label={props.ariaLabel}aria-labelledby={props.ariaLabelledBy}aria-describedby={props.ariaDescribedBy}tabindex="-1"- class={`relative flex w-full flex-col overflow-hidden bg-surface border border-border outline-none pointer-events-auto ${- layout() === 'drawer-right'- ? 'h-dvh max-w-[720px] rounded-none border-y-0 border-r-0 animate-slide-up sm:h-full sm:max-h-dvh sm:rounded-l-xl sm:border-y sm:border-r-0'- : 'max-h-[calc(100dvh-2rem)] rounded-md animate-slide-up'- } ${- props.panelClass ?? (layout() === 'drawer-right' ? '' : 'max-w-lg')- }`.trim()}+ class={getDialogPanelClass(state.layout(), props.panelClass)}onClick={(event) => event.stopPropagation()}>{props.children}diff --git a/frontend-modern/src/components/shared/SharedPrimitives.guardrails.test.ts b/frontend-modern/src/components/shared/SharedPrimitives.guardrails.test.tsindex 285f9bc6c0..acf18a0ab3 100644--- a/frontend-modern/src/components/shared/SharedPrimitives.guardrails.test.ts+++ b/frontend-modern/src/components/shared/SharedPrimitives.guardrails.test.ts@@ -8,6 +8,8 @@ import containerUpdateBadgeSource from '@/components/shared/ContainerUpdateBadgeimport containerUpdateBadgeModelSource from '@/components/shared/containerUpdateBadgeModel.ts?raw';import densityMapSource from '@/components/shared/DensityMap.tsx?raw';import densityMapModelSource from '@/components/shared/densityMapModel.ts?raw';+import dialogSource from '@/components/shared/Dialog.tsx?raw';+import dialogModelSource from '@/components/shared/dialogModel.ts?raw';import filterButtonGroupSource from '@/components/shared/FilterButtonGroup.tsx?raw';import helpIconSource from '@/components/shared/HelpIcon.tsx?raw';import helpIconModelSource from '@/components/shared/helpIconModel.ts?raw';@@ -43,6 +45,7 @@ import commandPaletteStateSource from '@/components/shared/useCommandPaletteStatimport collapsibleSearchInputStateSource from '@/components/shared/useCollapsibleSearchInputState.ts?raw';import containerUpdateButtonStateSource from '@/components/shared/useContainerUpdateButtonState.ts?raw';import densityMapStateSource from '@/components/shared/useDensityMapState.ts?raw';+import dialogStateSource from '@/components/shared/useDialogState.ts?raw';import helpIconStateSource from '@/components/shared/useHelpIconState.ts?raw';import historyChartStateSource from '@/components/shared/useHistoryChartState.ts?raw';import infrastructureDetailsDrawerStateSource from '@/components/shared/useInfrastructureDetailsDrawerState.ts?raw';@@ -260,6 +263,32 @@ describe('shared primitive guardrails', () => {expect(densityMapModelSource).toContain('getDensityMapCellOpacity');});+ it('keeps dialog on shell, runtime, and model owners', () => {+ expect(dialogSource).toContain('useDialogState');+ expect(dialogSource).toContain('getDialogViewportClass');+ expect(dialogSource).toContain('getDialogAlignmentClass');+ expect(dialogSource).toContain('getDialogPanelClass');+ expect(dialogSource).not.toContain('createEffect');+ expect(dialogSource).not.toContain('onCleanup');+ expect(dialogSource).not.toContain('FOCUSABLE_SELECTOR');+ expect(dialogSource).not.toContain('document.body.style.overflow');+ expect(dialogSource).not.toContain('querySelectorAll<HTMLElement>');++ expect(dialogStateSource).toContain('export function useDialogState');+ expect(dialogStateSource).toContain('createEffect');+ expect(dialogStateSource).toContain('onCleanup');+ expect(dialogStateSource).toContain('document.body.style.overflow');+ expect(dialogStateSource).toContain('openDialogCount');+ expect(dialogStateSource).toContain('getDialogFocusableElements');++ expect(dialogModelSource).toContain('export function getDialogLayout');+ expect(dialogModelSource).toContain('export function getDialogFocusableElements');+ expect(dialogModelSource).toContain('export function getDialogViewportClass');+ expect(dialogModelSource).toContain('export function getDialogAlignmentClass');+ expect(dialogModelSource).toContain('export function getDialogPanelClass');+ expect(dialogModelSource).toContain('FOCUSABLE_SELECTOR');+ });+it('keeps history chart on shell, runtime, and model owners', () => {expect(historyChartSource).toContain('useHistoryChartState');expect(historyChartSource).toContain('HistoryChartHeader');diff --git a/frontend-modern/src/components/shared/__tests__/Dialog.test.tsx b/frontend-modern/src/components/shared/__tests__/Dialog.test.tsxindex 80e1a98f99..c187baf92f 100644--- a/frontend-modern/src/components/shared/__tests__/Dialog.test.tsx+++ b/frontend-modern/src/components/shared/__tests__/Dialog.test.tsx@@ -1,6 +1,9 @@import { afterEach, describe, expect, it, vi } from 'vitest';import { cleanup, fireEvent, render, screen } from '@solidjs/testing-library';import { Dialog } from '@/components/shared/Dialog';+import dialogSource from '@/components/shared/Dialog.tsx?raw';+import dialogModelSource from '@/components/shared/dialogModel.ts?raw';+import dialogStateSource from '@/components/shared/useDialogState.ts?raw';describe('Dialog', () => {afterEach(() => {@@ -8,6 +11,32 @@ describe('Dialog', () => {document.body.style.overflow = '';});+ it('keeps dialog on shell, runtime, and model owners', () => {+ expect(dialogSource).toContain('useDialogState');+ expect(dialogSource).toContain('getDialogViewportClass');+ expect(dialogSource).toContain('getDialogAlignmentClass');+ expect(dialogSource).toContain('getDialogPanelClass');+ expect(dialogSource).not.toContain('createEffect');+ expect(dialogSource).not.toContain('onCleanup');+ expect(dialogSource).not.toContain('FOCUSABLE_SELECTOR');+ expect(dialogSource).not.toContain('document.body.style.overflow');+ expect(dialogSource).not.toContain('querySelectorAll<HTMLElement>');++ expect(dialogStateSource).toContain('export function useDialogState');+ expect(dialogStateSource).toContain('createEffect');+ expect(dialogStateSource).toContain('onCleanup');+ expect(dialogStateSource).toContain('document.body.style.overflow');+ expect(dialogStateSource).toContain('openDialogCount');+ expect(dialogStateSource).toContain('getDialogFocusableElements');++ expect(dialogModelSource).toContain('export function getDialogLayout');+ expect(dialogModelSource).toContain('export function getDialogFocusableElements');+ expect(dialogModelSource).toContain('export function getDialogViewportClass');+ expect(dialogModelSource).toContain('export function getDialogAlignmentClass');+ expect(dialogModelSource).toContain('export function getDialogPanelClass');+ expect(dialogModelSource).toContain('FOCUSABLE_SELECTOR');+ });+it('renders as a modal dialog and closes on backdrop click', () => {const onClose = vi.fn();render(() => (diff --git a/frontend-modern/src/components/shared/dialogModel.ts b/frontend-modern/src/components/shared/dialogModel.tsnew file mode 100644index 0000000000..0588449a9a--- /dev/null+++ b/frontend-modern/src/components/shared/dialogModel.ts@@ -0,0 +1,37 @@+export type DialogLayout = 'modal' | 'drawer-right';++const FOCUSABLE_SELECTOR =+ 'a[href],area[href],button:not([disabled]),input:not([disabled]):not([type="hidden"]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])';++export function getDialogLayout(layout?: DialogLayout): DialogLayout {+ return layout ?? 'modal';+}++export function getDialogFocusableElements(container: HTMLElement): HTMLElement[] {+ return Array.from(container.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR)).filter(+ (element) =>+ !element.hasAttribute('disabled') && element.getAttribute('aria-hidden') !== 'true',+ );+}++export function getDialogViewportClass(layout: DialogLayout): string {+ return `relative h-full overflow-y-auto pointer-events-none ${+ layout === 'drawer-right' ? 'p-0' : 'p-4 sm:p-6'+ }`;+}++export function getDialogAlignmentClass(layout: DialogLayout): string {+ return `flex min-h-full ${+ layout === 'drawer-right'+ ? 'items-stretch justify-end'+ : 'items-start justify-center sm:items-center'+ }`;+}++export function getDialogPanelClass(layout: DialogLayout, panelClass?: string): string {+ return `relative flex w-full flex-col overflow-hidden bg-surface border border-border outline-none pointer-events-auto ${+ layout === 'drawer-right'+ ? 'h-dvh max-w-[720px] rounded-none border-y-0 border-r-0 animate-slide-up sm:h-full sm:max-h-dvh sm:rounded-l-xl sm:border-y sm:border-r-0'+ : 'max-h-[calc(100dvh-2rem)] rounded-md animate-slide-up'+ } ${panelClass ?? (layout === 'drawer-right' ? '' : 'max-w-lg')}`.trim();+}diff --git a/frontend-modern/src/components/shared/useDialogState.ts b/frontend-modern/src/components/shared/useDialogState.tsnew file mode 100644index 0000000000..c924e30178--- /dev/null+++ b/frontend-modern/src/components/shared/useDialogState.ts@@ -0,0 +1,116 @@+import { createEffect, onCleanup } from 'solid-js';+import type { Accessor } from 'solid-js';+import {+ getDialogFocusableElements,+ getDialogLayout,+ type DialogLayout,+} from './dialogModel';++interface DialogStateOptions {+ closeOnBackdrop?: boolean;+ isOpen: boolean;+ layout?: DialogLayout;+ onClose: () => void;+}++let openDialogCount = 0;+let previousBodyOverflow = '';++function lockBodyScroll() {+ if (typeof document === 'undefined') return;+ if (openDialogCount === 0) {+ previousBodyOverflow = document.body.style.overflow;+ document.body.style.overflow = 'hidden';+ }+ openDialogCount += 1;+}++function unlockBodyScroll() {+ if (typeof document === 'undefined') return;+ openDialogCount = Math.max(0, openDialogCount - 1);+ if (openDialogCount === 0) {+ document.body.style.overflow = previousBodyOverflow;+ }+}++export function useDialogState(options: DialogStateOptions): {+ handleBackdropClick: () => void;+ layout: Accessor<DialogLayout>;+ setPanelRef: (el: HTMLDivElement) => void;+} {+ let panelRef: HTMLDivElement | undefined;++ createEffect(() => {+ if (!options.isOpen || typeof document === 'undefined') return;++ const previousFocus =+ document.activeElement instanceof HTMLElement ? document.activeElement : null;+ lockBodyScroll();++ queueMicrotask(() => {+ if (!panelRef) return;+ const focusable = getDialogFocusableElements(panelRef);+ if (focusable.length > 0) {+ focusable[0].focus();+ return;+ }+ panelRef.focus();+ });++ const onKeyDown = (event: KeyboardEvent) => {+ if (!panelRef) return;+ if (event.key === 'Escape') {+ event.preventDefault();+ options.onClose();+ return;+ }+ if (event.key !== 'Tab') return;++ const focusable = getDialogFocusableElements(panelRef);+ if (focusable.length === 0) {+ event.preventDefault();+ panelRef.focus();+ return;+ }++ const first = focusable[0];+ const last = focusable[focusable.length - 1];+ const active = document.activeElement as HTMLElement | null;+ const isOutside = !active || !panelRef.contains(active);++ if (event.shiftKey) {+ if (active === first || isOutside) {+ event.preventDefault();+ last.focus();+ }+ return;+ }++ if (active === last || isOutside) {+ event.preventDefault();+ first.focus();+ }+ };++ document.addEventListener('keydown', onKeyDown);+ onCleanup(() => {+ document.removeEventListener('keydown', onKeyDown);+ unlockBodyScroll();+ if (previousFocus && document.contains(previousFocus)) {+ previousFocus.focus();+ }+ });+ });++ return {+ handleBackdropClick: () => {+ if (options.closeOnBackdrop ?? true) {+ options.onClose();+ }+ },+ layout: () => getDialogLayout(options.layout),+ setPanelRef: (el) => {+ panelRef = el;+ },+ };+}diff --git a/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts b/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.tsindex 4f1dc53566..3b5d712582 100644--- a/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts+++ b/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts@@ -16,6 +16,8 @@ import containerUpdateBadgeSource from '@/components/shared/ContainerUpdateBadgeimport containerUpdateBadgeModelSource from '@/components/shared/containerUpdateBadgeModel.ts?raw';import densityMapSource from '@/components/shared/DensityMap.tsx?raw';import densityMapModelSource from '@/components/shared/densityMapModel.ts?raw';+import dialogSource from '@/components/shared/Dialog.tsx?raw';+import dialogModelSource from '@/components/shared/dialogModel.ts?raw';import helpIconSource from '@/components/shared/HelpIcon.tsx?raw';import helpIconModelSource from '@/components/shared/helpIconModel.ts?raw';import historyChartHeaderSource from '@/components/shared/HistoryChartHeader.tsx?raw';@@ -43,6 +45,7 @@ import sharedInfrastructureSummaryTableModelSource from '@/components/shared/infimport commandPaletteStateSource from '@/components/shared/useCommandPaletteState.ts?raw';import collapsibleSearchInputStateSource from '@/components/shared/useCollapsibleSearchInputState.ts?raw';import containerUpdateButtonStateSource from '@/components/shared/useContainerUpdateButtonState.ts?raw';+import dialogStateSource from '@/components/shared/useDialogState.ts?raw';import helpIconStateSource from '@/components/shared/useHelpIconState.ts?raw';import historyChartStateSource from '@/components/shared/useHistoryChartState.ts?raw';import mobileNavBarStateSource from '@/components/shared/useMobileNavBarState.ts?raw';@@ -2699,6 +2702,21 @@ describe('frontend resource type boundaries', () => {expect(tooltipStateSource).toContain('resolveTooltipPosition');expect(tooltipModelSource).toContain('sanitizeTooltipContent');expect(tooltipModelSource).toContain('resolveTooltipPosition');+ expect(dialogSource).toContain('useDialogState');+ expect(dialogSource).toContain('getDialogViewportClass');+ expect(dialogSource).toContain('getDialogAlignmentClass');+ expect(dialogSource).toContain('getDialogPanelClass');+ expect(dialogSource).not.toContain('createEffect');+ expect(dialogSource).not.toContain('document.body.style.overflow');+ expect(dialogSource).not.toContain('FOCUSABLE_SELECTOR');+ expect(dialogStateSource).toContain('createEffect');+ expect(dialogStateSource).toContain('onCleanup');+ expect(dialogStateSource).toContain('document.body.style.overflow');+ expect(dialogStateSource).toContain('getDialogFocusableElements');+ expect(dialogModelSource).toContain('getDialogFocusableElements');+ expect(dialogModelSource).toContain('getDialogViewportClass');+ expect(dialogModelSource).toContain('getDialogAlignmentClass');+ expect(dialogModelSource).toContain('getDialogPanelClass');expect(collapsibleSearchInputSource).toContain('useCollapsibleSearchInputState');expect(collapsibleSearchInputSource).not.toContain('createSignal');expect(collapsibleSearchInputSource).not.toContain('useTypeToSearch');