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.

Clamp storage history selectors to entitlements

rcourtmane1a516757a9e
diff --git a/frontend-modern/src/components/Storage/DiskDetail.tsx b/frontend-modern/src/components/Storage/DiskDetail.tsx
index d93dadb572..0b4c45916c 100644
--- a/frontend-modern/src/components/Storage/DiskDetail.tsx
+++ b/frontend-modern/src/components/Storage/DiskDetail.tsx
@@ -1,8 +1,13 @@
-import { Component, For, Show } from 'solid-js';
+import { Component, For, Show, createEffect, createMemo } from 'solid-js';
import type { Resource } from '@/types/resource';
import { FormSelect } from '@/components/shared/FormSelect';
import { HistoryChart } from '@/components/shared/HistoryChart';
import type { HistoryTimeRange } from '@/api/charts';
+import { maxHistoryDays } from '@/stores/license';
+import {
+ getUnlockedHistoryRangeOptions,
+ resolveHistoryRangeWithinLimit,
+} from '@/components/Storage/historyRangeAccess';
import {
DISK_DETAIL_HISTORY_RANGE_OPTIONS,
DISK_DETAIL_LIVE_CHARTS,
@@ -53,6 +58,20 @@ export const DiskDetail: Component<DiskDetailProps> = (props) => {
} = useDiskDetailModel({
disk: () => props.disk,
});
+ const rangeOptions = createMemo(() =>
+ getUnlockedHistoryRangeOptions(DISK_DETAIL_HISTORY_RANGE_OPTIONS, maxHistoryDays()),
+ );
+
+ createEffect(() => {
+ const nextRange = resolveHistoryRangeWithinLimit(
+ chartRange(),
+ DISK_DETAIL_HISTORY_RANGE_OPTIONS,
+ maxHistoryDays(),
+ );
+ if (nextRange !== chartRange()) {
+ setChartRange(nextRange);
+ }
+ });
return (
<div class={STORAGE_DISK_DETAIL_ROOT_CLASS}>
@@ -81,7 +100,7 @@ export const DiskDetail: Component<DiskDetailProps> = (props) => {
selectBaseClass={STORAGE_DETAIL_HEADER_SELECT_CLASS}
style={STORAGE_DETAIL_HEADER_SELECT_STYLE}
>
- <For each={DISK_DETAIL_HISTORY_RANGE_OPTIONS}>
+ <For each={rangeOptions()}>
{(option) => <option value={option.value}>{option.label}</option>}
</For>
</FormSelect>
diff --git a/frontend-modern/src/components/Storage/StoragePoolDetail.tsx b/frontend-modern/src/components/Storage/StoragePoolDetail.tsx
index 6cf4908e14..7ded48a996 100644
--- a/frontend-modern/src/components/Storage/StoragePoolDetail.tsx
+++ b/frontend-modern/src/components/Storage/StoragePoolDetail.tsx
@@ -1,7 +1,12 @@
-import { Component, For, Show } from 'solid-js';
+import { Component, For, Show, createEffect, createMemo } from 'solid-js';
import { FormSelect } from '@/components/shared/FormSelect';
import { HistoryChart } from '@/components/shared/HistoryChart';
import type { HistoryTimeRange } from '@/api/charts';
+import { maxHistoryDays } from '@/stores/license';
+import {
+ getUnlockedHistoryRangeOptions,
+ resolveHistoryRangeWithinLimit,
+} from '@/components/Storage/historyRangeAccess';
import {
getLinkedDiskHealthDotClass,
getLinkedDiskTemperatureTextClass,
@@ -48,6 +53,20 @@ export const StoragePoolDetail: Component<StoragePoolDetailProps> = (props) => {
record: () => props.record,
physicalDisks: () => props.physicalDisks,
});
+ const rangeOptions = createMemo(() =>
+ getUnlockedHistoryRangeOptions(STORAGE_POOL_DETAIL_HISTORY_RANGE_OPTIONS, maxHistoryDays()),
+ );
+
+ createEffect(() => {
+ const nextRange = resolveHistoryRangeWithinLimit(
+ chartRange(),
+ STORAGE_POOL_DETAIL_HISTORY_RANGE_OPTIONS,
+ maxHistoryDays(),
+ );
+ if (nextRange !== chartRange()) {
+ setChartRange(nextRange);
+ }
+ });
return (
<tr class={STORAGE_DETAIL_ROW_CLASS} data-inline-detail-for={props.summarySeriesId}>
@@ -66,7 +85,7 @@ export const StoragePoolDetail: Component<StoragePoolDetailProps> = (props) => {
selectBaseClass={STORAGE_DETAIL_SELECT_CLASS}
style={STORAGE_DETAIL_SELECT_STYLE}
>
- <For each={STORAGE_POOL_DETAIL_HISTORY_RANGE_OPTIONS}>
+ <For each={rangeOptions()}>
{(option) => <option value={option.value}>{option.label}</option>}
</For>
</FormSelect>
diff --git a/frontend-modern/src/components/Storage/__tests__/DiskDetail.test.tsx b/frontend-modern/src/components/Storage/__tests__/DiskDetail.test.tsx
new file mode 100644
index 0000000000..dd885c328f
--- /dev/null
+++ b/frontend-modern/src/components/Storage/__tests__/DiskDetail.test.tsx
@@ -0,0 +1,62 @@
+import { render, screen } from '@solidjs/testing-library';
+import { describe, expect, it, vi } from 'vitest';
+import { DiskDetail } from '@/components/Storage/DiskDetail';
+import type { Resource } from '@/types/resource';
+
+vi.mock('@/components/shared/HistoryChart', () => ({
+ HistoryChart: (props: { resourceType: string; resourceId: string; metric: string; range?: string }) => (
+ <div data-testid="history-chart">
+ {props.resourceType}:{props.resourceId}:{props.metric}:{props.range}
+ </div>
+ ),
+}));
+
+const buildDisk = (): Resource =>
+ ({
+ id: 'disk-1',
+ type: 'physical_disk',
+ name: 'disk-1',
+ displayName: 'Archive HDD',
+ platformId: 'cluster-main',
+ platformType: 'proxmox-pve',
+ sourceType: 'api',
+ status: 'online',
+ lastSeen: Date.now(),
+ metricsTarget: { resourceType: 'disk', resourceId: 'agent-tower:sda' },
+ identity: { hostname: 'tower' },
+ canonicalIdentity: { hostname: 'tower' },
+ platformData: {
+ proxmox: { nodeName: 'tower', instance: 'cluster-main' },
+ },
+ physicalDisk: {
+ devPath: '/dev/sda',
+ model: 'Archive HDD',
+ serial: 'SERIAL-1',
+ diskType: 'hdd',
+ temperature: 42,
+ smart: {
+ powerOnHours: 100,
+ reallocatedSectors: 0,
+ },
+ },
+ }) as unknown as Resource;
+
+describe('DiskDetail', () => {
+ it('keeps disk detail range choices inside the current history entitlement', () => {
+ render(() => <DiskDetail disk={buildDisk()} nodes={[]} />);
+
+ const rangeSelector = screen.getByRole('combobox', {
+ name: 'Disk history range',
+ }) as HTMLSelectElement;
+
+ expect(Array.from(rangeSelector.options).map((option) => option.value)).toEqual([
+ '1h',
+ '6h',
+ '12h',
+ '24h',
+ '7d',
+ ]);
+ expect(Array.from(rangeSelector.options).map((option) => option.value)).not.toContain('14d');
+ expect(Array.from(rangeSelector.options).map((option) => option.value)).not.toContain('90d');
+ });
+});
diff --git a/frontend-modern/src/components/Storage/__tests__/StoragePoolDetail.test.tsx b/frontend-modern/src/components/Storage/__tests__/StoragePoolDetail.test.tsx
index 2c4447f04f..b3dcb0fa5f 100644
--- a/frontend-modern/src/components/Storage/__tests__/StoragePoolDetail.test.tsx
+++ b/frontend-modern/src/components/Storage/__tests__/StoragePoolDetail.test.tsx
@@ -70,7 +70,7 @@ describe('StoragePoolDetail', () => {
);
});
- it('keeps the Relay 14-day range available in pool detail charts', () => {
+ it('keeps pool detail range choices inside the current history entitlement', () => {
historyChartSpy.mockClear();
render(() => (
@@ -93,19 +93,16 @@ describe('StoragePoolDetail', () => {
expect(Array.from(rangeSelector.options).map((option) => option.value)).toEqual([
'24h',
'7d',
- '14d',
- '30d',
- '90d',
]);
- fireEvent.change(rangeSelector, { target: { value: '14d' } });
+ fireEvent.change(rangeSelector, { target: { value: '7d' } });
expect(historyChartSpy).toHaveBeenLastCalledWith(
expect.objectContaining({
resourceType: 'storage',
resourceId: 'pool:tank',
metric: 'usage',
- range: '14d',
+ range: '7d',
}),
);
});
diff --git a/frontend-modern/src/components/Storage/__tests__/historyRangeAccess.test.ts b/frontend-modern/src/components/Storage/__tests__/historyRangeAccess.test.ts
new file mode 100644
index 0000000000..aac0db1ef8
--- /dev/null
+++ b/frontend-modern/src/components/Storage/__tests__/historyRangeAccess.test.ts
@@ -0,0 +1,52 @@
+import { describe, expect, it } from 'vitest';
+import {
+ getHistoryRangeDays,
+ getUnlockedHistoryRangeOptions,
+ resolveHistoryRangeWithinLimit,
+ type HistoryRangeOption,
+} from '@/components/Storage/historyRangeAccess';
+
+const options: readonly HistoryRangeOption[] = [
+ { value: '30m', label: '30m' },
+ { value: '24h', label: '24h' },
+ { value: '7d', label: '7d' },
+ { value: '14d', label: '14d' },
+ { value: '30d', label: '30d' },
+ { value: '90d', label: '90d' },
+];
+
+describe('historyRangeAccess', () => {
+ it('converts chart range tokens to day windows', () => {
+ expect(getHistoryRangeDays('30m')).toBeCloseTo(1 / 48);
+ expect(getHistoryRangeDays('24h')).toBe(1);
+ expect(getHistoryRangeDays('14d')).toBe(14);
+ });
+
+ it('filters range options to the runtime history entitlement', () => {
+ expect(getUnlockedHistoryRangeOptions(options, 7).map((option) => option.value)).toEqual([
+ '30m',
+ '24h',
+ '7d',
+ ]);
+ expect(getUnlockedHistoryRangeOptions(options, 14).map((option) => option.value)).toEqual([
+ '30m',
+ '24h',
+ '7d',
+ '14d',
+ ]);
+ expect(getUnlockedHistoryRangeOptions(options, 90).map((option) => option.value)).toEqual([
+ '30m',
+ '24h',
+ '7d',
+ '14d',
+ '30d',
+ '90d',
+ ]);
+ });
+
+ it('clamps a selected range down to the highest unlocked range', () => {
+ expect(resolveHistoryRangeWithinLimit('90d', options, 7)).toBe('7d');
+ expect(resolveHistoryRangeWithinLimit('90d', options, 14)).toBe('14d');
+ expect(resolveHistoryRangeWithinLimit('90d', options, 90)).toBe('90d');
+ });
+});
diff --git a/frontend-modern/src/components/Storage/historyRangeAccess.ts b/frontend-modern/src/components/Storage/historyRangeAccess.ts
new file mode 100644
index 0000000000..00f6e94c92
--- /dev/null
+++ b/frontend-modern/src/components/Storage/historyRangeAccess.ts
@@ -0,0 +1,49 @@
+import type { HistoryTimeRange } from '@/api/charts';
+
+export type HistoryRangeOption = {
+ value: HistoryTimeRange;
+ label: string;
+};
+
+export function getHistoryRangeDays(range: HistoryTimeRange): number {
+ const match = range.match(/^(\d+)(m|h|d)$/);
+ if (!match) return 0;
+
+ const value = Number.parseInt(match[1], 10);
+ if (!Number.isFinite(value) || value <= 0) return 0;
+
+ switch (match[2]) {
+ case 'm':
+ return value / (24 * 60);
+ case 'h':
+ return value / 24;
+ case 'd':
+ return value;
+ default:
+ return 0;
+ }
+}
+
+export function getUnlockedHistoryRangeOptions<T extends HistoryRangeOption>(
+ options: readonly T[],
+ maxHistoryDays: number,
+): T[] {
+ return options.filter((option) => getHistoryRangeDays(option.value) <= maxHistoryDays);
+}
+
+export function resolveHistoryRangeWithinLimit<T extends HistoryRangeOption>(
+ currentRange: HistoryTimeRange,
+ options: readonly T[],
+ maxHistoryDays: number,
+): HistoryTimeRange {
+ const available = getUnlockedHistoryRangeOptions(options, maxHistoryDays);
+ if (available.some((option) => option.value === currentRange)) {
+ return currentRange;
+ }
+
+ if (available.length > 0) {
+ return available[available.length - 1].value;
+ }
+
+ return options.length > 0 ? options[0].value : '24h';
+}