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.

Centralize approval presentation labels

rcourtmanfdb83d393574
diff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.md
index b5601fe35d..db5d5b3b12 100644
--- a/docs/release-control/v6/internal/subsystems/unified-resources.md
+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md
@@ -542,7 +542,10 @@ Canonical resources now carry first-class graph-expansion fields: `Capabilities`
inter-resource links with direction and confidence), and `RecentChanges` (typed
change timeline entries with source, confidence, and related-resource
references). These fields are defined in `capabilities.go`, `relationships.go`,
-`changes.go`, `privacy.go`, and `actions.go`. The store now also owns a
+`changes.go`, `privacy.go`, and `actions.go`. The frontend capability drawer
+now formats the shared approval-level vocabulary through a canonical
+presentation helper instead of a local switch, so the resource model and the
+rendered labels stay aligned. The store now also owns a
`resource_changes` persistence table with `RecordChange` and `GetRecentChanges`
methods so change history is queryable by canonical ID and time window.
The shared change presentation helper also owns the canonical kind, source
diff --git a/frontend-modern/src/components/Infrastructure/ResourceDetailDrawer.tsx b/frontend-modern/src/components/Infrastructure/ResourceDetailDrawer.tsx
index 2ef0cd21ff..36285dd38b 100644
--- a/frontend-modern/src/components/Infrastructure/ResourceDetailDrawer.tsx
+++ b/frontend-modern/src/components/Infrastructure/ResourceDetailDrawer.tsx
@@ -57,6 +57,7 @@ import { ResourceGraphSummary } from './ResourceGraphSummary';
import { ResourceChangeSummary } from './ResourceChangeSummary';
import { ResourceFacetSummary } from './ResourceFacetSummary';
import { ResourcePolicySummary } from './ResourcePolicySummary';
+import { getResourceApprovalLevelLabel } from '@/utils/approvalPresentation';
import {
RESOURCE_CHANGE_KIND_ORDER,
RESOURCE_CHANGE_SOURCE_ADAPTER_ORDER,
@@ -609,21 +610,6 @@ const DrawerContent: Component<ResourceDetailDrawerProps> = (props) => {
}
});
- const formatApprovalLevel = (value?: string) => {
- switch ((value || '').trim()) {
- case 'none':
- return 'None';
- case 'dry_run_only':
- return 'Dry Run Only';
- case 'admin':
- return 'Admin';
- case 'mfa':
- return 'MFA';
- default:
- return humanizeToken(value, { fallback: '—', preserveShortAllCaps: true });
- }
- };
-
const handleCopyJson = async () => {
const payload = debugJson();
try {
@@ -1633,7 +1619,7 @@ const DrawerContent: Component<ResourceDetailDrawerProps> = (props) => {
<div class="flex items-center justify-between gap-2">
<span class="text-muted">Approval</span>
<span class="font-medium text-base-content">
- {formatApprovalLevel(capability.minimumApprovalLevel)}
+ {getResourceApprovalLevelLabel(capability.minimumApprovalLevel)}
</span>
</div>
<Show when={capability.platform}>
diff --git a/frontend-modern/src/utils/__tests__/approvalPresentation.test.ts b/frontend-modern/src/utils/__tests__/approvalPresentation.test.ts
new file mode 100644
index 0000000000..50da92eb13
--- /dev/null
+++ b/frontend-modern/src/utils/__tests__/approvalPresentation.test.ts
@@ -0,0 +1,18 @@
+import { describe, expect, it } from 'vitest';
+
+import { getResourceApprovalLevelLabel } from '@/utils/approvalPresentation';
+
+describe('approvalPresentation', () => {
+ it('formats canonical approval labels', () => {
+ expect(getResourceApprovalLevelLabel('none')).toBe('None');
+ expect(getResourceApprovalLevelLabel('dry_run_only')).toBe('Dry Run Only');
+ expect(getResourceApprovalLevelLabel('admin')).toBe('Admin');
+ expect(getResourceApprovalLevelLabel('mfa')).toBe('MFA');
+ });
+
+ it('falls back safely for unknown approval levels', () => {
+ expect(getResourceApprovalLevelLabel('strict')).toBe('Strict');
+ expect(getResourceApprovalLevelLabel('')).toBe('—');
+ expect(getResourceApprovalLevelLabel(undefined)).toBe('—');
+ });
+});
diff --git a/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts b/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts
index 94ad46fcfa..c0f0c2d1ce 100644
--- a/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts
+++ b/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts
@@ -75,6 +75,7 @@ import resourceChangePresentationSource from '@/utils/resourceChangePresentation
import resourceRelationshipPresentationSource from '@/utils/resourceRelationshipPresentation.ts?raw';
import resourceCorrelationPresentationSource from '@/utils/resourceCorrelationPresentation.ts?raw';
import confidencePresentationSource from '@/utils/confidencePresentation.ts?raw';
+import approvalPresentationSource from '@/utils/approvalPresentation.ts?raw';
import textPresentationSource from '@/utils/textPresentation.ts?raw';
import messageItemSource from '@/components/AI/Chat/MessageItem.tsx?raw';
import toolExecutionBlockSource from '@/components/AI/Chat/ToolExecutionBlock.tsx?raw';
@@ -1916,6 +1917,7 @@ describe('frontend resource type boundaries', () => {
expect(resourceCorrelationPresentationSource).toContain('formatConfidencePercentage');
expect(confidencePresentationSource).toContain('formatConfidencePercentage');
expect(confidencePresentationSource).toContain('formatConfidenceLabel');
+ expect(approvalPresentationSource).toContain('getResourceApprovalLevelLabel');
expect(resourceChangePresentationSource).toContain('humanizeToken');
expect(resourceRelationshipPresentationSource).toContain('humanizeToken');
expect(resourceCorrelationPresentationSource).toContain('humanizeToken');
diff --git a/frontend-modern/src/utils/approvalPresentation.ts b/frontend-modern/src/utils/approvalPresentation.ts
new file mode 100644
index 0000000000..c96479ce85
--- /dev/null
+++ b/frontend-modern/src/utils/approvalPresentation.ts
@@ -0,0 +1,18 @@
+import type { ResourceApprovalLevel } from '@/types/resource';
+import { humanizeToken } from '@/utils/textPresentation';
+
+const APPROVAL_LEVEL_LABELS: Record<ResourceApprovalLevel, string> = {
+ none: 'None',
+ dry_run_only: 'Dry Run Only',
+ admin: 'Admin',
+ mfa: 'MFA',
+};
+
+export function getResourceApprovalLevelLabel(level?: ResourceApprovalLevel | string): string {
+ if (!level) {
+ return '—';
+ }
+
+ const normalized = level.trim() as ResourceApprovalLevel;
+ return APPROVAL_LEVEL_LABELS[normalized] ?? humanizeToken(normalized, { fallback: '—' });
+}