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.

Make alert frequency periods accessible

pulse-triage[bot]4651fae79edb
diff --git a/frontend-modern/src/features/alerts/AlertHistoryFrequencyCard.tsx b/frontend-modern/src/features/alerts/AlertHistoryFrequencyCard.tsx
index 04d888b75b..650e77f7fa 100644
--- a/frontend-modern/src/features/alerts/AlertHistoryFrequencyCard.tsx
+++ b/frontend-modern/src/features/alerts/AlertHistoryFrequencyCard.tsx
@@ -96,117 +96,125 @@ export function AlertHistoryFrequencyCard(props: AlertHistoryFrequencyCardProps)
{(() => {
const trends = props.state.alertTrends();
return (
- <div class="rounded bg-surface-alt p-1">
- <div class="flex h-12 items-end gap-1">
- {trends.buckets.map((value, index) => {
- const scaledHeight =
- value > 0 ? Math.min(100, Math.max(20, Math.log(value + 1) * 20)) : 0;
- const pixelHeight = value > 0 ? Math.max(8, (scaledHeight / 100) * 40) : 0;
- const isSelected = props.state.selectedBarIndex() === index;
- const bucketStart = trends.bucketTimes[index];
- const bucketEnd = bucketStart + trends.bucketSize * MS_PER_HOUR;
- const bucketRangeLabel = props.state.formatBucketRange(bucketStart, bucketEnd);
- const bucketDurationText =
- trends.bucketSize % 24 === 0
- ? `${trends.bucketSize / 24} day${trends.bucketSize / 24 === 1 ? '' : 's'}`
- : `${trends.bucketSize} hour${trends.bucketSize === 1 ? '' : 's'}`;
- const countLabel = getAlertBucketCountLabel(value);
- const tooltipContent = [
- countLabel,
- `${bucketDurationText} period`,
- bucketRangeLabel,
- ].join('\n');
+ <div
+ data-alert-frequency-scroll
+ class="overflow-x-auto pb-1"
+ role="group"
+ aria-label="Filter alert history by time period"
+ >
+ {/*
+ Keep each period at least 24 CSS pixels wide. On compact cards the
+ chart and its axis scroll as one surface instead of compressing
+ dozens of pointer targets below the WCAG 2.2 minimum target size.
+ */}
+ <div class="w-max min-w-full">
+ <div class="rounded bg-surface-alt p-1">
+ <div class="flex h-12 items-end gap-1">
+ {trends.buckets.map((value, index) => {
+ const scaledHeight =
+ value > 0 ? Math.min(100, Math.max(20, Math.log(value + 1) * 20)) : 0;
+ const pixelHeight = value > 0 ? Math.max(8, (scaledHeight / 100) * 40) : 0;
+ const isSelected = () => props.state.selectedBarIndex() === index;
+ const bucketStart = trends.bucketTimes[index];
+ const bucketEnd = bucketStart + trends.bucketSize * MS_PER_HOUR;
+ const bucketRangeLabel = props.state.formatBucketRange(bucketStart, bucketEnd);
+ const bucketDurationText =
+ trends.bucketSize % 24 === 0
+ ? `${trends.bucketSize / 24} day${trends.bucketSize / 24 === 1 ? '' : 's'}`
+ : `${trends.bucketSize} hour${trends.bucketSize === 1 ? '' : 's'}`;
+ const countLabel = getAlertBucketCountLabel(value);
+ const tooltipContent = [
+ countLabel,
+ `${bucketDurationText} period`,
+ bucketRangeLabel,
+ ].join('\n');
- return (
- <div
- class="relative flex flex-1 cursor-pointer items-end"
- role="button"
- tabIndex={0}
- aria-pressed={isSelected}
- aria-label={`${countLabel} between ${bucketRangeLabel}`}
- onClick={() =>
- props.state.setSelectedBarIndex(
- index === props.state.selectedBarIndex() ? null : index,
- )
- }
- onKeyDown={(event) => {
- if (event.key === 'Enter' || event.key === ' ') {
- event.preventDefault();
- props.state.setSelectedBarIndex(
- index === props.state.selectedBarIndex() ? null : index,
- );
- }
- }}
- >
- <div class="absolute bottom-0 h-1 w-full rounded-full bg-slate-300 opacity-30"></div>
- <div
- class="relative w-full rounded-sm transition-all"
- style={{
- height: `${pixelHeight}px`,
- 'background-color':
- value > 0 ? (isSelected ? '#2563eb' : '#3b82f6') : 'transparent',
- opacity: isSelected ? '1' : '0.8',
- 'box-shadow': isSelected ? '0 0 0 2px rgba(37, 99, 235, 0.4)' : 'none',
- }}
- title={bucketRangeLabel}
- onMouseEnter={(event) => {
- if (value <= 0) {
- hideTooltip();
- return;
+ return (
+ <button
+ type="button"
+ data-alert-frequency-bucket={index}
+ class="relative flex h-12 min-w-6 flex-1 cursor-pointer items-end rounded-sm focus:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-inset"
+ aria-pressed={isSelected()}
+ aria-label={`${countLabel} between ${bucketRangeLabel}`}
+ onClick={() =>
+ props.state.setSelectedBarIndex(
+ index === props.state.selectedBarIndex() ? null : index,
+ )
}
- const rect = (event.currentTarget as HTMLElement).getBoundingClientRect();
- showTooltip(tooltipContent, rect.left + rect.width / 2, rect.top, {
- align: 'center',
- direction: 'up',
- });
- }}
- onMouseLeave={() => hideTooltip()}
- />
- </div>
- );
- })}
- </div>
- </div>
- );
- })()}
+ >
+ <span class="absolute bottom-0 h-1 w-full rounded-full bg-slate-300 opacity-30"></span>
+ <span
+ class="relative w-full rounded-sm transition-all"
+ style={{
+ height: `${pixelHeight}px`,
+ 'background-color':
+ value > 0 ? (isSelected() ? '#2563eb' : '#3b82f6') : 'transparent',
+ opacity: isSelected() ? '1' : '0.8',
+ 'box-shadow': isSelected()
+ ? '0 0 0 2px rgba(37, 99, 235, 0.4)'
+ : 'none',
+ }}
+ title={bucketRangeLabel}
+ onMouseEnter={(event) => {
+ if (value <= 0) {
+ hideTooltip();
+ return;
+ }
+ const rect = event.currentTarget.getBoundingClientRect();
+ showTooltip(tooltipContent, rect.left + rect.width / 2, rect.top, {
+ align: 'center',
+ direction: 'up',
+ });
+ }}
+ onMouseLeave={() => hideTooltip()}
+ />
+ </button>
+ );
+ })}
+ </div>
+ </div>
- <Show when={props.state.axisTicks().length > 0}>
- <div class="relative mt-3 h-10">
- <div class="absolute inset-x-0 top-0 h-px bg-surface-hover"></div>
- <For each={props.state.axisTicks()}>
- {(tick, index) => {
- const lastIndex = props.state.axisTicks().length - 1;
- const mobileMidpoint = Math.floor(lastIndex / 2);
- const visibleOnMobile =
- index() === 0 || index() === mobileMidpoint || index() === lastIndex;
+ <Show when={props.state.axisTicks().length > 0}>
+ <div class="relative mt-3 h-10">
+ <div class="absolute inset-x-0 top-0 h-px bg-surface-hover"></div>
+ <For each={props.state.axisTicks()}>
+ {(tick, index) => {
+ const lastIndex = props.state.axisTicks().length - 1;
+ const mobileMidpoint = Math.floor(lastIndex / 2);
+ const visibleOnMobile =
+ index() === 0 || index() === mobileMidpoint || index() === lastIndex;
- return (
- <div
- data-testid="alert-frequency-axis-tick"
- class="pointer-events-none absolute top-0 h-full flex-col items-center sm:flex"
- classList={{
- hidden: !visibleOnMobile,
- flex: visibleOnMobile,
- }}
- style={{ left: `${tick.position * 100}%` }}
- >
- <div class="h-3 w-px bg-slate-300"></div>
- <div
- data-testid="alert-frequency-axis-label"
- class="mt-1 whitespace-nowrap text-[10px] text-muted transform"
- classList={{
- '-translate-x-1/2': tick.align === 'center',
- '-translate-x-full': tick.align === 'end',
+ return (
+ <div
+ data-testid="alert-frequency-axis-tick"
+ class="pointer-events-none absolute top-0 h-full flex-col items-center sm:flex"
+ classList={{
+ hidden: !visibleOnMobile,
+ flex: visibleOnMobile,
+ }}
+ style={{ left: `${tick.position * 100}%` }}
+ >
+ <div class="h-3 w-px bg-slate-300"></div>
+ <div
+ data-testid="alert-frequency-axis-label"
+ class="mt-1 whitespace-nowrap text-[10px] text-muted transform"
+ classList={{
+ '-translate-x-1/2': tick.align === 'center',
+ '-translate-x-full': tick.align === 'end',
+ }}
+ >
+ {tick.label}
+ </div>
+ </div>
+ );
}}
- >
- {tick.label}
- </div>
+ </For>
</div>
- );
- }}
- </For>
- </div>
- </Show>
+ </Show>
+ </div>
+ </div>
+ );
+ })()}
</Card>
);
}
diff --git a/frontend-modern/src/features/alerts/__tests__/AlertHistoryFrequencyCard.test.tsx b/frontend-modern/src/features/alerts/__tests__/AlertHistoryFrequencyCard.test.tsx
new file mode 100644
index 0000000000..441fcb5bf4
--- /dev/null
+++ b/frontend-modern/src/features/alerts/__tests__/AlertHistoryFrequencyCard.test.tsx
@@ -0,0 +1,88 @@
+import { cleanup, fireEvent, render, screen } from '@solidjs/testing-library';
+import { createSignal } from 'solid-js';
+import { afterEach, describe, expect, it } from 'vitest';
+
+import { AlertHistoryFrequencyCard } from '../AlertHistoryFrequencyCard';
+import type { AlertHistoryState } from '../useAlertHistoryState';
+
+afterEach(cleanup);
+
+function createFrequencyCardState(options?: { withAxis?: boolean }) {
+ const [selectedBarIndex, setSelectedBarIndex] = createSignal<number | null>(null);
+ const state = {
+ alertData: () => [],
+ selectedBucketDetails: () => null,
+ bucketDurationLabel: () => '1 hour',
+ rangeSummary: () => null,
+ selectedBarIndex,
+ setSelectedBarIndex,
+ alertTrends: () => ({
+ buckets: [0, 1, 2],
+ bucketTimes: [0, 60 * 60 * 1000, 2 * 60 * 60 * 1000],
+ bucketSize: 1,
+ }),
+ formatBucketRange: (start: number) => `Period ${start}`,
+ axisTicks: () =>
+ options?.withAxis
+ ? [
+ { label: 'Start', position: 0, align: 'start' },
+ { label: 'End', position: 1, align: 'end' },
+ ]
+ : [],
+ } as unknown as AlertHistoryState;
+
+ return { selectedBarIndex, state };
+}
+
+describe('AlertHistoryFrequencyCard', () => {
+ it('uses native, visible-focus period buttons with WCAG-sized pointer targets', () => {
+ const { state } = createFrequencyCardState();
+ const { container } = render(() => <AlertHistoryFrequencyCard state={state} />);
+
+ const group = screen.getByRole('group', {
+ name: 'Filter alert history by time period',
+ });
+ expect(group).toHaveClass('overflow-x-auto');
+
+ const buckets = Array.from(
+ container.querySelectorAll<HTMLButtonElement>('[data-alert-frequency-bucket]'),
+ );
+ expect(buckets).toHaveLength(3);
+ for (const bucket of buckets) {
+ expect(bucket.tagName).toBe('BUTTON');
+ expect(bucket).toHaveAttribute('type', 'button');
+ expect(bucket).toHaveClass('h-12');
+ expect(bucket).toHaveClass('min-w-6');
+ expect(bucket).toHaveClass('focus-visible:ring-2');
+ }
+ });
+
+ it('selects and clears a period while keeping aria-pressed in sync', () => {
+ const { selectedBarIndex, state } = createFrequencyCardState();
+ const { container } = render(() => <AlertHistoryFrequencyCard state={state} />);
+ const secondBucket = container.querySelector<HTMLButtonElement>(
+ '[data-alert-frequency-bucket="1"]',
+ );
+
+ expect(secondBucket).not.toBeNull();
+ expect(secondBucket).toHaveAttribute('aria-pressed', 'false');
+ fireEvent.click(secondBucket!);
+ expect(selectedBarIndex()).toBe(1);
+ expect(secondBucket).toHaveAttribute('aria-pressed', 'true');
+
+ fireEvent.click(secondBucket!);
+ expect(selectedBarIndex()).toBeNull();
+ expect(secondBucket).toHaveAttribute('aria-pressed', 'false');
+ });
+
+ it('keeps the time axis inside the same horizontal scroll surface as the bars', () => {
+ const { state } = createFrequencyCardState({ withAxis: true });
+ const { container } = render(() => <AlertHistoryFrequencyCard state={state} />);
+ const scrollSurface = container.querySelector('[data-alert-frequency-scroll]');
+ const axisTicks = screen.getAllByTestId('alert-frequency-axis-tick');
+
+ expect(scrollSurface).not.toBeNull();
+ expect(axisTicks).toHaveLength(2);
+ expect(axisTicks.every((tick) => scrollSurface!.contains(tick))).toBe(true);
+ });
+});