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.

Keep health-filter focus when live counts change

pulse-triage[bot]2afa7b9989ca
diff --git a/docs/release-control/v6/internal/subsystems/frontend-primitives.md b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
index 7f146b7531..863262db0c 100644
--- a/docs/release-control/v6/internal/subsystems/frontend-primitives.md
+++ b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
@@ -4548,7 +4548,16 @@ the existing danger precedence. Muted/unclassified rows stay in All only.
The status dot tooltip and accessible name expose that same current label
(Online, Stale or Offline), not an online tooltip on an amber retained row.
The canonical status, stale flag and timestamps remain observations, not derived
-health. Search, focus, route-owned selection and removal behaviour are unchanged.
+health. Search, route-owned selection and removal behaviour are unchanged.
+The shared FilterButtonGroup keys buttons by logical value rather than transient
+option-object identity. Count, label, disabled, icon and order updates keep the
+same focused button while its option survives; withdrawn keys retire normally.
+Numeric and string values stay distinct, and selection uses the current entry.
+FilterButtonGroup.test.tsx covers those replacement/reorder/removal boundaries;
+FilterToolbar.test.tsx covers the live segmented-control label projection and
+forwarded selection at the shared wrapper boundary;
+the Machines clock/selection control exercises the production toolbar on desktop
+and touch-phone browsers.
Attention sort classifies once per resource per call, preserving priority and
numeric-name ordering without keeping a cross-call status cache. Debug source
summaries read current status/error/last-seen by section ID, not a record captured
diff --git a/frontend-modern/browser-tests/machines-health-filters.cjs b/frontend-modern/browser-tests/machines-health-filters.cjs
index cd784fea98..e29d10185b 100644
--- a/frontend-modern/browser-tests/machines-health-filters.cjs
+++ b/frontend-modern/browser-tests/machines-health-filters.cjs
@@ -228,6 +228,33 @@ const hash = (p) => crypto.createHash('sha256').update(fs.readFileSync(p)).diges
await page.waitForURL((url) => url.searchParams.get('status') === 'degraded');
assert.equal(await row.count(), binding.mode === 'parent' ? 0 : 1);
await capture('withdrawn-degraded');
+ // Counts update on quiet clock ticks too: the selected logical button
+ // must retain keyboard focus even when its row leaves the filter.
+ await page.evaluate(() => window.__healthFilters.report());
+ await button('Healthy').click();
+ await page.waitForURL((url) => url.searchParams.get('status') === 'online');
+ await page.clock.runFor(1000); // Settle ordinary source metadata refresh.
+ await button('Healthy').focus();
+ await button('Healthy').evaluate((el) => {
+ window.__focusedHealthButton = el;
+ });
+ const focusReads = record.reads.length;
+ await page.clock.runFor(299000);
+ await counts(1, 0);
+ await page.clock.runFor(30000);
+ await counts(0, 1);
+ assert.equal(await row.count(), 0);
+ const focus = await page.evaluate(() => ({
+ originalButtonConnected: window.__focusedHealthButton.isConnected,
+ focusRetained: document.activeElement === window.__focusedHealthButton,
+ currentFocusTag: document.activeElement.tagName,
+ }));
+ assert.equal(focus.originalButtonConnected, binding.focus_expected);
+ assert.equal(focus.focusRetained, binding.focus_expected);
+ assert.equal(record.reads.length, focusReads);
+ assert.equal(new URL(page.url()).searchParams.get('status'), 'online');
+ record.focusCheck = { ...focus, clockReads: 0, selectedHealthyEmpty: true };
+ await capture('focused-health-clock');
assert.equal(record.reads.filter((p) => p === '/api/resources').length, 1);
record.sourceUpdateReads = record.reads.slice(reads);
for (const p of record.sourceUpdateReads) assert.equal(p, '/api/agents/metadata');
diff --git a/frontend-modern/browser-verification/fe8e1c696bec46ce.json b/frontend-modern/browser-verification/fe8e1c696bec46ce.json
new file mode 100644
index 0000000000..20402f1d1a
--- /dev/null
+++ b/frontend-modern/browser-verification/fe8e1c696bec46ce.json
@@ -0,0 +1,36 @@
+{
+ "version": 1,
+ "base_sha": "d1842b98f2b8753e097a608db6545095901bfec9",
+ "verified_at": "2026-10-11T19:44:01.301539Z",
+ "result": "passed",
+ "changed_paths": [
+ "frontend-modern/src/components/shared/FilterButtonGroup.tsx"
+ ],
+ "content_sha256": {
+ "frontend-modern/src/components/shared/FilterButtonGroup.tsx": "1d44ab764a9a30af38780a3424e0bd5026a332ef09a42f437ae1693ddf4cd7b9"
+ },
+ "routes": [
+ "/browser-tests/machines-health-filters.html, using production StandalonePageSurface/router/table/shared filters and q/status state; synthetic local evidence, not a new application route"
+ ],
+ "viewports": [
+ {
+ "width": 1680,
+ "height": 950
+ },
+ {
+ "width": 390,
+ "height": 950
+ }
+ ],
+ "states": [
+ "Playwright 1.56.1 matches the integration lock. Desktop Chromium 141.0.7390.37 light and dark touch-phone WebKit 26.0; exact d1842b98 parent and final runtime hashes checked. All twenty-four settled parent/final screenshots inspected.",
+ "After selecting and focusing Healthy, report age exactly five minutes remains Healthy. The next shared-clock tick changes Healthy 1 to 0 and Degraded 0 to 1, and correctly removes the held row. Parent disconnects the button and drops focus to BODY. Final keeps the same connected button and its focus, retaining the selected filter and identity search. Both quiet-clock controls perform no read/write.",
+ "Healthy/Degraded accessible counts agree with current row status and actual selected membership. The retained snapshot is unchanged by the clock. Arrival and explicit withdrawal update membership, and Stale is the accessible status name and tooltip. Unknown/offline and disabled/reordered/withdrawn keys remain source-test boundaries, not native acceptance.",
+ "No unexpected read, write, off-origin request, page or console error, or page-level horizontal overflow; normal source-update metadata revalidation is preserved. Both browser and server close. Synthetic browser evidence is not a full application, physical device, guest thaw/writes/liveness/restoration, native recovery, publication or release."
+ ],
+ "interactions": [
+ "Expand phone Filters, enter identity search, select Healthy and Degraded, inspect rows and filtered-empty states; route-owned q/status remain.",
+ "Focus the selected Healthy button before quiet clock advancement; record the same button identity and document.activeElement before and after count replacement.",
+ "Inject an arriving ordinary report, then a stale/withdrawn-report observation, without changing canonical status, thresholds or polling."
+ ]
+}
diff --git a/frontend-modern/src/components/shared/FilterButtonGroup.test.tsx b/frontend-modern/src/components/shared/FilterButtonGroup.test.tsx
index 3c73a5e58b..9a4bb4079b 100644
--- a/frontend-modern/src/components/shared/FilterButtonGroup.test.tsx
+++ b/frontend-modern/src/components/shared/FilterButtonGroup.test.tsx
@@ -1,7 +1,9 @@
import { cleanup, fireEvent, render, screen, within } from '@solidjs/testing-library';
import { afterEach, describe, expect, it, vi } from 'vitest';
import Sun from 'lucide-solid/icons/sun';
-import { FilterButtonGroup } from './FilterButtonGroup';
+import Moon from 'lucide-solid/icons/moon';
+import { createSignal } from 'solid-js';
+import { FilterButtonGroup, type FilterOption } from './FilterButtonGroup';
import filterButtonGroupSource from './FilterButtonGroup.tsx?raw';
import filterButtonGroupModelSource from './filterButtonGroupModel.ts?raw';
import filterButtonGroupStateSource from './useFilterButtonGroupState.ts?raw';
@@ -68,6 +70,72 @@ describe('FilterButtonGroup', () => {
expect(onChange).toHaveBeenCalledWith('dark');
});
+ it('keeps logical button identity and focus while counts, order and metadata change', () => {
+ const [options, setOptions] = createSignal<FilterOption<string>[]>([
+ { value: 'all', label: 'All', count: 1 },
+ { value: 'online', label: 'Healthy', count: 1, icon: Sun },
+ { value: 'degraded', label: 'Degraded', count: 0 },
+ ]);
+ const [value, setValue] = createSignal('online');
+ const onChange = vi.fn();
+ render(() => <FilterButtonGroup options={options()} value={value()} onChange={onChange} />);
+ const healthy = screen.getByRole('button', { name: 'Healthy, 1' });
+ const oldIcon = healthy.querySelector('svg');
+ healthy.focus();
+ setOptions([
+ { value: 'degraded', label: 'Needs attention', count: 2 },
+ {
+ value: 'online',
+ label: 'Fresh',
+ count: 0,
+ icon: Moon,
+ title: 'Current report',
+ },
+ { value: 'all', label: 'All', count: 2 },
+ ]);
+ expect(screen.getByRole('button', { name: 'Fresh, 0' })).toBe(healthy);
+ expect(document.activeElement).toBe(healthy);
+ expect(healthy).toHaveAttribute('title', 'Current report');
+ expect(healthy).not.toBeDisabled();
+ expect(healthy.querySelector('svg')).not.toBe(oldIcon);
+ expect(
+ screen.getAllByRole('button').map((button) => button.getAttribute('aria-label')),
+ ).toEqual(['Needs attention, 2', 'Fresh, 0', 'All, 2']);
+ setOptions(options().map((option) => ({ ...option, disabled: true })));
+ expect(screen.getByRole('button', { name: 'Fresh, 0' })).toBe(healthy);
+ expect(healthy).toBeDisabled();
+ fireEvent.click(healthy);
+ expect(onChange).not.toHaveBeenCalled();
+
+ setOptions(options().map((option) => ({ ...option, disabled: false, icon: undefined })));
+ setValue('degraded');
+ expect(healthy).toHaveAttribute('aria-pressed', 'false');
+ expect(healthy.querySelector('svg')).toBeNull();
+ fireEvent.click(healthy);
+ expect(onChange).toHaveBeenCalledExactlyOnceWith('online');
+ setOptions(options().filter((option) => option.value !== 'online'));
+ expect(healthy.isConnected).toBe(false);
+ expect(screen.queryByRole('button', { name: 'Fresh, 0' })).toBeNull();
+ });
+
+ it('keeps numeric and string values distinct during replacement and reordering', () => {
+ const [options, setOptions] = createSignal<FilterOption<number | string>[]>([
+ { value: 0, label: 'Number', count: 1 },
+ { value: '0', label: 'String', count: 2 },
+ ]);
+ render(() => <FilterButtonGroup options={options()} value={0} onChange={() => undefined} />);
+ const number = screen.getByRole('button', { name: 'Number, 1' });
+ const string = screen.getByRole('button', { name: 'String, 2' });
+ setOptions([
+ { value: '0', label: 'String', count: 3 },
+ { value: 0, label: 'Number', count: 4 },
+ ]);
+ expect(screen.getByRole('button', { name: 'Number, 4' })).toBe(number);
+ expect(screen.getByRole('button', { name: 'String, 3' })).toBe(string);
+ expect(number).toHaveAttribute('aria-pressed', 'true');
+ expect(string).toHaveAttribute('aria-pressed', 'false');
+ });
+
it('renders an optional count directly beside its label', () => {
render(() => (
<FilterButtonGroup
diff --git a/frontend-modern/src/components/shared/FilterButtonGroup.tsx b/frontend-modern/src/components/shared/FilterButtonGroup.tsx
index fd48011f61..35c24e8a27 100644
--- a/frontend-modern/src/components/shared/FilterButtonGroup.tsx
+++ b/frontend-modern/src/components/shared/FilterButtonGroup.tsx
@@ -1,4 +1,5 @@
-import { For, Show, splitProps } from 'solid-js';
+import { For, Show, createMemo, splitProps } from 'solid-js';
+import { Dynamic } from 'solid-js/web';
import {
getFilterButtonGroupButtonClass,
getFilterButtonGroupClass,
@@ -26,6 +27,11 @@ export function FilterButtonGroup<T extends string | number>(props: FilterButton
'disabled',
]);
const filterButtonGroup = useFilterButtonGroupState(props);
+ // Counts/labels are refreshed by callers with new option objects. The
+ // logical value owns the button, so those updates cannot discard focus.
+ const optionsByValue = createMemo(
+ () => new Map(local.options.map((option) => [option.value, option] as const)),
+ );
const groupLabel = () => local.ariaLabel ?? divProps['aria-label'] ?? 'Filter Options';
return (
@@ -40,10 +46,23 @@ export function FilterButtonGroup<T extends string | number>(props: FilterButton
{local.label}
</span>
</Show>
- <For each={local.options}>
- {(option) => {
- const Icon = option.icon;
- const renderedLabel = () => option.visualLabel ?? option.label;
+ <For each={[...optionsByValue().keys()]}>
+ {(value) => {
+ const initialOption = optionsByValue().get(value)!;
+ // Keep a retiring child safe until For removes its withdrawn key.
+ const option = () => optionsByValue().get(value) ?? initialOption;
+ const renderedLabel = () => option().visualLabel ?? option().label;
+ const accessibleLabel = () => {
+ const entry = option();
+ return (
+ entry.ariaLabel ??
+ (entry.visualLabel
+ ? undefined
+ : entry.count === undefined
+ ? entry.label
+ : `${entry.label}, ${entry.count.toLocaleString()}`)
+ );
+ };
const iconClass = () =>
filterButtonGroup.variant() === 'compact'
? 'h-3 w-3'
@@ -52,49 +71,44 @@ export function FilterButtonGroup<T extends string | number>(props: FilterButton
return (
<button
type="button"
- aria-label={
- option.ariaLabel ??
- (option.visualLabel
- ? undefined
- : option.count === undefined
- ? option.label
- : `${option.label}, ${option.count.toLocaleString()}`)
- }
- title={option.title}
- onClick={() => filterButtonGroup.handleOptionClick(option)}
+ aria-label={accessibleLabel()}
+ title={option().title}
+ onClick={() => filterButtonGroup.handleOptionClick(option())}
class={getFilterButtonGroupButtonClass(
filterButtonGroup.variant(),
- filterButtonGroup.isOptionActive(option),
- filterButtonGroup.isOptionDisabled(option),
- option.tone,
+ filterButtonGroup.isOptionActive(option()),
+ filterButtonGroup.isOptionDisabled(option()),
+ option().tone,
)}
- aria-pressed={filterButtonGroup.isOptionActive(option)}
- disabled={filterButtonGroup.isOptionDisabled(option)}
+ aria-pressed={filterButtonGroup.isOptionActive(option())}
+ disabled={filterButtonGroup.isOptionDisabled(option())}
>
- {option.leading}
- {Icon && <Icon class={iconClass()} />}
+ {option().leading}
+ <Show when={option().icon}>
+ {(Icon) => <Dynamic component={Icon()} class={iconClass()} />}
+ </Show>
<span class="inline-flex items-baseline gap-1.5 whitespace-nowrap">
<Show
- when={option.visualLabel}
+ when={option().visualLabel}
fallback={
filterButtonGroup.variant() === 'prominent' ? (
- <span>{option.label}</span>
+ <span>{option().label}</span>
) : (
<>
- <span class="hidden sm:inline">{option.label}</span>
- <span class="sm:hidden">{getFilterButtonGroupCompactLabel(option)}</span>
+ <span class="hidden sm:inline">{option().label}</span>
+ <span class="sm:hidden">{getFilterButtonGroupCompactLabel(option())}</span>
</>
)
}
>
<span>{renderedLabel()}</span>
</Show>
- <Show when={option.count !== undefined}>
+ <Show when={option().count !== undefined}>
<span
class="inline-block text-[11px] font-semibold leading-4 tabular-nums"
aria-hidden="true"
>
- {option.count!.toLocaleString()}
+ {option().count!.toLocaleString()}
</span>
</Show>
</span>
diff --git a/frontend-modern/src/components/shared/FilterToolbar.test.tsx b/frontend-modern/src/components/shared/FilterToolbar.test.tsx
index 0eddf84091..88fa9b68a5 100644
--- a/frontend-modern/src/components/shared/FilterToolbar.test.tsx
+++ b/frontend-modern/src/components/shared/FilterToolbar.test.tsx
@@ -65,6 +65,50 @@ describe('FilterHeader', () => {
expect(onChange).toHaveBeenCalledWith('warnings');
});
+ it('preserves segmented-control focus and selection across live label projections', () => {
+ const [healthyCount, setHealthyCount] = createSignal(1);
+ const [selected, setSelected] = createSignal('online');
+ const onChange = vi.fn();
+ render(() => (
+ <FilterSegmentedControl
+ value={selected()}
+ onChange={(next) => {
+ setSelected(next);
+ onChange(next);
+ }}
+ options={[
+ {
+ value: 'online',
+ label: <span>Healthy {healthyCount()}</span>,
+ ariaLabel: `Healthy, ${healthyCount()}`,
+ },
+ {
+ value: 'degraded',
+ label: <span>Degraded {1 - healthyCount()}</span>,
+ ariaLabel: `Degraded, ${1 - healthyCount()}`,
+ },
+ ]}
+ />
+ ));
+ const healthy = screen.getByRole('button', { name: 'Healthy, 1' });
+ const degraded = screen.getByRole('button', { name: 'Degraded, 0' });
+ healthy.focus();
+ setHealthyCount(0);
+ expect(screen.getByRole('button', { name: 'Healthy, 0' })).toBe(healthy);
+ expect(healthy).toHaveTextContent('Healthy 0');
+ expect(document.activeElement).toBe(healthy);
+ expect(healthy).toHaveAttribute('aria-pressed', 'true');
+ degraded.click();
+ expect(onChange).toHaveBeenCalledExactlyOnceWith('degraded');
+ expect(healthy).toHaveAttribute('aria-pressed', 'false');
+ expect(degraded).toHaveAttribute('aria-pressed', 'true');
+ degraded.focus();
+ setHealthyCount(1);
+ expect(screen.getByRole('button', { name: 'Degraded, 0' })).toBe(degraded);
+ expect(document.activeElement).toBe(degraded);
+ expect(degraded).toHaveAttribute('aria-pressed', 'true');
+ });
+
it('uses labeled toggle groups for compact stable filter choices', () => {
const onChange = vi.fn();
render(() => (