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 count ratio labels

rcourtmanaec7d39ddc40
diff --git a/docs/release-control/v6/internal/subsystems/frontend-primitives.md b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
index 78f59233df..646184e84a 100644
--- a/docs/release-control/v6/internal/subsystems/frontend-primitives.md
+++ b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
@@ -2630,9 +2630,13 @@ zero-defaulted, the consuming table owns that field/default choice and still
renders through `PlatformTableNumberValue`.
`PlatformTableCountRatioValue` owns the companion healthy/total or ready/total
count-ratio skeleton: numerator, slash, muted denominator, tabular styling, and
-empty marker behavior. Kubernetes cluster child counts compose that primitive
-instead of keeping a table-local `childCountCell` renderer; the table owns only
-which current/total values and warning tone apply.
+empty marker behavior. `formatPlatformTableCountRatioValue` owns the same
+zero-default and suffix behavior for string-only table summaries and titles.
+Kubernetes cluster child counts compose the component instead of keeping a
+table-local `childCountCell` renderer, and Kubernetes networking endpoint
+summaries compose the formatter instead of hand-building `3/3 ready` strings;
+the consuming table owns only which current/total values, suffix, and warning
+tone apply.
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
diff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.md
index cbc0042850..92c0772948 100644
--- a/docs/release-control/v6/internal/subsystems/unified-resources.md
+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md
@@ -257,10 +257,13 @@ domain-specific formatter is needed, and which current/total fields belong in a
grouped health ratio, while dense platform table cells must use
`PlatformTableNumberValue` for scalar count validation, tabular styling, and
unknown empty-cell markers, and `PlatformTableCountRatioValue` for
-healthy/total or ready/total count-ratio skeletons. Tables must not carry local
+healthy/total or ready/total count-ratio skeletons. String-only table summaries
+and titles use `formatPlatformTableCountRatioValue` for the same zero-default
+and suffix behavior. Tables must not carry local
`numberValue`, `numericValue`, `replicaCount`, `countCell`, `childCountCell`,
`diskCountLabel`, or cell-level `tabular-nums` variants for grouped
-child/share/service/storage counts.
+child/share/service/storage counts, or local ready/total template strings for
+endpoint summaries.
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
diff --git a/frontend-modern/scripts/shared-template-registry.json b/frontend-modern/scripts/shared-template-registry.json
index cfb9e84a4f..776844f357 100644
--- a/frontend-modern/scripts/shared-template-registry.json
+++ b/frontend-modern/scripts/shared-template-registry.json
@@ -1499,6 +1499,30 @@
"scripts/shared-template-audit.mjs"
]
},
+ {
+ "id": "platform-table-count-ratio-label",
+ "category": "platform-table-text-value",
+ "summary": "Platform tables must use the shared count-ratio formatter for ready/total string labels instead of recreating local ready/total template literals.",
+ "canonical": {
+ "path": "src/features/platformPage/sharedPlatformPage.tsx",
+ "export": "formatPlatformTableCountRatioValue"
+ },
+ "requiredConsumers": [{ "path": "src/features/kubernetes/KubernetesNetworkingTable.tsx" }],
+ "forbiddenPatterns": [
+ {
+ "path": "src/features/kubernetes/KubernetesNetworkingTable.tsx",
+ "patterns": [
+ "`${readyValue}/${totalValue} ready`",
+ "`${ready ?? 0}/${total ?? ready ?? 0} ready`"
+ ]
+ }
+ ],
+ "proof": [
+ "src/components/shared/SharedPrimitives.guardrails.test.ts",
+ "src/features/platformPage/__tests__/sharedPlatformPage.test.ts",
+ "scripts/shared-template-audit.mjs"
+ ]
+ },
{
"id": "platform-table-percent-value-fallback",
"category": "platform-table-text-value",
@@ -2278,6 +2302,26 @@
"scripts/shared-template-audit.mjs"
]
},
+ {
+ "id": "platform-table-local-ready-count-ratio-label",
+ "category": "platform-table-text-value",
+ "summary": "Kubernetes networking tables must not recreate ready/total endpoint count labels with local template strings.",
+ "canonical": {
+ "path": "src/features/platformPage/sharedPlatformPage.tsx",
+ "export": "formatPlatformTableCountRatioValue"
+ },
+ "scopes": ["src/features/kubernetes/KubernetesNetworkingTable.tsx"],
+ "extensions": [".tsx"],
+ "allPatterns": ["readyEndpointCount", "/${", " ready`"],
+ "legacyReason": "Retired migration debt. Ready/total endpoint labels must compose formatPlatformTableCountRatioValue so zero-default, suffix, and empty-label behavior stay shared with count-ratio cells.",
+ "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-truenas-count-cell-class",
"category": "platform-table-text-value",
diff --git a/frontend-modern/src/components/shared/SharedPrimitives.guardrails.test.ts b/frontend-modern/src/components/shared/SharedPrimitives.guardrails.test.ts
index 0ad79215a2..fd0f27e0d9 100644
--- a/frontend-modern/src/components/shared/SharedPrimitives.guardrails.test.ts
+++ b/frontend-modern/src/components/shared/SharedPrimitives.guardrails.test.ts
@@ -3986,13 +3986,25 @@ describe('shared primitive guardrails', () => {
const registeredRule = registry.rules?.find(
(rule) => rule.id === 'platform-table-count-ratio-value',
);
+ const formatterRule = registry.rules?.find(
+ (rule) => rule.id === 'platform-table-count-ratio-label',
+ );
const localCountRatioGuard = registry.patternGuards?.find(
(guard) => guard.id === 'platform-table-local-count-ratio-helper',
);
+ const localReadyCountRatioGuard = registry.patternGuards?.find(
+ (guard) => guard.id === 'platform-table-local-ready-count-ratio-label',
+ );
const platformCountRatioConsumers: Array<[string, string]> = [
['src/features/kubernetes/KubernetesClustersTable.tsx', kubernetesClustersTableSource],
];
+ const platformCountRatioFormatterConsumers: Array<[string, string]> = [
+ ['src/features/kubernetes/KubernetesNetworkingTable.tsx', kubernetesNetworkingTableSource],
+ ];
const platformCountRatioConsumerPaths = platformCountRatioConsumers.map(([path]) => path);
+ const platformCountRatioFormatterConsumerPaths = platformCountRatioFormatterConsumers.map(
+ ([path]) => path,
+ );
expect(registeredRule?.canonical?.path).toBe(
'src/features/platformPage/sharedPlatformPage.tsx',
@@ -4007,6 +4019,20 @@ describe('shared primitive guardrails', () => {
patterns: ['const childCountCell', '<span class="text-muted">/{count.total}</span>'],
},
]);
+ expect(formatterRule?.canonical?.path).toBe('src/features/platformPage/sharedPlatformPage.tsx');
+ expect(formatterRule?.canonical?.export).toBe('formatPlatformTableCountRatioValue');
+ expect(formatterRule?.requiredConsumers?.map((consumer) => consumer.path)).toEqual(
+ platformCountRatioFormatterConsumerPaths,
+ );
+ expect(formatterRule?.forbiddenPatterns).toEqual([
+ {
+ path: 'src/features/kubernetes/KubernetesNetworkingTable.tsx',
+ patterns: [
+ '`${readyValue}/${totalValue} ready`',
+ '`${ready ?? 0}/${total ?? ready ?? 0} ready`',
+ ],
+ },
+ ]);
expect(localCountRatioGuard?.canonical?.path).toBe(
'src/features/platformPage/sharedPlatformPage.tsx',
);
@@ -4018,8 +4044,25 @@ describe('shared primitive guardrails', () => {
expect(localCountRatioGuard?.scopes).toEqual(['src/features/kubernetes']);
expect(localCountRatioGuard?.allowedPaths ?? []).toHaveLength(0);
expect(localCountRatioGuard?.ignoredPaths ?? []).toHaveLength(0);
+ expect(localReadyCountRatioGuard?.canonical?.path).toBe(
+ 'src/features/platformPage/sharedPlatformPage.tsx',
+ );
+ expect(localReadyCountRatioGuard?.canonical?.export).toBe('formatPlatformTableCountRatioValue');
+ expect(localReadyCountRatioGuard?.allPatterns).toEqual([
+ 'readyEndpointCount',
+ '/${',
+ ' ready`',
+ ]);
+ expect(localReadyCountRatioGuard?.scopes).toEqual([
+ 'src/features/kubernetes/KubernetesNetworkingTable.tsx',
+ ]);
+ expect(localReadyCountRatioGuard?.allowedPaths ?? []).toHaveLength(0);
+ expect(localReadyCountRatioGuard?.ignoredPaths ?? []).toHaveLength(0);
expect(sharedPlatformPageSource).toContain('export function PlatformTableCountRatioValue');
+ expect(sharedPlatformPageSource).toContain(
+ 'export function formatPlatformTableCountRatioValue',
+ );
for (const [path, source] of platformCountRatioConsumers) {
expect(source).toContain('PlatformTableCountRatioValue');
@@ -4029,6 +4072,15 @@ describe('shared primitive guardrails', () => {
expect(source).not.toContain(pattern);
}
}
+
+ for (const [path, source] of platformCountRatioFormatterConsumers) {
+ expect(source).toContain('formatPlatformTableCountRatioValue');
+ const forbiddenPatterns =
+ formatterRule?.forbiddenPatterns?.find((entry) => entry.path === path)?.patterns ?? [];
+ for (const pattern of forbiddenPatterns) {
+ expect(source).not.toContain(pattern);
+ }
+ }
});
it('keeps platform table scalar unit values on shared primitives', () => {
diff --git a/frontend-modern/src/features/kubernetes/KubernetesNetworkingTable.tsx b/frontend-modern/src/features/kubernetes/KubernetesNetworkingTable.tsx
index 05cc632ea8..68624f3cc7 100644
--- a/frontend-modern/src/features/kubernetes/KubernetesNetworkingTable.tsx
+++ b/frontend-modern/src/features/kubernetes/KubernetesNetworkingTable.tsx
@@ -8,6 +8,7 @@ import {
PlatformTableEmptyState,
PlatformTableToolbar,
createPlatformTableFilterState,
+ formatPlatformTableCountRatioValue,
formatPlatformTableTextValue,
getPlatformTableCellClassForKind,
getPlatformTableHeadClassForKind,
@@ -64,11 +65,10 @@ const addressOrHosts = (resource: Resource): { label: string; title: string } =>
const ready = resource.kubernetes?.readyEndpointCount;
const total = resource.kubernetes?.endpointCount;
if (typeof ready === 'number' || typeof total === 'number') {
- const readyValue = ready ?? 0;
- const totalValue = total ?? readyValue;
+ const label = formatPlatformTableCountRatioValue(ready, total, { suffix: 'ready' });
return {
- label: `${readyValue}/${totalValue} ready`,
- title: `${readyValue}/${totalValue} ready`,
+ label,
+ title: label,
};
}
return summarizePlatformTableValues(resource.kubernetes?.addresses);
@@ -92,7 +92,7 @@ const targetSummary = (resource: Resource): { label: string; title: string } =>
const total = resource.kubernetes?.endpointCount;
const endpointLabel =
typeof ready === 'number' || typeof total === 'number'
- ? `${ready ?? 0}/${total ?? ready ?? 0} ready`
+ ? formatPlatformTableCountRatioValue(ready, total, { suffix: 'ready' })
: '';
return {
label: [service, endpointLabel].filter((value) => value && value !== '—').join(' · ') || '—',
diff --git a/frontend-modern/src/features/platformPage/__tests__/sharedPlatformPage.test.ts b/frontend-modern/src/features/platformPage/__tests__/sharedPlatformPage.test.ts
index 42d86d9a5f..64ebad0126 100644
--- a/frontend-modern/src/features/platformPage/__tests__/sharedPlatformPage.test.ts
+++ b/frontend-modern/src/features/platformPage/__tests__/sharedPlatformPage.test.ts
@@ -10,6 +10,7 @@ import {
PlatformTableTemperatureValue,
createPlatformTableFilterState,
formatPlatformTableBytesValue,
+ formatPlatformTableCountRatioValue,
formatPlatformTableTitleCaseValue,
formatPlatformTableUptimeValue,
filterPlatformResources,
@@ -335,6 +336,12 @@ describe('PlatformTableNumberValue', () => {
});
describe('PlatformTableCountRatioValue', () => {
+ it('formats count-ratio labels for string-only table summaries', () => {
+ expect(formatPlatformTableCountRatioValue(3, 5, { suffix: 'ready' })).toBe('3/5 ready');
+ expect(formatPlatformTableCountRatioValue(undefined, 4, { suffix: 'ready' })).toBe('0/4 ready');
+ expect(formatPlatformTableCountRatioValue(undefined, undefined, { emptyText: '' })).toBe('');
+ });
+
it('renders count ratios through shared tabular number styling', () => {
const { container } = render(() =>
PlatformTableCountRatioValue({
diff --git a/frontend-modern/src/features/platformPage/sharedPlatformPage.tsx b/frontend-modern/src/features/platformPage/sharedPlatformPage.tsx
index d8f518aec0..133299a0ed 100644
--- a/frontend-modern/src/features/platformPage/sharedPlatformPage.tsx
+++ b/frontend-modern/src/features/platformPage/sharedPlatformPage.tsx
@@ -221,6 +221,32 @@ export function PlatformTableNumberValue(props: {
return <span class="tabular-nums">{label()}</span>;
}
+const resolvePlatformTableCountRatioParts = (
+ current: number | undefined,
+ total: number | undefined,
+): { current: number; total: number } | undefined => {
+ const currentValue =
+ typeof current === 'number' && Number.isFinite(current) ? current : undefined;
+ const totalValue = typeof total === 'number' && Number.isFinite(total) ? total : undefined;
+ if (currentValue === undefined && totalValue === undefined) return undefined;
+ const resolvedCurrent = currentValue ?? 0;
+ return {
+ current: resolvedCurrent,
+ total: totalValue ?? resolvedCurrent,
+ };
+};
+
+export function formatPlatformTableCountRatioValue(
+ current: number | undefined,
+ total: number | undefined,
+ options: { emptyText?: string; suffix?: string } = {},
+): string {
+ const ratio = resolvePlatformTableCountRatioParts(current, total);
+ if (!ratio) return options.emptyText ?? '—';
+ const suffix = options.suffix ? ` ${options.suffix}` : '';
+ return `${ratio.current}/${ratio.total}${suffix}`;
+}
+
export function PlatformTableCountRatioValue(props: {
current: number | undefined;
total: number | undefined;
@@ -228,30 +254,29 @@ export function PlatformTableCountRatioValue(props: {
emptyText?: string;
suffix?: string;
}) {
- const hasAnyValue = () =>
- [props.current, props.total].some(
- (value) => typeof value === 'number' && Number.isFinite(value),
- );
+ const ratio = () => resolvePlatformTableCountRatioParts(props.current, props.total);
const currentClass = () =>
props.currentTone === 'warning' ? 'text-amber-700 dark:text-amber-300' : '';
return (
<Show
- when={hasAnyValue()}
+ when={ratio()}
fallback={<PlatformTableNumberValue value={undefined} emptyText={props.emptyText} />}
>
- <span class="inline-flex items-baseline whitespace-nowrap">
- <span class={currentClass()}>
- <PlatformTableNumberValue value={props.current} emptyText={props.emptyText} />
- </span>
- <span class="text-muted">/</span>
- <span class="text-muted">
- <PlatformTableNumberValue value={props.total} emptyText={props.emptyText} />
+ {(resolved) => (
+ <span class="inline-flex items-baseline whitespace-nowrap">
+ <span class={currentClass()}>
+ <PlatformTableNumberValue value={resolved().current} emptyText={props.emptyText} />
+ </span>
+ <span class="text-muted">/</span>
+ <span class="text-muted">
+ <PlatformTableNumberValue value={resolved().total} emptyText={props.emptyText} />
+ </span>
+ <Show when={props.suffix}>
+ {(suffix) => <span class="ml-1 text-muted"> {suffix()}</span>}
+ </Show>
</span>
- <Show when={props.suffix}>
- {(suffix) => <span class="ml-1 text-muted"> {suffix()}</span>}
- </Show>
- </span>
+ )}
</Show>
);
}