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 alert detail formatters

rcourtmand07c0a004ff3
diff --git a/docs/release-control/v6/internal/subsystems/alerts.md b/docs/release-control/v6/internal/subsystems/alerts.md
index f92fec0aa6..781e817174 100644
--- a/docs/release-control/v6/internal/subsystems/alerts.md
+++ b/docs/release-control/v6/internal/subsystems/alerts.md
@@ -528,6 +528,13 @@ frontend-primitives owns the visible platform severity badge and dot shells in
`frontend-modern/src/components/shared/AlertSeverityBadge.tsx`. Platform alert
tables must consume that split instead of recreating provider-local severity
label, text-class, detail-tone, or variant helpers.
+Platform alert detail field formatting is also a shared alerts presentation
+boundary. `frontend-modern/src/utils/alertDetailPresentation.ts` owns provider
+code labels, provider-specific resource-type labels, vSphere alert entity
+labels, row timestamp labels, and detail timestamp labels for Docker,
+Kubernetes, TrueNAS, and vSphere alert tables. Platform alert tables must call
+those helpers instead of recreating local `formatCode`, `formatResourceType`,
+`formatEntityType`, `formatStartedAt`, or `detailDateTime` helpers.
Alert history filter defaults such as the all-time period option must likewise
come from the alert overview/history presentation helper and the shared
filter-option label primitive rather than hard-coded title-case strings in the
diff --git a/docs/release-control/v6/internal/subsystems/frontend-primitives.md b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
index 961f69d435..8d106d4cf0 100644
--- a/docs/release-control/v6/internal/subsystems/frontend-primitives.md
+++ b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
@@ -2433,6 +2433,15 @@ owns the canonical All/Critical/Warning/Info option labels, tones, and leading
dots for platform alert table toolbars. Platform alert tables must call
`getPlatformAlertSeverityFilterOptions` instead of declaring local severity
filter arrays or calling `filterChipStatusDot` directly for those filters.
+Platform alert detail formatting follows the same by-construction primitive
+rule. `frontend-modern/src/utils/alertDetailPresentation.ts` owns the provider
+code labels, provider-specific resource-type labels, vSphere alert entity
+labels, started-at row labels, and full detail timestamp labels consumed by
+Docker, Kubernetes, TrueNAS, and vSphere alert tables. Those tables must call
+`formatPlatformAlertCode`, `formatPlatformAlertResourceType`,
+`formatPlatformAlertEntityType`, `formatPlatformAlertStartedAt`, and
+`formatPlatformAlertDetailDateTime` instead of declaring local formatter
+helpers.
Read-only metadata badges follow the same primitive-owned shell rule.
`frontend-modern/src/components/shared/MetadataBadge.tsx` owns filled and
outlined appearances, compact sizing, shape, typed tone vocabulary, fit
diff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.md
index 74cc5dbd8b..a2fc090bf0 100644
--- a/docs/release-control/v6/internal/subsystems/unified-resources.md
+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md
@@ -1789,6 +1789,13 @@ severity-label helpers, detail severity row tones must use
and their severity toolbar filters must use
`getPlatformAlertSeverityFilterOptions` instead of restoring local
All/Critical/Warning/Info option arrays,
+and platform alert detail fields must use
+`formatPlatformAlertCode`, `formatPlatformAlertResourceType`,
+`formatPlatformAlertEntityType`, `formatPlatformAlertStartedAt`, and
+`formatPlatformAlertDetailDateTime` from
+`frontend-modern/src/utils/alertDetailPresentation.ts` instead of restoring
+table-local provider code, resource-type, entity-type, or timestamp formatter
+helpers,
and local operator identity labels now split from governed detail summaries:
infrastructure tables, selectors, links, and drawer headings must preserve the
canonical local instance identity (`displayName`, canonical display name,
diff --git a/frontend-modern/scripts/shared-template-registry.json b/frontend-modern/scripts/shared-template-registry.json
index 1db4ccd089..499d958404 100644
--- a/frontend-modern/scripts/shared-template-registry.json
+++ b/frontend-modern/scripts/shared-template-registry.json
@@ -857,6 +857,65 @@
"scripts/shared-template-audit.mjs"
]
},
+ {
+ "id": "platform-alert-detail-formatters",
+ "category": "detail-formatting",
+ "summary": "Platform alert tables must get provider code, resource-type, entity-type, and timestamp labels from alertDetailPresentation instead of defining table-local detail formatter helpers.",
+ "canonical": {
+ "path": "src/utils/alertDetailPresentation.ts",
+ "export": "formatPlatformAlertCode"
+ },
+ "requiredConsumers": [
+ { "path": "src/features/docker/DockerAlertsTable.tsx" },
+ { "path": "src/features/kubernetes/KubernetesAlertsTable.tsx" },
+ { "path": "src/features/truenas/TrueNASAlertsTable.tsx" },
+ { "path": "src/features/vmware/VsphereAlertsTable.tsx" }
+ ],
+ "forbiddenPatterns": [
+ {
+ "path": "src/features/docker/DockerAlertsTable.tsx",
+ "patterns": [
+ "const formatResourceType",
+ "const formatCode",
+ "const formatStartedAt",
+ "const detailDateTime"
+ ]
+ },
+ {
+ "path": "src/features/kubernetes/KubernetesAlertsTable.tsx",
+ "patterns": [
+ "const formatResourceType",
+ "const formatCode",
+ "const formatStartedAt",
+ "const detailDateTime"
+ ]
+ },
+ {
+ "path": "src/features/truenas/TrueNASAlertsTable.tsx",
+ "patterns": [
+ "const formatResourceType",
+ "const formatCode",
+ "const formatStartedAt",
+ "const detailDateTime"
+ ]
+ },
+ {
+ "path": "src/features/vmware/VsphereAlertsTable.tsx",
+ "patterns": [
+ "const formatResourceType",
+ "const formatEntityType",
+ "const formatCode",
+ "const formatStartedAt",
+ "const detailDateTime"
+ ]
+ }
+ ],
+ "proof": [
+ "src/components/shared/SharedPrimitives.guardrails.test.ts",
+ "src/utils/__tests__/alertDetailPresentation.test.ts",
+ "scripts/shared-template-audit.mjs"
+ ]
+ },
{
"id": "metadata-badge-shell",
"category": "metadata-badge",
@@ -1685,6 +1744,126 @@
"scripts/shared-template-audit.mjs"
]
},
+ {
+ "id": "platform-alert-local-code-formatter-helper",
+ "category": "detail-formatting",
+ "summary": "Platform alert tables must not recreate provider-code formatter helpers; alert code labels belong to alertDetailPresentation.",
+ "canonical": {
+ "path": "src/utils/alertDetailPresentation.ts",
+ "export": "formatPlatformAlertCode"
+ },
+ "scopes": [
+ "src/features/docker",
+ "src/features/kubernetes",
+ "src/features/truenas",
+ "src/features/vmware"
+ ],
+ "extensions": [".tsx"],
+ "allPatterns": ["const formatCode", "IncidentRow"],
+ "legacyReason": "Retired migration debt. Platform alert code labels must call formatPlatformAlertCode instead of carrying page-local prefix stripping and title casing.",
+ "allowedPaths": [],
+ "ignoredPaths": [],
+ "proof": [
+ "src/components/shared/SharedPrimitives.guardrails.test.ts",
+ "src/utils/__tests__/alertDetailPresentation.test.ts",
+ "scripts/shared-template-audit.mjs"
+ ]
+ },
+ {
+ "id": "platform-alert-local-resource-type-formatter-helper",
+ "category": "detail-formatting",
+ "summary": "Platform alert tables must not recreate resource-type formatter helpers; provider-specific resource labels belong to alertDetailPresentation.",
+ "canonical": {
+ "path": "src/utils/alertDetailPresentation.ts",
+ "export": "formatPlatformAlertResourceType"
+ },
+ "scopes": [
+ "src/features/docker",
+ "src/features/kubernetes",
+ "src/features/truenas",
+ "src/features/vmware"
+ ],
+ "extensions": [".tsx"],
+ "allPatterns": ["const formatResourceType", "IncidentRow"],
+ "legacyReason": "Retired migration debt. Platform alert resource-type labels must call formatPlatformAlertResourceType instead of carrying page-local switch maps.",
+ "allowedPaths": [],
+ "ignoredPaths": [],
+ "proof": [
+ "src/components/shared/SharedPrimitives.guardrails.test.ts",
+ "src/utils/__tests__/alertDetailPresentation.test.ts",
+ "scripts/shared-template-audit.mjs"
+ ]
+ },
+ {
+ "id": "platform-alert-local-started-at-formatter-helper",
+ "category": "detail-formatting",
+ "summary": "Platform alert tables must not recreate started-at timestamp formatter helpers; alert timestamp labels belong to alertDetailPresentation.",
+ "canonical": {
+ "path": "src/utils/alertDetailPresentation.ts",
+ "export": "formatPlatformAlertStartedAt"
+ },
+ "scopes": [
+ "src/features/docker",
+ "src/features/kubernetes",
+ "src/features/truenas",
+ "src/features/vmware"
+ ],
+ "extensions": [".tsx"],
+ "allPatterns": ["const formatStartedAt", "IncidentRow"],
+ "legacyReason": "Retired migration debt. Platform alert row timestamps must call formatPlatformAlertStartedAt instead of carrying page-local date formatting.",
+ "allowedPaths": [],
+ "ignoredPaths": [],
+ "proof": [
+ "src/components/shared/SharedPrimitives.guardrails.test.ts",
+ "src/utils/__tests__/alertDetailPresentation.test.ts",
+ "scripts/shared-template-audit.mjs"
+ ]
+ },
+ {
+ "id": "platform-alert-local-detail-date-formatter-helper",
+ "category": "detail-formatting",
+ "summary": "Platform alert tables must not recreate detail timestamp formatter helpers; alert detail date labels belong to alertDetailPresentation.",
+ "canonical": {
+ "path": "src/utils/alertDetailPresentation.ts",
+ "export": "formatPlatformAlertDetailDateTime"
+ },
+ "scopes": [
+ "src/features/docker",
+ "src/features/kubernetes",
+ "src/features/truenas",
+ "src/features/vmware"
+ ],
+ "extensions": [".tsx"],
+ "allPatterns": ["const detailDateTime", "IncidentRow"],
+ "legacyReason": "Retired migration debt. Platform alert detail timestamps must call formatPlatformAlertDetailDateTime instead of carrying page-local date formatting.",
+ "allowedPaths": [],
+ "ignoredPaths": [],
+ "proof": [
+ "src/components/shared/SharedPrimitives.guardrails.test.ts",
+ "src/utils/__tests__/alertDetailPresentation.test.ts",
+ "scripts/shared-template-audit.mjs"
+ ]
+ },
+ {
+ "id": "platform-alert-local-entity-type-formatter-helper",
+ "category": "detail-formatting",
+ "summary": "vSphere alert tables must not recreate entity-type formatter helpers; vSphere alert entity labels belong to alertDetailPresentation.",
+ "canonical": {
+ "path": "src/utils/alertDetailPresentation.ts",
+ "export": "formatPlatformAlertEntityType"
+ },
+ "scopes": ["src/features/vmware"],
+ "extensions": [".tsx"],
+ "allPatterns": ["const formatEntityType", "VmwareIncidentRow"],
+ "legacyReason": "Retired migration debt. vSphere alert entity labels must call formatPlatformAlertEntityType instead of carrying page-local normalization.",
+ "allowedPaths": [],
+ "ignoredPaths": [],
+ "proof": [
+ "src/components/shared/SharedPrimitives.guardrails.test.ts",
+ "src/utils/__tests__/alertDetailPresentation.test.ts",
+ "scripts/shared-template-audit.mjs"
+ ]
+ },
{
"id": "patrol-finding-metadata-badge-local-shell",
"category": "metadata-badge",
@@ -2592,6 +2771,35 @@
"scripts/shared-template-audit.mjs"
]
},
+ {
+ "id": "platform-alert-detail-formatters-required",
+ "category": "detail-formatting",
+ "summary": "Feature alert tables with incident-row detail code and started-at fields must compose the shared platform alert detail formatter primitive.",
+ "canonical": {
+ "path": "src/utils/alertDetailPresentation.ts",
+ "export": "formatPlatformAlertCode"
+ },
+ "scopes": [
+ "src/features/docker",
+ "src/features/kubernetes",
+ "src/features/truenas",
+ "src/features/vmware"
+ ],
+ "extensions": [".tsx"],
+ "triggerPatterns": ["IncidentRow", "incident.code", "incident.startedAt"],
+ "requiredPatterns": [
+ "formatPlatformAlertCode",
+ "formatPlatformAlertStartedAt",
+ "formatPlatformAlertDetailDateTime"
+ ],
+ "allowedPaths": [],
+ "ignoredPaths": [],
+ "proof": [
+ "src/components/shared/SharedPrimitives.guardrails.test.ts",
+ "src/utils/__tests__/alertDetailPresentation.test.ts",
+ "scripts/shared-template-audit.mjs"
+ ]
+ },
{
"id": "platform-row-detail-toggle-inline-detail",
"category": "row-disclosure",
diff --git a/frontend-modern/src/components/shared/SharedPrimitives.guardrails.test.ts b/frontend-modern/src/components/shared/SharedPrimitives.guardrails.test.ts
index 5089f9a5f3..3e0f92452d 100644
--- a/frontend-modern/src/components/shared/SharedPrimitives.guardrails.test.ts
+++ b/frontend-modern/src/components/shared/SharedPrimitives.guardrails.test.ts
@@ -112,6 +112,7 @@ import sharedTemplateRegistrySource from '../../../scripts/shared-template-regis
import discoveryTabSource from '@/components/Discovery/DiscoveryTab.tsx?raw';
import emailProviderSelectSource from '@/components/Alerts/EmailProviderSelect.tsx?raw';
import incidentTimelinePanelSource from '@/components/Alerts/IncidentTimelinePanel.tsx?raw';
+import alertDetailPresentationSource from '@/utils/alertDetailPresentation.ts?raw';
import alertSeverityPresentationSource from '@/utils/alertSeverityPresentation.ts?raw';
import thresholdsTableDockerIgnoredPrefixesSectionSource from '@/components/Alerts/ThresholdsTableDockerIgnoredPrefixesSection.tsx?raw';
import webhookConfigFormSource from '@/components/Alerts/WebhookConfigForm.tsx?raw';
@@ -1708,18 +1709,39 @@ describe('shared primitive guardrails', () => {
const detailToneRule = registry.rules?.find(
(rule) => rule.id === 'platform-alert-severity-detail-tone',
);
+ const detailFormatterRule = registry.rules?.find(
+ (rule) => rule.id === 'platform-alert-detail-formatters',
+ );
const localHelperGuard = registry.patternGuards?.find(
(guard) => guard.id === 'platform-alert-severity-local-helper',
);
const localDetailToneGuard = registry.patternGuards?.find(
(guard) => guard.id === 'platform-alert-severity-local-detail-tone-helper',
);
+ const localCodeFormatterGuard = registry.patternGuards?.find(
+ (guard) => guard.id === 'platform-alert-local-code-formatter-helper',
+ );
+ const localResourceTypeFormatterGuard = registry.patternGuards?.find(
+ (guard) => guard.id === 'platform-alert-local-resource-type-formatter-helper',
+ );
+ const localStartedAtFormatterGuard = registry.patternGuards?.find(
+ (guard) => guard.id === 'platform-alert-local-started-at-formatter-helper',
+ );
+ const localDetailDateFormatterGuard = registry.patternGuards?.find(
+ (guard) => guard.id === 'platform-alert-local-detail-date-formatter-helper',
+ );
+ const localEntityTypeFormatterGuard = registry.patternGuards?.find(
+ (guard) => guard.id === 'platform-alert-local-entity-type-formatter-helper',
+ );
const requiredGuard = registry.requiredPatternGuards?.find(
(guard) => guard.id === 'platform-alert-severity-indicator-required',
);
const requiredFilterOptionsGuard = registry.requiredPatternGuards?.find(
(guard) => guard.id === 'platform-alert-severity-filter-options-required',
);
+ const requiredDetailFormatterGuard = registry.requiredPatternGuards?.find(
+ (guard) => guard.id === 'platform-alert-detail-formatters-required',
+ );
const alertTableConsumerPaths = [
'src/features/docker/DockerAlertsTable.tsx',
'src/features/kubernetes/KubernetesAlertsTable.tsx',
@@ -1744,6 +1766,11 @@ describe('shared primitive guardrails', () => {
expect(detailToneRule?.requiredConsumers?.map((consumer) => consumer.path)).toEqual(
alertTableConsumerPaths,
);
+ expect(detailFormatterRule?.canonical?.path).toBe('src/utils/alertDetailPresentation.ts');
+ expect(detailFormatterRule?.canonical?.export).toBe('formatPlatformAlertCode');
+ expect(detailFormatterRule?.requiredConsumers?.map((consumer) => consumer.path)).toEqual(
+ alertTableConsumerPaths,
+ );
expect(registeredRule?.forbiddenPatterns).toEqual(
alertTableConsumerPaths.map((path) => ({
path,
@@ -1789,6 +1816,45 @@ describe('shared primitive guardrails', () => {
patterns: ['const alertTone', 'type AlertDetailTone'],
})),
);
+ expect(detailFormatterRule?.forbiddenPatterns).toEqual([
+ {
+ path: 'src/features/docker/DockerAlertsTable.tsx',
+ patterns: [
+ 'const formatResourceType',
+ 'const formatCode',
+ 'const formatStartedAt',
+ 'const detailDateTime',
+ ],
+ },
+ {
+ path: 'src/features/kubernetes/KubernetesAlertsTable.tsx',
+ patterns: [
+ 'const formatResourceType',
+ 'const formatCode',
+ 'const formatStartedAt',
+ 'const detailDateTime',
+ ],
+ },
+ {
+ path: 'src/features/truenas/TrueNASAlertsTable.tsx',
+ patterns: [
+ 'const formatResourceType',
+ 'const formatCode',
+ 'const formatStartedAt',
+ 'const detailDateTime',
+ ],
+ },
+ {
+ path: 'src/features/vmware/VsphereAlertsTable.tsx',
+ patterns: [
+ 'const formatResourceType',
+ 'const formatEntityType',
+ 'const formatCode',
+ 'const formatStartedAt',
+ 'const detailDateTime',
+ ],
+ },
+ ]);
expect(localHelperGuard?.canonical?.path).toBe('src/components/shared/AlertSeverityBadge.tsx');
expect(localHelperGuard?.canonical?.export).toBe('AlertSeverityBadge');
expect(localHelperGuard?.allPatterns).toEqual(['severityVariant', 'severityTextClass']);
@@ -1811,6 +1877,82 @@ describe('shared primitive guardrails', () => {
]);
expect(localDetailToneGuard?.allowedPaths ?? []).toHaveLength(0);
expect(localDetailToneGuard?.ignoredPaths ?? []).toHaveLength(0);
+ expect(localCodeFormatterGuard?.canonical?.path).toBe('src/utils/alertDetailPresentation.ts');
+ expect(localCodeFormatterGuard?.canonical?.export).toBe('formatPlatformAlertCode');
+ expect(localCodeFormatterGuard?.allPatterns).toEqual(['const formatCode', 'IncidentRow']);
+ expect(localCodeFormatterGuard?.scopes).toEqual([
+ 'src/features/docker',
+ 'src/features/kubernetes',
+ 'src/features/truenas',
+ 'src/features/vmware',
+ ]);
+ expect(localCodeFormatterGuard?.allowedPaths ?? []).toHaveLength(0);
+ expect(localCodeFormatterGuard?.ignoredPaths ?? []).toHaveLength(0);
+ expect(localResourceTypeFormatterGuard?.canonical?.path).toBe(
+ 'src/utils/alertDetailPresentation.ts',
+ );
+ expect(localResourceTypeFormatterGuard?.canonical?.export).toBe(
+ 'formatPlatformAlertResourceType',
+ );
+ expect(localResourceTypeFormatterGuard?.allPatterns).toEqual([
+ 'const formatResourceType',
+ 'IncidentRow',
+ ]);
+ expect(localResourceTypeFormatterGuard?.scopes).toEqual([
+ 'src/features/docker',
+ 'src/features/kubernetes',
+ 'src/features/truenas',
+ 'src/features/vmware',
+ ]);
+ expect(localResourceTypeFormatterGuard?.allowedPaths ?? []).toHaveLength(0);
+ expect(localResourceTypeFormatterGuard?.ignoredPaths ?? []).toHaveLength(0);
+ expect(localStartedAtFormatterGuard?.canonical?.path).toBe(
+ 'src/utils/alertDetailPresentation.ts',
+ );
+ expect(localStartedAtFormatterGuard?.canonical?.export).toBe('formatPlatformAlertStartedAt');
+ expect(localStartedAtFormatterGuard?.allPatterns).toEqual([
+ 'const formatStartedAt',
+ 'IncidentRow',
+ ]);
+ expect(localStartedAtFormatterGuard?.scopes).toEqual([
+ 'src/features/docker',
+ 'src/features/kubernetes',
+ 'src/features/truenas',
+ 'src/features/vmware',
+ ]);
+ expect(localStartedAtFormatterGuard?.allowedPaths ?? []).toHaveLength(0);
+ expect(localStartedAtFormatterGuard?.ignoredPaths ?? []).toHaveLength(0);
+ expect(localDetailDateFormatterGuard?.canonical?.path).toBe(
+ 'src/utils/alertDetailPresentation.ts',
+ );
+ expect(localDetailDateFormatterGuard?.canonical?.export).toBe(
+ 'formatPlatformAlertDetailDateTime',
+ );
+ expect(localDetailDateFormatterGuard?.allPatterns).toEqual([
+ 'const detailDateTime',
+ 'IncidentRow',
+ ]);
+ expect(localDetailDateFormatterGuard?.scopes).toEqual([
+ 'src/features/docker',
+ 'src/features/kubernetes',
+ 'src/features/truenas',
+ 'src/features/vmware',
+ ]);
+ expect(localDetailDateFormatterGuard?.allowedPaths ?? []).toHaveLength(0);
+ expect(localDetailDateFormatterGuard?.ignoredPaths ?? []).toHaveLength(0);
+ expect(localEntityTypeFormatterGuard?.canonical?.path).toBe(
+ 'src/utils/alertDetailPresentation.ts',
+ );
+ expect(localEntityTypeFormatterGuard?.canonical?.export).toBe(
+ 'formatPlatformAlertEntityType',
+ );
+ expect(localEntityTypeFormatterGuard?.allPatterns).toEqual([
+ 'const formatEntityType',
+ 'VmwareIncidentRow',
+ ]);
+ expect(localEntityTypeFormatterGuard?.scopes).toEqual(['src/features/vmware']);
+ expect(localEntityTypeFormatterGuard?.allowedPaths ?? []).toHaveLength(0);
+ expect(localEntityTypeFormatterGuard?.ignoredPaths ?? []).toHaveLength(0);
expect(requiredGuard?.canonical?.path).toBe('src/components/shared/AlertSeverityBadge.tsx');
expect(requiredGuard?.canonical?.export).toBe('AlertSeverityBadge');
expect(requiredGuard?.triggerPatterns).toEqual([
@@ -1837,6 +1979,22 @@ describe('shared primitive guardrails', () => {
]);
expect(requiredFilterOptionsGuard?.allowedPaths ?? []).toHaveLength(0);
expect(requiredFilterOptionsGuard?.ignoredPaths ?? []).toHaveLength(0);
+ expect(requiredDetailFormatterGuard?.canonical?.path).toBe(
+ 'src/utils/alertDetailPresentation.ts',
+ );
+ expect(requiredDetailFormatterGuard?.canonical?.export).toBe('formatPlatformAlertCode');
+ expect(requiredDetailFormatterGuard?.triggerPatterns).toEqual([
+ 'IncidentRow',
+ 'incident.code',
+ 'incident.startedAt',
+ ]);
+ expect(requiredDetailFormatterGuard?.requiredPatterns).toEqual([
+ 'formatPlatformAlertCode',
+ 'formatPlatformAlertStartedAt',
+ 'formatPlatformAlertDetailDateTime',
+ ]);
+ expect(requiredDetailFormatterGuard?.allowedPaths ?? []).toHaveLength(0);
+ expect(requiredDetailFormatterGuard?.ignoredPaths ?? []).toHaveLength(0);
expect(alertSeverityBadgeSource).toContain('StatusIndicatorBadge');
expect(alertSeverityBadgeSource).toContain('StatusDot');
@@ -1848,6 +2006,11 @@ describe('shared primitive guardrails', () => {
expect(alertSeverityPresentationSource).toContain('getAlertSeverityIndicatorVariant');
expect(alertSeverityPresentationSource).toContain('getAlertSeverityDetailTone');
expect(alertSeverityPresentationSource).toContain('formatAlertSeverityLabel');
+ expect(alertDetailPresentationSource).toContain('formatPlatformAlertCode');
+ expect(alertDetailPresentationSource).toContain('formatPlatformAlertResourceType');
+ expect(alertDetailPresentationSource).toContain('formatPlatformAlertEntityType');
+ expect(alertDetailPresentationSource).toContain('formatPlatformAlertStartedAt');
+ expect(alertDetailPresentationSource).toContain('formatPlatformAlertDetailDateTime');
for (const source of [
dockerAlertsTableSource,
@@ -1860,10 +2023,18 @@ describe('shared primitive guardrails', () => {
expect(source).toContain('formatAlertSeverityLabel');
expect(source).toContain('getAlertSeverityDetailTone');
expect(source).toContain('getPlatformAlertSeverityFilterOptions');
+ expect(source).toContain('formatPlatformAlertCode');
+ expect(source).toContain('formatPlatformAlertResourceType');
+ expect(source).toContain('formatPlatformAlertStartedAt');
+ expect(source).toContain('formatPlatformAlertDetailDateTime');
expect(source).not.toContain('severityVariant');
expect(source).not.toContain('severityTextClass');
expect(source).not.toContain('const alertTone');
expect(source).not.toContain('type AlertDetailTone');
+ expect(source).not.toContain('const formatResourceType');
+ expect(source).not.toContain('const formatCode');
+ expect(source).not.toContain('const formatStartedAt');
+ expect(source).not.toContain('const detailDateTime');
expect(source).not.toContain('filterChipStatusDot(');
expect(source).not.toContain("value: 'critical'");
expect(source).not.toContain("value: 'warning'");
diff --git a/frontend-modern/src/features/docker/DockerAlertsTable.tsx b/frontend-modern/src/features/docker/DockerAlertsTable.tsx
index 4f17226ac5..511464c292 100644
--- a/frontend-modern/src/features/docker/DockerAlertsTable.tsx
+++ b/frontend-modern/src/features/docker/DockerAlertsTable.tsx
@@ -23,7 +23,12 @@ import {
getPlatformResourceDetailRowClass,
} from '@/features/platformPage/PlatformResourceDetailTableRow';
import { getPlatformAlertSeverityFilterOptions } from '@/features/platformPage/platformAlertSeverityFilterOptions';
-import type { ResourceType } from '@/types/resource';
+import {
+ formatPlatformAlertCode,
+ formatPlatformAlertDetailDateTime,
+ formatPlatformAlertResourceType,
+ formatPlatformAlertStartedAt,
+} from '@/utils/alertDetailPresentation';
import { getAlertFilteredEmptyState } from '@/utils/alertOverviewPresentation';
import {
formatAlertSeverityLabel,
@@ -38,70 +43,6 @@ import {
const DOCKER_INCIDENT_STATUS_OPTIONS =
getPlatformAlertSeverityFilterOptions<DockerIncidentSeverityFilter>();
-const formatResourceType = (type: ResourceType): string => {
- switch (type) {
- case 'agent':
- return 'Host';
- case 'app-container':
- return 'Container';
- case 'docker-service':
- return 'Service';
- case 'docker-task':
- return 'Task';
- case 'docker-swarm-node':
- return 'Swarm Node';
- case 'docker-image':
- return 'Image';
- case 'docker-volume':
- return 'Volume';
- case 'docker-network':
- return 'Network';
- case 'docker-secret':
- return 'Secret';
- case 'docker-config':
- return 'Config';
- default:
- return type;
- }
-};
-
-const formatCode = (code: string): string => {
- const normalized = code.trim().replace(/^docker_/, '');
- if (!normalized) return '-';
- return normalized
- .split(/[\s_-]+/)
- .filter(Boolean)
- .map((part) => part.charAt(0).toUpperCase() + part.slice(1).toLowerCase())
- .join(' ');
-};
-
-const formatStartedAt = (value: string | undefined): string => {
- if (!value) return '-';
- const parsed = new Date(value);
- if (Number.isNaN(parsed.getTime())) return '-';
- if (parsed.getUTCFullYear() < 2000) return '-';
- return parsed.toLocaleString(undefined, {
- month: 'short',
- day: 'numeric',
- hour: '2-digit',
- minute: '2-digit',
- });
-};
-
-const detailDateTime = (value?: string): string => {
- if (!value) return '-';
- const parsed = new Date(value);
- if (Number.isNaN(parsed.getTime())) return value;
- if (parsed.getUTCFullYear() < 2000) return '-';
- return parsed.toLocaleString(undefined, {
- month: 'short',
- day: 'numeric',
- year: 'numeric',
- hour: '2-digit',
- minute: '2-digit',
- });
-};
-
type AlertDetailSection = DetailSection;
const detailRow = makeDetailRow;
@@ -117,14 +58,16 @@ const buildAlertDetailSections = (incident: DockerIncidentRow): AlertDetailSecti
}),
detailRow('Summary', incident.summary),
detailRow('Signal', incident.label),
- detailRow('Code', formatCode(incident.code), { title: incident.code }),
+ detailRow('Code', formatPlatformAlertCode(incident.code, 'docker'), {
+ title: incident.code,
+ }),
]),
},
{
label: 'Affected resource',
rows: compactDetailRows([
detailRow('Name', incident.resourceName),
- detailRow('Type', formatResourceType(incident.resourceType)),
+ detailRow('Type', formatPlatformAlertResourceType(incident.resourceType, 'docker')),
detailRow('Host', docker?.hostname),
detailRow('Runtime', docker?.runtime),
detailRow('Swarm cluster', docker?.swarm?.clusterName),
@@ -134,7 +77,7 @@ const buildAlertDetailSections = (incident: DockerIncidentRow): AlertDetailSecti
{
label: 'Source',
rows: compactDetailRows([
- detailRow('Started', detailDateTime(incident.startedAt)),
+ detailRow('Started', formatPlatformAlertDetailDateTime(incident.startedAt)),
detailRow('Provider', incident.source),
]),
},
@@ -150,8 +93,9 @@ const AlertDetail: Component<{ incident: DockerIncidentRow; onClose: () => void
testId="docker-alert-detail"
detailFor={props.incident.id}
title="Docker alert detail"
- summary={`${formatAlertSeverityLabel(props.incident.severity)} · ${formatCode(
+ summary={`${formatAlertSeverityLabel(props.incident.severity)} · ${formatPlatformAlertCode(
props.incident.code,
+ 'docker',
)}`}
sections={buildAlertDetailSections(props.incident)}
detailAttributes={{ 'data-docker-alert-detail-for': props.incident.id }}
@@ -280,7 +224,7 @@ export const DockerAlertsTable: Component<{
{incident.resourceName}
</div>
<div class="truncate text-[10px] text-muted">
- {formatResourceType(incident.resourceType)}
+ {formatPlatformAlertResourceType(incident.resourceType, 'docker')}
<Show when={incident.resource.parentName}>
on {incident.resource.parentName}
</Show>
@@ -312,13 +256,13 @@ export const DockerAlertsTable: Component<{
{docker()?.hostname || docker()?.swarm?.clusterName || '-'}
</span>
<span class="block truncate text-[10px] text-muted">
- {docker()?.runtime || formatCode(incident.code)}
+ {docker()?.runtime || formatPlatformAlertCode(incident.code, 'docker')}
</span>
</TableCell>
<TableCell
class={`${getPlatformTableCellClassForKind('text')} hidden text-base-content lg:table-cell`}
>
- {formatStartedAt(incident.startedAt)}
+ {formatPlatformAlertStartedAt(incident.startedAt)}
</TableCell>
<TableCell
class={`${getPlatformTableCellClassForKind('text')} hidden text-base-content xl:table-cell`}
diff --git a/frontend-modern/src/features/kubernetes/KubernetesAlertsTable.tsx b/frontend-modern/src/features/kubernetes/KubernetesAlertsTable.tsx
index 7c85fafaaf..c37c3e9045 100644
--- a/frontend-modern/src/features/kubernetes/KubernetesAlertsTable.tsx
+++ b/frontend-modern/src/features/kubernetes/KubernetesAlertsTable.tsx
@@ -23,7 +23,12 @@ import {
getPlatformResourceDetailRowClass,
} from '@/features/platformPage/PlatformResourceDetailTableRow';
import { getPlatformAlertSeverityFilterOptions } from '@/features/platformPage/platformAlertSeverityFilterOptions';
-import type { ResourceType } from '@/types/resource';
+import {
+ formatPlatformAlertCode,
+ formatPlatformAlertDetailDateTime,
+ formatPlatformAlertResourceType,
+ formatPlatformAlertStartedAt,
+} from '@/utils/alertDetailPresentation';
import { getAlertFilteredEmptyState } from '@/utils/alertOverviewPresentation';
import {
formatAlertSeverityLabel,
@@ -38,82 +43,6 @@ import {
const KUBERNETES_INCIDENT_STATUS_OPTIONS =
getPlatformAlertSeverityFilterOptions<KubernetesIncidentSeverityFilter>();
-const formatResourceType = (type: ResourceType): string => {
- switch (type) {
- case 'agent':
- return 'Node';
- case 'k8s-cluster':
- return 'Cluster';
- case 'k8s-node':
- return 'Node';
- case 'pod':
- return 'Pod';
- case 'k8s-deployment':
- return 'Deployment';
- case 'k8s-replicaset':
- return 'ReplicaSet';
- case 'k8s-statefulset':
- return 'StatefulSet';
- case 'k8s-daemonset':
- return 'DaemonSet';
- case 'k8s-job':
- return 'Job';
- case 'k8s-cronjob':
- return 'CronJob';
- case 'k8s-service':
- return 'Service';
- case 'k8s-ingress':
- return 'Ingress';
- case 'k8s-namespace':
- return 'Namespace';
- case 'k8s-event':
- return 'Event';
- case 'k8s-persistent-volume':
- return 'PersistentVolume';
- case 'k8s-persistent-volume-claim':
- return 'PVC';
- default:
- return type;
- }
-};
-
-const formatCode = (code: string): string => {
- const normalized = code.trim().replace(/^k8s_/, '');
- if (!normalized) return '-';
- return normalized
- .split(/[\s_-]+/)
- .filter(Boolean)
- .map((part) => part.charAt(0).toUpperCase() + part.slice(1).toLowerCase())
- .join(' ');
-};
-
-const formatStartedAt = (value: string | undefined): string => {
- if (!value) return '-';
- const parsed = new Date(value);
- if (Number.isNaN(parsed.getTime())) return '-';
- if (parsed.getUTCFullYear() < 2000) return '-';
- return parsed.toLocaleString(undefined, {
- month: 'short',
- day: 'numeric',
- hour: '2-digit',
- minute: '2-digit',
- });
-};
-
-const detailDateTime = (value?: string): string => {
- if (!value) return '-';
- const parsed = new Date(value);
- if (Number.isNaN(parsed.getTime())) return value;
- if (parsed.getUTCFullYear() < 2000) return '-';
- return parsed.toLocaleString(undefined, {
- month: 'short',
- day: 'numeric',
- year: 'numeric',
- hour: '2-digit',
- minute: '2-digit',
- });
-};
-
type AlertDetailSection = DetailSection;
const detailRow = makeDetailRow;
@@ -130,14 +59,16 @@ const buildAlertDetailSections = (incident: KubernetesIncidentRow): AlertDetailS
}),
detailRow('Summary', incident.summary),
detailRow('Signal', incident.label),
- detailRow('Code', formatCode(incident.code), { title: incident.code }),
+ detailRow('Code', formatPlatformAlertCode(incident.code, 'kubernetes'), {
+ title: incident.code,
+ }),
]),
},
{
label: 'Affected resource',
rows: compactDetailRows([
detailRow('Name', incident.resourceName),
- detailRow('Type', formatResourceType(incident.resourceType)),
+ detailRow('Type', formatPlatformAlertResourceType(incident.resourceType, 'kubernetes')),
detailRow('Cluster', k?.clusterName || k?.clusterId),
detailRow('Namespace', k?.namespace),
detailRow('Node', k?.nodeName),
@@ -148,7 +79,7 @@ const buildAlertDetailSections = (incident: KubernetesIncidentRow): AlertDetailS
{
label: 'Source',
rows: compactDetailRows([
- detailRow('Started', detailDateTime(incident.startedAt)),
+ detailRow('Started', formatPlatformAlertDetailDateTime(incident.startedAt)),
detailRow('Provider', incident.source),
]),
},
@@ -166,8 +97,9 @@ const AlertDetail: Component<{ incident: KubernetesIncidentRow; onClose: () => v
testId="kubernetes-alert-detail"
detailFor={props.incident.id}
title="Kubernetes alert detail"
- summary={`${formatAlertSeverityLabel(props.incident.severity)} · ${formatCode(
+ summary={`${formatAlertSeverityLabel(props.incident.severity)} · ${formatPlatformAlertCode(
props.incident.code,
+ 'kubernetes',
)}`}
sections={buildAlertDetailSections(props.incident)}
detailAttributes={{ 'data-kubernetes-alert-detail-for': props.incident.id }}
@@ -302,7 +234,10 @@ export const KubernetesAlertsTable: Component<{
{incident.resourceName}
</div>
<div class="truncate text-[10px] text-muted">
- {formatResourceType(incident.resourceType)}
+ {formatPlatformAlertResourceType(
+ incident.resourceType,
+ 'kubernetes',
+ )}
<Show when={k()?.ownerKind && k()?.ownerName}>
· {k()?.ownerKind}/{k()?.ownerName}
</Show>
@@ -331,13 +266,13 @@ export const KubernetesAlertsTable: Component<{
{scopeText()}
</span>
<span class="block truncate text-[10px] text-muted">
- {k()?.nodeName || formatCode(incident.code)}
+ {k()?.nodeName || formatPlatformAlertCode(incident.code, 'kubernetes')}
</span>
</TableCell>
<TableCell
class={`${getPlatformTableCellClassForKind('text')} hidden text-base-content lg:table-cell`}
>
- {formatStartedAt(incident.startedAt)}
+ {formatPlatformAlertStartedAt(incident.startedAt)}
</TableCell>
<TableCell
class={`${getPlatformTableCellClassForKind('text')} hidden text-base-content xl:table-cell`}
diff --git a/frontend-modern/src/features/truenas/TrueNASAlertsTable.tsx b/frontend-modern/src/features/truenas/TrueNASAlertsTable.tsx
index 422f54aa39..4b691bf4b8 100644
--- a/frontend-modern/src/features/truenas/TrueNASAlertsTable.tsx
+++ b/frontend-modern/src/features/truenas/TrueNASAlertsTable.tsx
@@ -28,7 +28,13 @@ import {
makeDetailRow,
type DetailSection,
} from '@/components/shared/DetailSectionTable';
-import type { Resource, ResourceType } from '@/types/resource';
+import type { Resource } from '@/types/resource';
+import {
+ formatPlatformAlertCode,
+ formatPlatformAlertDetailDateTime,
+ formatPlatformAlertResourceType,
+ formatPlatformAlertStartedAt,
+} from '@/utils/alertDetailPresentation';
import { getAlertFilteredEmptyState } from '@/utils/alertOverviewPresentation';
import {
formatAlertSeverityLabel,
@@ -38,65 +44,8 @@ import {
const TRUENAS_INCIDENT_STATUS_OPTIONS =
getPlatformAlertSeverityFilterOptions<TrueNASIncidentSeverityFilter>();
-const formatResourceType = (type: ResourceType): string => {
- switch (type) {
- case 'agent':
- return 'System';
- case 'storage':
- case 'pool':
- return 'Pool';
- case 'dataset':
- return 'Dataset';
- case 'physical_disk':
- return 'Disk';
- case 'network-share':
- return 'Share';
- case 'vm':
- return 'VM';
- case 'app-container':
- return 'App';
- default:
- return type;
- }
-};
-
-const formatCode = (code: string): string => {
- const normalized = code.trim().replace(/^truenas_/, '');
- if (!normalized) return '-';
- return normalized
- .split(/[\s_-]+/)
- .filter(Boolean)
- .map((part) => part.charAt(0).toUpperCase() + part.slice(1).toLowerCase())
- .join(' ');
-};
-
-const formatStartedAt = (value: string | undefined): string => {
- if (!value) return '-';
- const parsed = new Date(value);
- if (Number.isNaN(parsed.getTime())) return '-';
- return parsed.toLocaleString(undefined, {
- month: 'short',
- day: 'numeric',
- hour: '2-digit',
- minute: '2-digit',
- });
-};
-
type AlertDetailSection = DetailSection;
-const detailDateTime = (value?: string): string | null => {
- if (!value) return null;
- const parsed = new Date(value);
- if (Number.isNaN(parsed.getTime())) return value;
- return parsed.toLocaleString(undefined, {
- month: 'short',
- day: 'numeric',
- year: 'numeric',
- hour: '2-digit',
- minute: '2-digit',
- });
-};
-
const detailRow = makeDetailRow;
const buildAlertDetailSections = (incident: TrueNASIncidentRow): AlertDetailSection[] => {
@@ -110,22 +59,24 @@ const buildAlertDetailSections = (incident: TrueNASIncidentRow): AlertDetailSect
}),
detailRow('Summary', incident.summary),
detailRow('Label', incident.label),
- detailRow('Code', formatCode(incident.code), { title: incident.code }),
- detailRow('Category', formatCode(incident.category)),
+ detailRow('Code', formatPlatformAlertCode(incident.code, 'truenas'), {
+ title: incident.code,
+ }),
+ detailRow('Category', formatPlatformAlertCode(incident.category, 'truenas')),
]),
},
{
label: 'Source',
rows: compactDetailRows([
detailRow('Provider', incident.source),
- detailRow('Started', detailDateTime(incident.startedAt)),
+ detailRow('Started', formatPlatformAlertDetailDateTime(incident.startedAt)),
]),
},
{
label: 'Affected resource',
rows: compactDetailRows([
detailRow('Name', incident.resourceName),
- detailRow('Type', formatResourceType(incident.resourceType)),
+ detailRow('Type', formatPlatformAlertResourceType(incident.resourceType, 'truenas')),
detailRow('Parent', parentName),
detailRow('Resource ID', incident.resourceId),
]),
@@ -144,8 +95,9 @@ const AlertDetailTable: Component<{ incident: TrueNASIncidentRow; onClose: () =>
testId="truenas-alert-detail"
detailFor={props.incident.id}
title="Alert detail"
- summary={`${formatAlertSeverityLabel(props.incident.severity)} · ${formatCode(
+ summary={`${formatAlertSeverityLabel(props.incident.severity)} · ${formatPlatformAlertCode(
props.incident.code,
+ 'truenas',
)}`}
sections={buildAlertDetailSections(props.incident)}
detailAttributes={{ 'data-truenas-alert-detail-for': props.incident.id }}
@@ -274,7 +226,10 @@ export const TrueNASAlertsTable: Component<{
{incident.resourceName}
</div>
<div class="truncate text-[10px] text-muted">
- {formatResourceType(incident.resourceType)}
+ {formatPlatformAlertResourceType(
+ incident.resourceType,
+ 'truenas',
+ )}
<Show when={incident.resource.parentName}>
on {incident.resource.parentName}
</Show>
@@ -300,7 +255,7 @@ export const TrueNASAlertsTable: Component<{
class={`${getPlatformTableCellClassForKind('text')} hidden md:table-cell`}
>
<span class="block truncate" title={incident.code}>
- {formatCode(incident.code)}
+ {formatPlatformAlertCode(incident.code, 'truenas')}
</span>
<span class="block truncate text-[10px] text-muted">
{incident.source}
@@ -309,7 +264,7 @@ export const TrueNASAlertsTable: Component<{
<TableCell
class={`${getPlatformTableCellClassForKind('text')} hidden text-base-content lg:table-cell`}
>
- {formatStartedAt(incident.startedAt)}
+ {formatPlatformAlertStartedAt(incident.startedAt)}
</TableCell>
<TableCell
class={`${getPlatformTableCellClassForKind('text')} hidden text-base-content xl:table-cell`}
diff --git a/frontend-modern/src/features/vmware/VsphereAlertsTable.tsx b/frontend-modern/src/features/vmware/VsphereAlertsTable.tsx
index 5eedd66236..98b786dfa9 100644
--- a/frontend-modern/src/features/vmware/VsphereAlertsTable.tsx
+++ b/frontend-modern/src/features/vmware/VsphereAlertsTable.tsx
@@ -23,7 +23,13 @@ import {
getPlatformResourceDetailRowClass,
} from '@/features/platformPage/PlatformResourceDetailTableRow';
import { getPlatformAlertSeverityFilterOptions } from '@/features/platformPage/platformAlertSeverityFilterOptions';
-import type { ResourceType } from '@/types/resource';
+import {
+ formatPlatformAlertCode,
+ formatPlatformAlertDetailDateTime,
+ formatPlatformAlertEntityType,
+ formatPlatformAlertResourceType,
+ formatPlatformAlertStartedAt,
+} from '@/utils/alertDetailPresentation';
import { getAlertFilteredEmptyState } from '@/utils/alertOverviewPresentation';
import {
formatAlertSeverityLabel,
@@ -38,64 +44,6 @@ import {
const VSPHERE_INCIDENT_STATUS_OPTIONS =
getPlatformAlertSeverityFilterOptions<VmwareIncidentSeverityFilter>();
-const formatResourceType = (type: ResourceType): string => {
- switch (type) {
- case 'agent':
- return 'Host';
- case 'vm':
- return 'VM';
- case 'storage':
- return 'Datastore';
- default:
- return type;
- }
-};
-
-const formatEntityType = (value: string): string => {
- const normalized = value.trim().toLowerCase();
- if (normalized === 'host') return 'Host';
- if (normalized === 'vm') return 'VM';
- if (normalized === 'datastore') return 'Datastore';
- return normalized ? normalized.charAt(0).toUpperCase() + normalized.slice(1) : '-';
-};
-
-const formatCode = (code: string): string => {
- const normalized = code.trim().replace(/^vmware_/, '');
- if (!normalized) return '-';
- return normalized
- .split(/[\s_-]+/)
- .filter(Boolean)
- .map((part) => part.charAt(0).toUpperCase() + part.slice(1).toLowerCase())
- .join(' ');
-};
-
-const formatStartedAt = (value: string | undefined): string => {
- if (!value) return '-';
- const parsed = new Date(value);
- if (Number.isNaN(parsed.getTime())) return '-';
- if (parsed.getUTCFullYear() < 2000) return '-';
- return parsed.toLocaleString(undefined, {
- month: 'short',
- day: 'numeric',
- hour: '2-digit',
- minute: '2-digit',
- });
-};
-
-const detailDateTime = (value?: string): string => {
- if (!value) return '-';
- const parsed = new Date(value);
- if (Number.isNaN(parsed.getTime())) return value;
- if (parsed.getUTCFullYear() < 2000) return '-';
- return parsed.toLocaleString(undefined, {
- month: 'short',
- day: 'numeric',
- year: 'numeric',
- hour: '2-digit',
- minute: '2-digit',
- });
-};
-
type AlertDetailSection = DetailSection;
const detailRow = makeDetailRow;
@@ -111,15 +59,17 @@ const buildAlertDetailSections = (incident: VmwareIncidentRow): AlertDetailSecti
}),
detailRow('Summary', incident.summary),
detailRow('Signal', incident.label),
- detailRow('Code', formatCode(incident.code), { title: incident.code }),
+ detailRow('Code', formatPlatformAlertCode(incident.code, 'vmware'), {
+ title: incident.code,
+ }),
]),
},
{
label: 'Affected resource',
rows: compactDetailRows([
detailRow('Resource', incident.resourceName),
- detailRow('Type', formatResourceType(incident.resourceType)),
- detailRow('Entity', formatEntityType(incident.entityType)),
+ detailRow('Type', formatPlatformAlertResourceType(incident.resourceType, 'vmware')),
+ detailRow('Entity', formatPlatformAlertEntityType(incident.entityType)),
detailRow('Managed object', incident.managedObjectId),
detailRow('vCenter', meta?.connectionName || meta?.vcenterHost),
detailRow('Datacenter', meta?.datacenterName),
@@ -130,7 +80,7 @@ const buildAlertDetailSections = (incident: VmwareIncidentRow): AlertDetailSecti
{
label: 'Source',
rows: compactDetailRows([
- detailRow('Started', detailDateTime(incident.startedAt)),
+ detailRow('Started', formatPlatformAlertDetailDateTime(incident.startedAt)),
detailRow('Provider', incident.source),
]),
},
@@ -146,8 +96,9 @@ const AlertDetail: Component<{ incident: VmwareIncidentRow; onClose: () => void
testId="vsphere-alert-detail"
detailFor={props.incident.id}
title="vSphere health detail"
- summary={`${formatAlertSeverityLabel(props.incident.severity)} · ${formatCode(
+ summary={`${formatAlertSeverityLabel(props.incident.severity)} · ${formatPlatformAlertCode(
props.incident.code,
+ 'vmware',
)}`}
sections={buildAlertDetailSections(props.incident)}
detailAttributes={{ 'data-vsphere-alert-detail-for': props.incident.id }}
@@ -276,7 +227,7 @@ export const VsphereAlertsTable: Component<{
{incident.resourceName}
</div>
<div class="truncate text-[10px] text-muted">
- {formatResourceType(incident.resourceType)}
+ {formatPlatformAlertResourceType(incident.resourceType, 'vmware')}
<Show when={incident.resource.parentName}>
on {incident.resource.parentName}
</Show>
@@ -315,7 +266,7 @@ export const VsphereAlertsTable: Component<{
class={`${getPlatformTableCellClassForKind('text')} hidden text-base-content lg:table-cell`}
>
<span class="block truncate" title={incident.managedObjectId}>
- {formatEntityType(incident.entityType)}
+ {formatPlatformAlertEntityType(incident.entityType)}
</span>
<span class="block truncate text-[10px] text-muted">
{incident.managedObjectId}
@@ -324,7 +275,7 @@ export const VsphereAlertsTable: Component<{
<TableCell
class={`${getPlatformTableCellClassForKind('text')} hidden text-base-content xl:table-cell`}
>
- {formatStartedAt(incident.startedAt)}
+ {formatPlatformAlertStartedAt(incident.startedAt)}
</TableCell>
</TableRow>
<Show when={isExpanded()}>
diff --git a/frontend-modern/src/utils/__tests__/alertDetailPresentation.test.ts b/frontend-modern/src/utils/__tests__/alertDetailPresentation.test.ts
new file mode 100644
index 0000000000..44899e3d55
--- /dev/null
+++ b/frontend-modern/src/utils/__tests__/alertDetailPresentation.test.ts
@@ -0,0 +1,42 @@
+import { describe, expect, it } from 'vitest';
+import {
+ formatPlatformAlertCode,
+ formatPlatformAlertDetailDateTime,
+ formatPlatformAlertEntityType,
+ formatPlatformAlertResourceType,
+ formatPlatformAlertStartedAt,
+} from '@/utils/alertDetailPresentation';
+
+describe('alertDetailPresentation', () => {
+ it('formats provider alert codes with canonical prefix stripping and title casing', () => {
+ expect(formatPlatformAlertCode('docker_restart_loop', 'docker')).toBe('Restart Loop');
+ expect(formatPlatformAlertCode('k8s_pod_crash_loop', 'kubernetes')).toBe('Pod Crash Loop');
+ expect(formatPlatformAlertCode('truenas_pool_degraded', 'truenas')).toBe('Pool Degraded');
+ expect(formatPlatformAlertCode('vmware_datastore_low_space', 'vmware')).toBe(
+ 'Datastore Low Space',
+ );
+ expect(formatPlatformAlertCode('')).toBe('-');
+ });
+
+ it('maps platform alert resource types through provider-specific labels', () => {
+ expect(formatPlatformAlertResourceType('app-container', 'docker')).toBe('Container');
+ expect(formatPlatformAlertResourceType('app-container', 'truenas')).toBe('App');
+ expect(formatPlatformAlertResourceType('agent', 'kubernetes')).toBe('Node');
+ expect(formatPlatformAlertResourceType('storage', 'vmware')).toBe('Datastore');
+ });
+
+ it('formats vSphere alert entity types consistently', () => {
+ expect(formatPlatformAlertEntityType('vm')).toBe('VM');
+ expect(formatPlatformAlertEntityType('datastore')).toBe('Datastore');
+ expect(formatPlatformAlertEntityType('distributed_switch')).toBe('Distributed_switch');
+ expect(formatPlatformAlertEntityType('')).toBe('-');
+ });
+
+ it('formats table and detail timestamps with the alert table fallbacks', () => {
+ expect(formatPlatformAlertStartedAt(undefined)).toBe('-');
+ expect(formatPlatformAlertStartedAt('1999-12-31T23:59:59Z')).toBe('-');
+ expect(formatPlatformAlertDetailDateTime(undefined)).toBe('-');
+ expect(formatPlatformAlertDetailDateTime('not-a-date')).toBe('not-a-date');
+ expect(formatPlatformAlertDetailDateTime('1999-12-31T23:59:59Z')).toBe('-');
+ });
+});
diff --git a/frontend-modern/src/utils/alertDetailPresentation.ts b/frontend-modern/src/utils/alertDetailPresentation.ts
new file mode 100644
index 0000000000..50e2fa9765
--- /dev/null
+++ b/frontend-modern/src/utils/alertDetailPresentation.ts
@@ -0,0 +1,130 @@
+import type { ResourceType } from '@/types/resource';
+
+export type PlatformAlertProvider = 'docker' | 'kubernetes' | 'truenas' | 'vmware';
+
+const CODE_PREFIX_BY_PROVIDER: Record<PlatformAlertProvider, string> = {
+ docker: 'docker_',
+ kubernetes: 'k8s_',
+ truenas: 'truenas_',
+ vmware: 'vmware_',
+};
+
+const RESOURCE_TYPE_LABELS: Record<PlatformAlertProvider, Partial<Record<ResourceType, string>>> =
+ {
+ docker: {
+ agent: 'Host',
+ 'app-container': 'Container',
+ 'docker-service': 'Service',
+ 'docker-task': 'Task',
+ 'docker-swarm-node': 'Swarm Node',
+ 'docker-image': 'Image',
+ 'docker-volume': 'Volume',
+ 'docker-network': 'Network',
+ 'docker-secret': 'Secret',
+ 'docker-config': 'Config',
+ },
+ kubernetes: {
+ agent: 'Node',
+ 'k8s-cluster': 'Cluster',
+ 'k8s-node': 'Node',
+ pod: 'Pod',
+ 'k8s-deployment': 'Deployment',
+ 'k8s-replicaset': 'ReplicaSet',
+ 'k8s-statefulset': 'StatefulSet',
+ 'k8s-daemonset': 'DaemonSet',
+ 'k8s-job': 'Job',
+ 'k8s-cronjob': 'CronJob',
+ 'k8s-service': 'Service',
+ 'k8s-ingress': 'Ingress',
+ 'k8s-namespace': 'Namespace',
+ 'k8s-event': 'Event',
+ 'k8s-persistent-volume': 'PersistentVolume',
+ 'k8s-persistent-volume-claim': 'PVC',
+ },
+ truenas: {
+ agent: 'System',
+ storage: 'Pool',
+ pool: 'Pool',
+ dataset: 'Dataset',
+ physical_disk: 'Disk',
+ 'network-share': 'Share',
+ vm: 'VM',
+ 'app-container': 'App',
+ },
+ vmware: {
+ agent: 'Host',
+ vm: 'VM',
+ storage: 'Datastore',
+ },
+ };
+
+const titleCaseToken = (part: string): string =>
+ part.charAt(0).toUpperCase() + part.slice(1).toLowerCase();
+
+const isUnsetDate = (date: Date): boolean =>
+ Number.isNaN(date.getTime()) || date.getUTCFullYear() < 2000;
+
+export function formatPlatformAlertCode(
+ code: string,
+ provider?: PlatformAlertProvider,
+): string {
+ const trimmed = code.trim();
+ const prefix = provider ? CODE_PREFIX_BY_PROVIDER[provider] : undefined;
+ const normalized =
+ prefix && trimmed.startsWith(prefix)
+ ? trimmed.slice(prefix.length)
+ : trimmed.replace(/^(docker|k8s|truenas|vmware)_/, '');
+
+ if (!normalized) return '-';
+
+ return normalized
+ .split(/[\s_-]+/)
+ .filter(Boolean)
+ .map(titleCaseToken)
+ .join(' ');
+}
+
+export function formatPlatformAlertResourceType(
+ type: ResourceType,
+ provider: PlatformAlertProvider,
+): string {
+ return RESOURCE_TYPE_LABELS[provider][type] ?? type;
+}
+
+export function formatPlatformAlertEntityType(value: string): string {
+ const normalized = value.trim().toLowerCase();
+ if (normalized === 'host') return 'Host';
+ if (normalized === 'vm') return 'VM';
+ if (normalized === 'datastore') return 'Datastore';
+ return normalized ? titleCaseToken(normalized) : '-';
+}
+
+export function formatPlatformAlertStartedAt(value: string | undefined): string {
+ if (!value) return '-';
+
+ const parsed = new Date(value);
+ if (isUnsetDate(parsed)) return '-';
+
+ return parsed.toLocaleString(undefined, {
+ month: 'short',
+ day: 'numeric',
+ hour: '2-digit',
+ minute: '2-digit',
+ });
+}
+
+export function formatPlatformAlertDetailDateTime(value?: string): string {
+ if (!value) return '-';
+
+ const parsed = new Date(value);
+ if (Number.isNaN(parsed.getTime())) return value;
+ if (parsed.getUTCFullYear() < 2000) return '-';
+
+ return parsed.toLocaleString(undefined, {
+ month: 'short',
+ day: 'numeric',
+ year: 'numeric',
+ hour: '2-digit',
+ minute: '2-digit',
+ });
+}