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 correlation endpoint labels

rcourtmand126cec1f811
diff --git a/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts b/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts
index b7af4ffae0..7fbd09fb73 100644
--- a/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts
+++ b/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts
@@ -1917,6 +1917,7 @@ describe('frontend resource type boundaries', () => {
expect(resourceRelationshipPresentationSource).toContain('formatConfidencePercentage');
expect(resourceCorrelationPresentationSource).toContain('formatConfidencePercentage');
expect(resourceCorrelationPresentationSource).toContain('humanizeArrowDelimitedLabel');
+ expect(resourceCorrelationPresentationSource).toContain('formatTrimmedLabel');
expect(confidencePresentationSource).toContain('formatConfidencePercentage');
expect(confidencePresentationSource).toContain('formatConfidenceLabel');
expect(approvalPresentationSource).toContain('getResourceApprovalLevelLabel');
@@ -1925,6 +1926,8 @@ describe('frontend resource type boundaries', () => {
expect(resourceChangePresentationSource).toContain('humanizeToken');
expect(resourceRelationshipPresentationSource).toContain('humanizeToken');
expect(textPresentationSource).toContain('humanizeArrowDelimitedLabel');
+ expect(textPresentationSource).toContain('formatTrimmedLabel');
+ expect(resourceCorrelationPresentationSource).not.toContain('formatResourceCorrelationEndpointLabel');
expect(resourceCorrelationPresentationSource).not.toContain(
"replace(/\\s*->\\s*/g, ' → ')",
);
diff --git a/frontend-modern/src/utils/__tests__/textPresentation.test.ts b/frontend-modern/src/utils/__tests__/textPresentation.test.ts
index df255f237e..11cf71bfcc 100644
--- a/frontend-modern/src/utils/__tests__/textPresentation.test.ts
+++ b/frontend-modern/src/utils/__tests__/textPresentation.test.ts
@@ -2,6 +2,7 @@ import { describe, expect, it } from 'vitest';
import {
formatIdentifierLabel,
+ formatTrimmedLabel,
humanizeArrowDelimitedLabel,
humanizeToken,
titleCaseDelimitedLabel,
@@ -31,6 +32,11 @@ describe('textPresentation', () => {
expect(formatIdentifierLabel(undefined, { fallback: 'Unknown' })).toBe('Unknown');
});
+ it('formats trimmed labels with a fallback', () => {
+ expect(formatTrimmedLabel(' endpoint ', { fallback: 'Unknown resource' })).toBe('endpoint');
+ expect(formatTrimmedLabel('', { fallback: 'Unknown resource' })).toBe('Unknown resource');
+ });
+
it('title-cases delimited labels with configurable separators', () => {
expect(titleCaseDelimitedLabel('docker_host')).toBe('Docker Host');
expect(titleCaseDelimitedLabel('IP_address', { preserveShortAllCaps: true })).toBe(
diff --git a/frontend-modern/src/utils/resourceCorrelationPresentation.ts b/frontend-modern/src/utils/resourceCorrelationPresentation.ts
index ba89b235a8..a9e28b6128 100644
--- a/frontend-modern/src/utils/resourceCorrelationPresentation.ts
+++ b/frontend-modern/src/utils/resourceCorrelationPresentation.ts
@@ -1,7 +1,7 @@
import type { ResourceCorrelation } from '@/types/aiIntelligence';
import { formatDurationMs } from '@/utils/patrolFormat';
import { formatConfidencePercentage } from '@/utils/confidencePresentation';
-import { humanizeArrowDelimitedLabel } from '@/utils/textPresentation';
+import { formatTrimmedLabel, humanizeArrowDelimitedLabel } from '@/utils/textPresentation';
const parseGoDurationMs = (value: string): number | null => {
const normalized = value.trim();
@@ -31,20 +31,15 @@ const humanizeCorrelationToken = (value?: string): string => {
return humanizeArrowDelimitedLabel(value, { fallback: 'Correlation' });
};
-const formatResourceCorrelationEndpointLabel = (value?: string): string => {
- const normalized = (value || '').trim();
- if (!normalized) return 'Unknown resource';
- return normalized;
-};
-
export function formatResourceCorrelationEndpoint(
correlation: ResourceCorrelation,
role: 'source' | 'target',
): string {
- return formatResourceCorrelationEndpointLabel(
+ return formatTrimmedLabel(
role === 'source'
? correlation.source_name || correlation.source_id
: correlation.target_name || correlation.target_id,
+ { fallback: 'Unknown resource' },
);
}
diff --git a/frontend-modern/src/utils/textPresentation.ts b/frontend-modern/src/utils/textPresentation.ts
index 76141e4cee..835e2a8d99 100644
--- a/frontend-modern/src/utils/textPresentation.ts
+++ b/frontend-modern/src/utils/textPresentation.ts
@@ -15,6 +15,10 @@ export interface TitleCaseLabelOptions {
separators?: RegExp;
}
+export interface TrimmedLabelOptions {
+ fallback?: string;
+}
+
export function humanizeToken(value?: string, options?: HumanizeTokenOptions): string {
const normalized = (value || '').trim();
if (!normalized) {
@@ -83,6 +87,14 @@ export function titleCaseDelimitedLabel(
.join(' ');
}
+export function formatTrimmedLabel(
+ value?: string,
+ options?: TrimmedLabelOptions,
+): string {
+ const normalized = (value || '').trim();
+ return normalized || options?.fallback || '';
+}
+
export function humanizeArrowDelimitedLabel(
value?: string,
options?: HumanizeTokenOptions,