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.

Converge platform scalar value cells

rcourtman626c191cde02
diff --git a/docs/release-control/v6/internal/subsystems/frontend-primitives.md b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
index c745757856..11edd35ea0 100644
--- a/docs/release-control/v6/internal/subsystems/frontend-primitives.md
+++ b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
@@ -2625,6 +2625,13 @@ that primitive instead of declaring local `numberValue`, `numericValue`,
`replicaCount`, or `countCell` helpers. If a scheduler or service-domain count
is intentionally zero-defaulted, the consuming table owns that field/default
choice and still renders through `PlatformTableNumberValue`.
+One-decimal percent and positive Celsius cells are also shared platform-table
+value primitives. `PlatformTablePercentValue` owns percent formatting,
+tabular-number styling, and empty markers, while
+`PlatformTableTemperatureValue` owns finite positive Celsius validation,
+one-decimal `°C` formatting, tabular-number styling, and empty markers. Docker
+/ Podman host and TrueNAS system tables must compose those primitives instead
+of carrying local `formatPercent` or `formatTemperature` helpers.
Platform table metric fallback rendering is also shared.
`PlatformTableMetricFallback` owns the centered muted empty marker used in
metric bar cells plus optional caller-owned fallback label/title text, and
diff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.md
index 0a10350725..d920f18dd4 100644
--- a/docs/release-control/v6/internal/subsystems/unified-resources.md
+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md
@@ -257,6 +257,12 @@ formatter is needed, while dense platform table cells must use
`PlatformTableNumberValue` for finite-number validation, tabular styling, and
unknown empty-cell markers instead of carrying local `numberValue`,
`numericValue`, `replicaCount`, or `countCell` helpers.
+Percent and temperature table cells follow the same split: unified-resource
+consumers own which usage percentage or temperature source is meaningful for
+the row, while dense platform table rendering must use
+`PlatformTablePercentValue` and `PlatformTableTemperatureValue` for one-decimal
+formatting, positive Celsius validation, tabular styling, and empty markers
+instead of local `formatPercent` or `formatTemperature` helpers.
Metric bar fallbacks follow that split as well: unified-resource consumers own
which CPU or memory value is selected, plus any source-specific fallback reason
such as outdated standalone agent telemetry, while platform tables must use
diff --git a/frontend-modern/scripts/shared-template-registry.json b/frontend-modern/scripts/shared-template-registry.json
index c802562f92..f32e644475 100644
--- a/frontend-modern/scripts/shared-template-registry.json
+++ b/frontend-modern/scripts/shared-template-registry.json
@@ -1454,6 +1454,64 @@
"scripts/shared-template-audit.mjs"
]
},
+ {
+ "id": "platform-table-percent-value-fallback",
+ "category": "platform-table-text-value",
+ "summary": "Platform tables must use the shared percent-value primitive for one-decimal percent cells, tabular styling, and canonical empty-cell markers instead of recreating local formatPercent helpers.",
+ "canonical": {
+ "path": "src/features/platformPage/sharedPlatformPage.tsx",
+ "export": "PlatformTablePercentValue"
+ },
+ "requiredConsumers": [{ "path": "src/features/truenas/TrueNASSystemsTable.tsx" }],
+ "forbiddenPatterns": [
+ {
+ "path": "src/features/truenas/TrueNASSystemsTable.tsx",
+ "patterns": [
+ "const formatPercent",
+ "<span class=\"tabular-nums\">{percent.toFixed(1)}%</span>"
+ ]
+ }
+ ],
+ "proof": [
+ "src/components/shared/SharedPrimitives.guardrails.test.ts",
+ "src/features/platformPage/__tests__/sharedPlatformPage.test.ts",
+ "scripts/shared-template-audit.mjs"
+ ]
+ },
+ {
+ "id": "platform-table-temperature-value-fallback",
+ "category": "platform-table-text-value",
+ "summary": "Platform tables must use the shared temperature-value primitive for positive Celsius cells, tabular styling, and canonical empty-cell markers instead of recreating local formatTemperature helpers.",
+ "canonical": {
+ "path": "src/features/platformPage/sharedPlatformPage.tsx",
+ "export": "PlatformTableTemperatureValue"
+ },
+ "requiredConsumers": [
+ { "path": "src/features/docker/DockerHostsTable.tsx" },
+ { "path": "src/features/truenas/TrueNASSystemsTable.tsx" }
+ ],
+ "forbiddenPatterns": [
+ {
+ "path": "src/features/docker/DockerHostsTable.tsx",
+ "patterns": [
+ "const formatTemperature",
+ "<span class=\"tabular-nums\">{celsius.toFixed(1)}°C</span>"
+ ]
+ },
+ {
+ "path": "src/features/truenas/TrueNASSystemsTable.tsx",
+ "patterns": [
+ "const formatTemperature",
+ "<span class=\"tabular-nums\">{celsius.toFixed(1)}°C</span>"
+ ]
+ }
+ ],
+ "proof": [
+ "src/components/shared/SharedPrimitives.guardrails.test.ts",
+ "src/features/platformPage/__tests__/sharedPlatformPage.test.ts",
+ "scripts/shared-template-audit.mjs"
+ ]
+ },
{
"id": "platform-table-metric-fallback",
"category": "platform-table-metric",
@@ -2130,6 +2188,52 @@
"scripts/shared-template-audit.mjs"
]
},
+ {
+ "id": "platform-table-local-percent-value-helper",
+ "category": "platform-table-text-value",
+ "summary": "Platform tables must not recreate local formatPercent helpers for one-decimal percent cells.",
+ "canonical": {
+ "path": "src/features/platformPage/sharedPlatformPage.tsx",
+ "export": "PlatformTablePercentValue"
+ },
+ "scopes": ["src/features/truenas"],
+ "extensions": [".tsx"],
+ "allPatterns": [
+ "const formatPercent",
+ "<span class=\"tabular-nums\">{percent.toFixed(1)}%</span>"
+ ],
+ "legacyReason": "Retired migration debt. One-decimal percent cells must compose PlatformTablePercentValue so percent formatting, tabular styling, and empty markers stay shared.",
+ "allowedPaths": [],
+ "ignoredPaths": [],
+ "proof": [
+ "src/components/shared/SharedPrimitives.guardrails.test.ts",
+ "src/features/platformPage/__tests__/sharedPlatformPage.test.ts",
+ "scripts/shared-template-audit.mjs"
+ ]
+ },
+ {
+ "id": "platform-table-local-temperature-value-helper",
+ "category": "platform-table-text-value",
+ "summary": "Platform tables must not recreate local formatTemperature helpers for positive Celsius cells.",
+ "canonical": {
+ "path": "src/features/platformPage/sharedPlatformPage.tsx",
+ "export": "PlatformTableTemperatureValue"
+ },
+ "scopes": ["src/features/docker", "src/features/truenas"],
+ "extensions": [".tsx"],
+ "allPatterns": [
+ "const formatTemperature",
+ "<span class=\"tabular-nums\">{celsius.toFixed(1)}°C</span>"
+ ],
+ "legacyReason": "Retired migration debt. Positive Celsius table cells must compose PlatformTableTemperatureValue so validity, formatting, tabular styling, and empty markers stay shared.",
+ "allowedPaths": [],
+ "ignoredPaths": [],
+ "proof": [
+ "src/components/shared/SharedPrimitives.guardrails.test.ts",
+ "src/features/platformPage/__tests__/sharedPlatformPage.test.ts",
+ "scripts/shared-template-audit.mjs"
+ ]
+ },
{
"id": "platform-table-local-metric-fallback-helper",
"category": "platform-table-metric",
diff --git a/frontend-modern/src/components/shared/SharedPrimitives.guardrails.test.ts b/frontend-modern/src/components/shared/SharedPrimitives.guardrails.test.ts
index b0d0a78227..9d8fbca7fd 100644
--- a/frontend-modern/src/components/shared/SharedPrimitives.guardrails.test.ts
+++ b/frontend-modern/src/components/shared/SharedPrimitives.guardrails.test.ts
@@ -3914,6 +3914,122 @@ describe('shared primitive guardrails', () => {
expect(proxmoxMailGatewayTableSource).toContain('format={formatLocaleCount}');
});
+ it('keeps platform table scalar unit values on shared primitives', () => {
+ const registry = JSON.parse(sharedTemplateRegistrySource) as {
+ rules?: Array<{
+ id: string;
+ canonical?: { path?: string; export?: string };
+ requiredConsumers?: Array<{ path?: string }>;
+ forbiddenPatterns?: Array<{ path?: string; patterns?: string[] }>;
+ }>;
+ patternGuards?: Array<{
+ id: string;
+ canonical?: { path?: string; export?: string };
+ allPatterns?: string[];
+ scopes?: string[];
+ allowedPaths?: string[];
+ ignoredPaths?: string[];
+ }>;
+ };
+ const percentRule = registry.rules?.find(
+ (rule) => rule.id === 'platform-table-percent-value-fallback',
+ );
+ const temperatureRule = registry.rules?.find(
+ (rule) => rule.id === 'platform-table-temperature-value-fallback',
+ );
+ const localPercentGuard = registry.patternGuards?.find(
+ (guard) => guard.id === 'platform-table-local-percent-value-helper',
+ );
+ const localTemperatureGuard = registry.patternGuards?.find(
+ (guard) => guard.id === 'platform-table-local-temperature-value-helper',
+ );
+ const percentConsumers: Array<[string, string]> = [
+ ['src/features/truenas/TrueNASSystemsTable.tsx', truenasSystemsTableSource],
+ ];
+ const temperatureConsumers: Array<[string, string]> = [
+ ['src/features/docker/DockerHostsTable.tsx', dockerHostsTableSource],
+ ['src/features/truenas/TrueNASSystemsTable.tsx', truenasSystemsTableSource],
+ ];
+ const localPercentPatterns = [
+ 'const formatPercent',
+ '<span class="tabular-nums">{percent.toFixed(1)}%</span>',
+ ];
+ const localTemperaturePatterns = [
+ 'const formatTemperature',
+ '<span class="tabular-nums">{celsius.toFixed(1)}°C</span>',
+ ];
+
+ expect(percentRule?.canonical?.path).toBe('src/features/platformPage/sharedPlatformPage.tsx');
+ expect(percentRule?.canonical?.export).toBe('PlatformTablePercentValue');
+ expect(percentRule?.requiredConsumers?.map((consumer) => consumer.path)).toEqual(
+ percentConsumers.map(([path]) => path),
+ );
+ expect(percentRule?.forbiddenPatterns).toEqual([
+ {
+ path: 'src/features/truenas/TrueNASSystemsTable.tsx',
+ patterns: localPercentPatterns,
+ },
+ ]);
+
+ expect(temperatureRule?.canonical?.path).toBe(
+ 'src/features/platformPage/sharedPlatformPage.tsx',
+ );
+ expect(temperatureRule?.canonical?.export).toBe('PlatformTableTemperatureValue');
+ expect(temperatureRule?.requiredConsumers?.map((consumer) => consumer.path)).toEqual(
+ temperatureConsumers.map(([path]) => path),
+ );
+ expect(temperatureRule?.forbiddenPatterns).toEqual([
+ {
+ path: 'src/features/docker/DockerHostsTable.tsx',
+ patterns: localTemperaturePatterns,
+ },
+ {
+ path: 'src/features/truenas/TrueNASSystemsTable.tsx',
+ patterns: localTemperaturePatterns,
+ },
+ ]);
+
+ expect(localPercentGuard?.canonical?.path).toBe(
+ 'src/features/platformPage/sharedPlatformPage.tsx',
+ );
+ expect(localPercentGuard?.canonical?.export).toBe('PlatformTablePercentValue');
+ expect(localPercentGuard?.allPatterns).toEqual(localPercentPatterns);
+ expect(localPercentGuard?.scopes).toEqual(['src/features/truenas']);
+ expect(localPercentGuard?.allowedPaths ?? []).toHaveLength(0);
+ expect(localPercentGuard?.ignoredPaths ?? []).toHaveLength(0);
+ expect(localTemperatureGuard?.canonical?.path).toBe(
+ 'src/features/platformPage/sharedPlatformPage.tsx',
+ );
+ expect(localTemperatureGuard?.canonical?.export).toBe('PlatformTableTemperatureValue');
+ expect(localTemperatureGuard?.allPatterns).toEqual(localTemperaturePatterns);
+ expect(localTemperatureGuard?.scopes).toEqual(['src/features/docker', 'src/features/truenas']);
+ expect(localTemperatureGuard?.allowedPaths ?? []).toHaveLength(0);
+ expect(localTemperatureGuard?.ignoredPaths ?? []).toHaveLength(0);
+
+ expect(sharedPlatformPageSource).toContain('export function PlatformTablePercentValue');
+ expect(sharedPlatformPageSource).toContain('export function PlatformTableTemperatureValue');
+ expect(sharedPlatformPageSource).toContain('formatOneDecimalPercent');
+ expect(sharedPlatformPageSource).toContain('formatOneDecimalCelsius');
+
+ for (const [path, source] of percentConsumers) {
+ expect(source).toContain('PlatformTablePercentValue');
+ const forbiddenPatterns =
+ percentRule?.forbiddenPatterns?.find((entry) => entry.path === path)?.patterns ?? [];
+ for (const pattern of forbiddenPatterns) {
+ expect(source).not.toContain(pattern);
+ }
+ }
+
+ for (const [path, source] of temperatureConsumers) {
+ expect(source).toContain('PlatformTableTemperatureValue');
+ const forbiddenPatterns =
+ temperatureRule?.forbiddenPatterns?.find((entry) => entry.path === path)?.patterns ?? [];
+ for (const pattern of forbiddenPatterns) {
+ expect(source).not.toContain(pattern);
+ }
+ }
+ });
+
it('keeps platform table compact value summaries on the shared helper', () => {
const registry = JSON.parse(sharedTemplateRegistrySource) as {
rules?: Array<{
diff --git a/frontend-modern/src/features/docker/DockerHostsTable.tsx b/frontend-modern/src/features/docker/DockerHostsTable.tsx
index 79604d138e..f149bd9ddd 100644
--- a/frontend-modern/src/features/docker/DockerHostsTable.tsx
+++ b/frontend-modern/src/features/docker/DockerHostsTable.tsx
@@ -14,6 +14,7 @@ import {
PLATFORM_HEALTH_FILTER_OPTIONS,
PlatformTableMetricFallback,
PlatformTableEmptyState,
+ PlatformTableTemperatureValue,
PlatformTableShell,
PlatformTableToolbar,
createPlatformTableFilterState,
@@ -41,11 +42,6 @@ import {
// any other agent. This bespoke table reuses canonical shared
// primitives and surfaces the Docker-native columns.
-const formatTemperature = (celsius: number | undefined): JSX.Element => {
- if (typeof celsius !== 'number' || celsius <= 0) return <span class="text-muted">—</span>;
- return <span class="tabular-nums">{celsius.toFixed(1)}°C</span>;
-};
-
const percentFromMetric = (metric: Resource['cpu'] | undefined): number | undefined =>
getPlatformTableFiniteMetric(metric?.current);
@@ -372,7 +368,9 @@ export const DockerHostsTable: Component<{
<TableCell
class={`${getPlatformTableCellClassForKind('numeric-value')} hidden text-base-content md:table-cell`}
>
- {formatTemperature(host.temperature ?? docker()?.temperature)}
+ <PlatformTableTemperatureValue
+ value={host.temperature ?? docker()?.temperature}
+ />
</TableCell>
<Show when={showSwarmColumn()}>
<TableCell
diff --git a/frontend-modern/src/features/platformPage/__tests__/sharedPlatformPage.test.ts b/frontend-modern/src/features/platformPage/__tests__/sharedPlatformPage.test.ts
index 9aeefde0f9..691a9a54a3 100644
--- a/frontend-modern/src/features/platformPage/__tests__/sharedPlatformPage.test.ts
+++ b/frontend-modern/src/features/platformPage/__tests__/sharedPlatformPage.test.ts
@@ -5,6 +5,8 @@ import type { Resource } from '@/types/resource';
import {
PlatformTableMetricFallback,
PlatformTableNumberValue,
+ PlatformTablePercentValue,
+ PlatformTableTemperatureValue,
createPlatformTableFilterState,
formatPlatformTableBytesValue,
formatPlatformTableTitleCaseValue,
@@ -331,6 +333,38 @@ describe('PlatformTableNumberValue', () => {
});
});
+describe('PlatformTablePercentValue', () => {
+ it('renders finite percentages with one decimal place and shared tabular styling', () => {
+ const { container } = render(() => PlatformTablePercentValue({ value: 42.345 }));
+ const marker = container.querySelector('span');
+
+ expect(marker?.textContent).toBe('42.3%');
+ expect(marker?.classList.contains('tabular-nums')).toBe(true);
+
+ cleanup();
+ render(() => PlatformTablePercentValue({ value: Number.NaN, emptyText: '-' }));
+ expect(screen.getByText('-')).toBeInTheDocument();
+ });
+});
+
+describe('PlatformTableTemperatureValue', () => {
+ it('renders positive Celsius values with one decimal place and rejects absent readings', () => {
+ const { container } = render(() => PlatformTableTemperatureValue({ value: 38.86 }));
+ const marker = container.querySelector('span');
+
+ expect(marker?.textContent).toBe('38.9°C');
+ expect(marker?.classList.contains('tabular-nums')).toBe(true);
+
+ cleanup();
+ render(() => PlatformTableTemperatureValue({ value: 0, emptyText: 'No sensor' }));
+ expect(screen.getByText('No sensor')).toBeInTheDocument();
+
+ cleanup();
+ render(() => PlatformTableTemperatureValue({ value: Number.POSITIVE_INFINITY }));
+ expect(screen.getByText('—')).toBeInTheDocument();
+ });
+});
+
describe('getPlatformTableFiniteMetric', () => {
it('normalizes platform table metrics to finite numeric values only', () => {
expect(getPlatformTableFiniteMetric(42)).toBe(42);
diff --git a/frontend-modern/src/features/platformPage/sharedPlatformPage.tsx b/frontend-modern/src/features/platformPage/sharedPlatformPage.tsx
index ea61ce19de..8b9a4ab0ea 100644
--- a/frontend-modern/src/features/platformPage/sharedPlatformPage.tsx
+++ b/frontend-modern/src/features/platformPage/sharedPlatformPage.tsx
@@ -221,6 +221,43 @@ export function PlatformTableNumberValue(props: {
return <span class="tabular-nums">{label()}</span>;
}
+const formatOneDecimalPercent = (value: number): string => `${value.toFixed(1)}%`;
+const formatOneDecimalCelsius = (value: number): string => `${value.toFixed(1)}°C`;
+
+export function PlatformTablePercentValue(props: {
+ value: number | null | undefined;
+ emptyText?: string;
+}) {
+ const finiteValue = () =>
+ typeof props.value === 'number' && Number.isFinite(props.value) ? props.value : undefined;
+
+ return (
+ <PlatformTableNumberValue
+ value={finiteValue()}
+ emptyText={props.emptyText}
+ format={formatOneDecimalPercent}
+ />
+ );
+}
+
+export function PlatformTableTemperatureValue(props: {
+ value: number | null | undefined;
+ emptyText?: string;
+}) {
+ const finitePositiveValue = () =>
+ typeof props.value === 'number' && Number.isFinite(props.value) && props.value > 0
+ ? props.value
+ : undefined;
+
+ return (
+ <PlatformTableNumberValue
+ value={finitePositiveValue()}
+ emptyText={props.emptyText}
+ format={formatOneDecimalCelsius}
+ />
+ );
+}
+
export const getPlatformTableFiniteMetric = (value: number | undefined): number | undefined =>
typeof value === 'number' && Number.isFinite(value) ? value : undefined;
diff --git a/frontend-modern/src/features/truenas/TrueNASSystemsTable.tsx b/frontend-modern/src/features/truenas/TrueNASSystemsTable.tsx
index c8794eeb31..a76c0c9fcf 100644
--- a/frontend-modern/src/features/truenas/TrueNASSystemsTable.tsx
+++ b/frontend-modern/src/features/truenas/TrueNASSystemsTable.tsx
@@ -9,6 +9,8 @@ import { buildMetricKeyForUnifiedResource } from '@/utils/metricsKeys';
import {
PLATFORM_HEALTH_FILTER_OPTIONS,
PlatformTableMetricFallback,
+ PlatformTablePercentValue,
+ PlatformTableTemperatureValue,
PlatformTableToolbar,
PlatformTableEmptyState,
createPlatformTableFilterState,
@@ -47,17 +49,6 @@ import type { Resource } from '@/types/resource';
// client-side from the same TrueNAS resource scope already fetched by
// the page (no extra API calls).
-const formatPercent = (percent?: number): JSX.Element => {
- if (typeof percent !== 'number' || Number.isNaN(percent))
- return <span class="text-muted">—</span>;
- return <span class="tabular-nums">{percent.toFixed(1)}%</span>;
-};
-
-const formatTemperature = (celsius: number | undefined): JSX.Element => {
- if (typeof celsius !== 'number' || celsius <= 0) return <span class="text-muted">—</span>;
- return <span class="tabular-nums">{celsius.toFixed(1)}°C</span>;
-};
-
const EMPTY_COUNTS: TrueNASSystemChildCounts = {
pools: 0,
datasets: 0,
@@ -209,7 +200,7 @@ export const TrueNASSystemsTable: Component<{
typeof system.disk?.used === 'number' &&
typeof system.disk?.total === 'number'
? `${formatPlatformTableBytesValue(system.disk.used)} / ${formatPlatformTableBytesValue(system.disk.total)}`
- : formatPercent(storagePercent());
+ : undefined;
const c = () => countsBySystem().get(system.id) ?? EMPTY_COUNTS;
const uptimeLabel = () => formatPlatformTableUptimeValue(system.uptime);
const systemMeta = () =>
@@ -302,13 +293,22 @@ export const TrueNASSystemsTable: Component<{
<TableCell
class={`${getPlatformTableCellClassForKind('metric-bar')} text-base-content`}
>
- <span class="md:hidden">{formatPercent(storagePercent())}</span>
- <span class="hidden md:inline">{storageFullLabel()}</span>
+ <span class="md:hidden">
+ <PlatformTablePercentValue value={storagePercent()} />
+ </span>
+ <span class="hidden md:inline">
+ <Show
+ when={storageFullLabel()}
+ fallback={<PlatformTablePercentValue value={storagePercent()} />}
+ >
+ {(label) => label()}
+ </Show>
+ </span>
</TableCell>
<TableCell
class={`${getPlatformTableCellClassForKind('numeric-value')} hidden text-base-content md:table-cell`}
>
- {formatTemperature(system.temperature)}
+ <PlatformTableTemperatureValue value={system.temperature} />
</TableCell>
<TableCell
class={`${getPlatformTableCellClassForKind('text')} hidden whitespace-normal text-base-content lg:table-cell`}