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.

Canonicalize resource change label presentation

rcourtman76e6c3786724
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index ccf4de93f1..7bb6e9781b 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -219,6 +219,10 @@ That shared presentation layer also owns the elapsed-time and "ago" wording
utilities, so the same "time ago" phrasing stays consistent across resource,
incident, and fallback memory summaries instead of being reformatted
independently.
+The canonical resource-change kind, source type, and source adapter labels
+now also come from the shared change presentation helper, so the resource
+summary card and drawer history use the same badge vocabulary instead of
+hardcoding their own labels.
Resource-only incident context should follow the same rule: if an alert
timeline is absent, the incident prompt path should fall back to the canonical
unified-resource timeline rather than depending only on patrol-local change
diff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.md
index 69badcb864..40fd66501a 100644
--- a/docs/release-control/v6/internal/subsystems/unified-resources.md
+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md
@@ -504,6 +504,10 @@ references). These fields are defined in `capabilities.go`, `relationships.go`,
`changes.go`, `privacy.go`, and `actions.go`. 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
+type, and source adapter labels for those timeline entries, so summary cards
+and drawer history surfaces both read the same badge vocabulary instead of
+rebuilding resource-change labels locally.
That frontend consumer rule now applies on the canonical decode path too:
`frontend-modern/src/hooks/useUnifiedResources.ts` must preserve backend-owned
diff --git a/frontend-modern/src/components/Infrastructure/ResourceChangeSummary.tsx b/frontend-modern/src/components/Infrastructure/ResourceChangeSummary.tsx
index 33cea6fb7d..b2cbf48e12 100644
--- a/frontend-modern/src/components/Infrastructure/ResourceChangeSummary.tsx
+++ b/frontend-modern/src/components/Infrastructure/ResourceChangeSummary.tsx
@@ -3,8 +3,10 @@ import type { ResourceChange } from '@/types/resource';
import { formatRelativeTime } from '@/utils/format';
import { buildInfrastructureResourceHref } from '@/routing/resourceLinks';
import {
+ getResourceChangeKindPresentation,
+ getResourceChangeSourceAdapterPresentation,
+ getResourceChangeSourceTypePresentation,
formatResourceChangeHeadline,
- formatResourceChangeKind,
sortResourceChangesByObservedAt,
} from '@/utils/resourceChangePresentation';
@@ -75,6 +77,13 @@ export const ResourceChangeSummary: Component<ResourceChangeSummaryProps> = (pro
const headline = formatResourceChangeHeadline(change);
const resourceHref = buildResourceHref(change.resourceId);
const relatedResources = (change.relatedResources ?? []).slice(0, 3);
+ const kindPresentation = getResourceChangeKindPresentation(change.kind);
+ const sourceTypePresentation = getResourceChangeSourceTypePresentation(
+ change.sourceType,
+ );
+ const sourceAdapterPresentation = change.sourceAdapter
+ ? getResourceChangeSourceAdapterPresentation(change.sourceAdapter)
+ : null;
return (
<li class={`rounded-md border border-border-subtle bg-base ${itemPadding()}`}>
@@ -111,20 +120,26 @@ export const ResourceChangeSummary: Component<ResourceChangeSummaryProps> = (pro
<div class="flex flex-wrap items-center gap-1.5">
<span
- class={`rounded-full border border-border-subtle bg-surface px-2 py-0.5 ${badgeText()} font-medium text-muted`}
+ class={`rounded-full border px-2 py-0.5 ${badgeText()} font-medium ${
+ kindPresentation.className
+ }`}
>
- {formatResourceChangeKind(change.kind)}
+ {kindPresentation.label}
</span>
<span
- class={`rounded-full border border-border-subtle bg-surface px-2 py-0.5 ${badgeText()} font-medium text-muted`}
+ class={`rounded-full border px-2 py-0.5 ${badgeText()} font-medium ${
+ sourceTypePresentation.className
+ }`}
>
- {change.sourceType}
+ {sourceTypePresentation.label}
</span>
- <Show when={change.sourceAdapter}>
+ <Show when={sourceAdapterPresentation}>
<span
- class={`rounded-full border border-border-subtle bg-surface px-2 py-0.5 ${badgeText()} font-medium text-muted`}
+ class={`rounded-full border px-2 py-0.5 ${badgeText()} font-medium ${
+ sourceAdapterPresentation!.className
+ }`}
>
- {change.sourceAdapter}
+ {sourceAdapterPresentation!.label}
</span>
</Show>
</div>
diff --git a/frontend-modern/src/components/Infrastructure/ResourceDetailDrawer.tsx b/frontend-modern/src/components/Infrastructure/ResourceDetailDrawer.tsx
index 494bb851f1..3ef600194a 100644
--- a/frontend-modern/src/components/Infrastructure/ResourceDetailDrawer.tsx
+++ b/frontend-modern/src/components/Infrastructure/ResourceDetailDrawer.tsx
@@ -56,6 +56,14 @@ import { ResourceGraphSummary } from './ResourceGraphSummary';
import { ResourceChangeSummary } from './ResourceChangeSummary';
import { ResourceFacetSummary } from './ResourceFacetSummary';
import { ResourcePolicySummary } from './ResourcePolicySummary';
+import {
+ RESOURCE_CHANGE_KIND_ORDER,
+ RESOURCE_CHANGE_SOURCE_ADAPTER_ORDER,
+ RESOURCE_CHANGE_SOURCE_TYPE_ORDER,
+ getResourceChangeKindPresentation,
+ getResourceChangeSourceAdapterPresentation,
+ getResourceChangeSourceTypePresentation,
+} from '@/utils/resourceChangePresentation';
import type { ResourceIntelligence } from '@/types/aiIntelligence';
import { buildInfrastructureResourceHref } from '@/routing/resourceLinks';
@@ -83,30 +91,27 @@ const hasMetadataEntries = (value?: Record<string, unknown> | null): boolean =>
const timelineKindOptions: Array<{ label: string; value: ResourceChangeKind | '' }> = [
{ label: 'All kinds', value: '' },
- { label: 'State transition', value: 'state_transition' },
- { label: 'Restart', value: 'restart' },
- { label: 'Config update', value: 'config_update' },
- { label: 'Metric anomaly', value: 'metric_anomaly' },
- { label: 'Relationship change', value: 'relationship_change' },
- { label: 'Capability change', value: 'capability_change' },
+ ...RESOURCE_CHANGE_KIND_ORDER.map((kind) => ({
+ label: getResourceChangeKindPresentation(kind).label,
+ value: kind,
+ })),
];
const timelineSourceTypeOptions: Array<{ label: string; value: ResourceChangeSourceType | '' }> = [
{ label: 'All sources', value: '' },
- { label: 'Platform event', value: 'platform_event' },
- { label: 'Pulse diff', value: 'pulse_diff' },
- { label: 'Heuristic', value: 'heuristic' },
- { label: 'User action', value: 'user_action' },
- { label: 'Agent action', value: 'agent_action' },
+ ...RESOURCE_CHANGE_SOURCE_TYPE_ORDER.map((sourceType) => ({
+ label: getResourceChangeSourceTypePresentation(sourceType).label,
+ value: sourceType,
+ })),
];
const timelineSourceAdapterOptions: Array<{ label: string; value: ResourceChangeSourceAdapter | '' }> =
[
{ label: 'All adapters', value: '' },
- { label: 'Docker adapter', value: 'docker_adapter' },
- { label: 'Proxmox adapter', value: 'proxmox_adapter' },
- { label: 'TrueNAS adapter', value: 'truenas_adapter' },
- { label: 'Ops agent', value: 'agent:ops-helper' },
+ ...RESOURCE_CHANGE_SOURCE_ADAPTER_ORDER.map((sourceAdapter) => ({
+ label: getResourceChangeSourceAdapterPresentation(sourceAdapter).label,
+ value: sourceAdapter,
+ })),
];
const DrawerContent: Component<ResourceDetailDrawerProps> = (props) => {
@@ -1827,91 +1832,99 @@ const DrawerContent: Component<ResourceDetailDrawerProps> = (props) => {
>
<div class="space-y-2">
<For each={sortedResourceTimeline()}>
- {(change) => (
- <div class="rounded border border-border bg-surface-hover px-2 py-1.5 text-[10px]">
- <div class="flex items-start justify-between gap-3">
- <div class="min-w-0">
- <div class="font-medium text-base-content">
- {humanizeFacetToken(change.kind)}
- </div>
- <div class="mt-0.5 text-muted">
- {formatFacetTimestamp(change.observedAt)}
- <Show when={change.occurredAt}>
- <span class="mx-1">•</span>
- <span>Occurred {formatFacetTimestamp(change.occurredAt)}</span>
- </Show>
+ {(change) => {
+ const kindPresentation = getResourceChangeKindPresentation(change.kind);
+ const sourceTypePresentation = getResourceChangeSourceTypePresentation(
+ change.sourceType,
+ );
+ const sourceAdapterPresentation = change.sourceAdapter
+ ? getResourceChangeSourceAdapterPresentation(change.sourceAdapter)
+ : null;
+
+ return (
+ <div class="rounded border border-border bg-surface-hover px-2 py-1.5 text-[10px]">
+ <div class="flex items-start justify-between gap-3">
+ <div class="min-w-0">
+ <div class="font-medium text-base-content">{kindPresentation.label}</div>
+ <div class="mt-0.5 text-muted">
+ {formatFacetTimestamp(change.observedAt)}
+ <Show when={change.occurredAt}>
+ <span class="mx-1">•</span>
+ <span>Occurred {formatFacetTimestamp(change.occurredAt)}</span>
+ </Show>
+ </div>
</div>
+ <span class="text-muted">{sourceTypePresentation.label}</span>
</div>
- <span class="text-muted">{humanizeFacetToken(change.sourceType)}</span>
- </div>
- <div class="mt-1 grid gap-1 sm:grid-cols-2">
- <div class="flex items-center justify-between gap-2">
- <span class="text-muted">Confidence</span>
- <span class="font-medium text-base-content">
- {formatConfidence(change.confidence)}
- </span>
- </div>
- <div class="flex items-center justify-between gap-2">
- <span class="text-muted">Adapter</span>
- <span class="font-medium text-base-content">
- {change.sourceAdapter || '—'}
- </span>
- </div>
- <Show when={change.actor}>
+ <div class="mt-1 grid gap-1 sm:grid-cols-2">
<div class="flex items-center justify-between gap-2">
- <span class="text-muted">Actor</span>
- <span class="font-medium text-base-content">{change.actor}</span>
+ <span class="text-muted">Confidence</span>
+ <span class="font-medium text-base-content">
+ {formatConfidence(change.confidence)}
+ </span>
</div>
- </Show>
- <Show when={change.from || change.to}>
<div class="flex items-center justify-between gap-2">
- <span class="text-muted">Transition</span>
+ <span class="text-muted">Adapter</span>
<span class="font-medium text-base-content">
- {change.from || '—'} → {change.to || '—'}
+ {sourceAdapterPresentation?.label || '—'}
</span>
</div>
+ <Show when={change.actor}>
+ <div class="flex items-center justify-between gap-2">
+ <span class="text-muted">Actor</span>
+ <span class="font-medium text-base-content">{change.actor}</span>
+ </div>
+ </Show>
+ <Show when={change.from || change.to}>
+ <div class="flex items-center justify-between gap-2">
+ <span class="text-muted">Transition</span>
+ <span class="font-medium text-base-content">
+ {change.from || '—'} → {change.to || '—'}
+ </span>
+ </div>
+ </Show>
+ </div>
+ <Show when={change.reason}>
+ <div class="mt-1 rounded border border-border bg-base px-2 py-1 text-[10px] text-base-content">
+ {change.reason}
+ </div>
+ </Show>
+ <Show when={hasMetadataEntries(change.metadata)}>
+ <details class="mt-1 rounded border border-border bg-base px-2 py-1">
+ <summary class="cursor-pointer list-none text-[10px] font-medium text-muted">
+ Metadata
+ </summary>
+ <pre class="mt-2 overflow-auto whitespace-pre-wrap break-words text-[10px] text-base-content">
+ {JSON.stringify(change.metadata ?? {}, null, 2)}
+ </pre>
+ </details>
+ </Show>
+ <Show when={change.relatedResources && change.relatedResources.length > 0}>
+ <div class="mt-1 flex flex-wrap items-center gap-1 text-muted">
+ <span>Related:</span>
+ <For each={change.relatedResources ?? []}>
+ {(relatedResource) => {
+ const href = buildInfrastructureResourceHref(relatedResource);
+ return href ? (
+ <a
+ class="inline-flex rounded bg-surface px-1.5 py-0.5 text-[10px] text-blue-700 hover:underline dark:text-blue-300"
+ href={href}
+ aria-label={`Open related resource ${relatedResource} in Infrastructure`}
+ >
+ {relatedResource}
+ </a>
+ ) : (
+ <span class="inline-flex rounded bg-surface px-1.5 py-0.5 text-[10px] text-base-content">
+ {relatedResource}
+ </span>
+ );
+ }}
+ </For>
+ </div>
</Show>
</div>
- <Show when={change.reason}>
- <div class="mt-1 rounded border border-border bg-base px-2 py-1 text-[10px] text-base-content">
- {change.reason}
- </div>
- </Show>
- <Show when={hasMetadataEntries(change.metadata)}>
- <details class="mt-1 rounded border border-border bg-base px-2 py-1">
- <summary class="cursor-pointer list-none text-[10px] font-medium text-muted">
- Metadata
- </summary>
- <pre class="mt-2 overflow-auto whitespace-pre-wrap break-words text-[10px] text-base-content">
- {JSON.stringify(change.metadata ?? {}, null, 2)}
- </pre>
- </details>
- </Show>
- <Show when={change.relatedResources && change.relatedResources.length > 0}>
- <div class="mt-1 flex flex-wrap items-center gap-1 text-muted">
- <span>Related:</span>
- <For each={change.relatedResources ?? []}>
- {(relatedResource) => {
- const href = buildInfrastructureResourceHref(relatedResource);
- return href ? (
- <a
- class="inline-flex rounded bg-surface px-1.5 py-0.5 text-[10px] text-blue-700 hover:underline dark:text-blue-300"
- href={href}
- aria-label={`Open related resource ${relatedResource} in Infrastructure`}
- >
- {relatedResource}
- </a>
- ) : (
- <span class="inline-flex rounded bg-surface px-1.5 py-0.5 text-[10px] text-base-content">
- {relatedResource}
- </span>
- );
- }}
- </For>
- </div>
- </Show>
- </div>
- )}
+ );
+ }}
</For>
</div>
</Show>
diff --git a/frontend-modern/src/components/Infrastructure/__tests__/ResourceChangeSummary.test.tsx b/frontend-modern/src/components/Infrastructure/__tests__/ResourceChangeSummary.test.tsx
index a89a45cd34..1aab4bfc0f 100644
--- a/frontend-modern/src/components/Infrastructure/__tests__/ResourceChangeSummary.test.tsx
+++ b/frontend-modern/src/components/Infrastructure/__tests__/ResourceChangeSummary.test.tsx
@@ -44,6 +44,8 @@ describe('ResourceChangeSummary', () => {
expect(screen.getByText('Recent changes')).toBeInTheDocument();
expect(screen.getByText('Canonical 24h timeline')).toBeInTheDocument();
expect(screen.getByText('Restart: running → restarting')).toBeInTheDocument();
+ expect(screen.getByText('Platform event')).toBeInTheDocument();
+ expect(screen.getByText('Docker adapter')).toBeInTheDocument();
expect(
screen.getByRole('link', { name: 'Open resource storage-2 in Infrastructure' }),
).toHaveAttribute('href', '/infrastructure?resource=storage-2');
diff --git a/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts b/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts
index 28c0dd093f..9d27969bf2 100644
--- a/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts
+++ b/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts
@@ -65,6 +65,8 @@ import dashboardStoragePresentationSource from '@/utils/dashboardStoragePresenta
import dashboardRecoveryPresentationSource from '@/utils/dashboardRecoveryPresentation.ts?raw';
import dashboardKpiPresentationSource from '@/utils/dashboardKpiPresentation.ts?raw';
import dashboardEmptyStatePresentationSource from '@/utils/dashboardEmptyStatePresentation.ts?raw';
+import resourceChangeSummarySource from '@/components/Infrastructure/ResourceChangeSummary.tsx?raw';
+import resourceChangePresentationSource from '@/utils/resourceChangePresentation.ts?raw';
import diskListSource from '@/components/Storage/DiskList.tsx?raw';
import useDiskListModelSource from '@/components/Storage/useDiskListModel.ts?raw';
import diskDetailSource from '@/components/Storage/DiskDetail.tsx?raw';
@@ -1832,8 +1834,26 @@ describe('frontend resource type boundaries', () => {
expect(resourceDetailDrawerSource).toContain('getServiceHealthPresentation');
expect(resourceDetailDrawerSource).toContain('ResourceAPI.getFacetBundle');
expect(resourceDetailDrawerSource).toContain('History');
+ expect(resourceDetailDrawerSource).toContain('RESOURCE_CHANGE_KIND_ORDER');
+ expect(resourceDetailDrawerSource).toContain('RESOURCE_CHANGE_SOURCE_TYPE_ORDER');
+ expect(resourceDetailDrawerSource).toContain('RESOURCE_CHANGE_SOURCE_ADAPTER_ORDER');
+ expect(resourceDetailDrawerSource).toContain('getResourceChangeKindPresentation');
+ expect(resourceDetailDrawerSource).toContain('getResourceChangeSourceTypePresentation');
+ expect(resourceDetailDrawerSource).toContain('getResourceChangeSourceAdapterPresentation');
+ expect(resourceChangeSummarySource).toContain('getResourceChangeKindPresentation');
+ expect(resourceChangeSummarySource).toContain('getResourceChangeSourceTypePresentation');
+ expect(resourceChangeSummarySource).toContain(
+ 'getResourceChangeSourceAdapterPresentation',
+ );
expect(resourceDetailDrawerSource).not.toContain('healthToneClass(');
expect(resourceDetailDrawerSource).not.toContain('normalizeHealthLabel(');
+ expect(resourceChangePresentationSource).toContain('getResourceChangeKindPresentation');
+ expect(resourceChangePresentationSource).toContain(
+ 'getResourceChangeSourceTypePresentation',
+ );
+ expect(resourceChangePresentationSource).toContain(
+ 'getResourceChangeSourceAdapterPresentation',
+ );
expect(useUnifiedResourcesSource).toContain('normalizeResourcePolicy(');
expect(useUnifiedResourcesSource).not.toContain('const resolvePolicySensitivity =');
expect(useUnifiedResourcesSource).not.toContain('const resolvePolicyRoutingScope =');
diff --git a/frontend-modern/src/utils/resourceChangePresentation.ts b/frontend-modern/src/utils/resourceChangePresentation.ts
index 7ccf31e72c..24cdfd668e 100644
--- a/frontend-modern/src/utils/resourceChangePresentation.ts
+++ b/frontend-modern/src/utils/resourceChangePresentation.ts
@@ -131,22 +131,47 @@ const RESOURCE_CHANGE_SOURCE_ADAPTER_PRESENTATIONS: Record<
},
};
+const humanizeResourceChangeToken = (value: string): string => {
+ const normalized = value.trim();
+ if (!normalized) {
+ return 'Unknown';
+ }
+ return normalized
+ .replace(/_/g, ' ')
+ .replace(/\b\w/g, (char) => char.toUpperCase());
+};
+
+const fallbackResourceChangePresentation = (value: string): ResourceChangeLabelPresentation => {
+ const label = humanizeResourceChangeToken(value);
+ return {
+ label,
+ plural: `${label}s`,
+ className: 'bg-surface text-muted',
+ };
+};
+
export function getResourceChangeKindPresentation(
- kind: ResourceChangeKind,
+ kind: ResourceChangeKind | string,
): ResourceChangeLabelPresentation {
- return RESOURCE_CHANGE_KIND_PRESENTATIONS[kind];
+ return RESOURCE_CHANGE_KIND_PRESENTATIONS[kind as ResourceChangeKind] ?? fallbackResourceChangePresentation(String(kind));
}
export function getResourceChangeSourceTypePresentation(
- sourceType: ResourceChangeSourceType,
+ sourceType: ResourceChangeSourceType | string,
): ResourceChangeLabelPresentation {
- return RESOURCE_CHANGE_SOURCE_TYPE_PRESENTATIONS[sourceType];
+ return (
+ RESOURCE_CHANGE_SOURCE_TYPE_PRESENTATIONS[sourceType as ResourceChangeSourceType] ??
+ fallbackResourceChangePresentation(String(sourceType))
+ );
}
export function getResourceChangeSourceAdapterPresentation(
- sourceAdapter: ResourceFacetSourceAdapter,
+ sourceAdapter: ResourceFacetSourceAdapter | string,
): ResourceChangeLabelPresentation {
- return RESOURCE_CHANGE_SOURCE_ADAPTER_PRESENTATIONS[sourceAdapter];
+ return (
+ RESOURCE_CHANGE_SOURCE_ADAPTER_PRESENTATIONS[sourceAdapter as ResourceFacetSourceAdapter] ??
+ fallbackResourceChangePresentation(String(sourceAdapter))
+ );
}
export function formatResourceChangeKind(kind: ResourceChange['kind']): string {