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.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
Centralize trimmed string normalization
rcourtman2e934262c08b
diff --git a/docs/release-control/v6/internal/subsystems/frontend-primitives.md b/docs/release-control/v6/internal/subsystems/frontend-primitives.mdindex 5218167424..ad40df71a1 100644--- a/docs/release-control/v6/internal/subsystems/frontend-primitives.md+++ b/docs/release-control/v6/internal/subsystems/frontend-primitives.md@@ -96,6 +96,9 @@ identity lookup helper from `frontend-modern/src/utils/resourceIdentity.ts`so dotted hostnames and alias variants stay consistent between the sharedtable, drawer, and detail views instead of each component carrying its ownidentifier-variant logic.+Those same surfaces also share the trimmed-string helper from+`frontend-modern/src/utils/stringUtils.ts` so shared components do not keep+their own copy of the same whitespace-trimming identity logic.General settings segmented selectors for theme preference and temperature unitmust now also route through the shared `FilterButtonGroup` primitive instead ofdiff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.mdindex 2b487e9be8..75b30e2523 100644--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md@@ -730,7 +730,10 @@ their own sensitivity or routing guesses in page-local presentation code. Theshared `frontend-modern/src/hooks/useUnifiedResources.ts` decode path nowtrusts the backend canonical metadata directly instead of re-normalizing itlocally, so storage and recovery views see the same policy posture the API-publishes. That same boundary now also owns the backend facet-bundle route for capability,-relationship, and timeline history reads, so storage and recovery surfaces-must continue to consume the shared bundle rather than issuing separate local-resource-detail fetches.+publishes. The same hook and the resource-identity helpers it depends on now+share the canonical trimmed-string utility instead of each surface rebuilding+its own whitespace cleanup, so storage and recovery identity checks stay+aligned with the other resource-graph consumers. That same boundary now also+owns the backend facet-bundle route for capability, relationship, and timeline+history reads, so storage and recovery surfaces must continue to consume the+shared bundle rather than issuing separate local resource-detail fetches.diff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.mdindex edfdd4e7ee..2e69e73a0f 100644--- a/docs/release-control/v6/internal/subsystems/unified-resources.md+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md@@ -430,6 +430,10 @@ lookup helper for these matches, so dotted hostnames such as`tower.example.local` collapse to the same canonical lookup variants as theresource table and resource graph surfaces instead of each view inventing itsown comparison rule.+The same identity surfaces also share the trimmed-string helper from+`frontend-modern/src/utils/stringUtils.ts` so resource-id, hostname, and+linked-node normalization keep the same fail-closed whitespace trimming rules+instead of reimplementing ad hoc local string cleanups.The same governed lookup boundary now also owns policy-aware resolved context:downstream consumers that need routing plus canonical policy metadata must usethe unified-resource resolution context instead of rescanning typed views ordiff --git a/frontend-modern/src/components/Infrastructure/InfrastructureSummary.tsx b/frontend-modern/src/components/Infrastructure/InfrastructureSummary.tsxindex 5d4391e735..91da59dade 100644--- a/frontend-modern/src/components/Infrastructure/InfrastructureSummary.tsx+++ b/frontend-modern/src/components/Infrastructure/InfrastructureSummary.tsx@@ -25,6 +25,7 @@ import {getResourceIdentityAliases,getNormalizedIdentityLookupVariants,} from '@/utils/resourceIdentity';+import { asTrimmedString } from '@/utils/stringUtils';import { getOrgID } from '@/utils/apiClient';import { normalizeOrgScope } from '@/utils/orgScope';import { eventBus } from '@/stores/events';@@ -41,15 +42,10 @@ const getNormalizedResourceIdentifiers = (resource: Resource): Set<string> =>),]);-const asTrimmedString = (value: unknown): string | null => {- if (typeof value !== 'string') return null;- const trimmed = value.trim();- return trimmed.length > 0 ? trimmed : null;-};-const getLinkedNodeIdFromResource = (resource: Resource): string | null =>asTrimmedString(getPlatformDataRecord(resource)?.linkedNodeId) ||- asTrimmedString(getPlatformAgentRecord(resource)?.linkedNodeId);+ asTrimmedString(getPlatformAgentRecord(resource)?.linkedNodeId) ||+ null;// Format bytes/sec to human-readable rateconst formatRate = (bytesPerSec: number): string => {diff --git a/frontend-modern/src/components/shared/InfrastructureSummaryTable.tsx b/frontend-modern/src/components/shared/InfrastructureSummaryTable.tsxindex 4371cc129b..2f379bddfb 100644--- a/frontend-modern/src/components/shared/InfrastructureSummaryTable.tsx+++ b/frontend-modern/src/components/shared/InfrastructureSummaryTable.tsx@@ -28,6 +28,7 @@ import {getAgentLikeIdentityAliases,getNormalizedIdentityLookupVariants,} from '@/utils/resourceIdentity';+import { asTrimmedString } from '@/utils/stringUtils';// Lazy load InfrastructureDetailsDrawer to avoid circular dependencies and reduce bundle sizeconst InfrastructureDetailsDrawer = lazy(() =>@@ -37,12 +38,6 @@ const InfrastructureDetailsDrawer = lazy(() =>const asRecord = (value: unknown): Record<string, unknown> | undefined =>value && typeof value === 'object' ? (value as Record<string, unknown>) : undefined;-const asTrimmedString = (value: unknown): string | undefined => {- if (typeof value !== 'string') return undefined;- const trimmed = value.trim();- return trimmed.length > 0 ? trimmed : undefined;-};-const getAgentLinkedNodeId = (agent: Agent): string | undefined => {const agentRecord = agent as unknown as Record<string, unknown>;const platformData = asRecord(agentRecord.platformData);diff --git a/frontend-modern/src/components/shared/__tests__/InfrastructureSummaryTable.test.tsx b/frontend-modern/src/components/shared/__tests__/InfrastructureSummaryTable.test.tsxindex bb32050839..0be9179e64 100644--- a/frontend-modern/src/components/shared/__tests__/InfrastructureSummaryTable.test.tsx+++ b/frontend-modern/src/components/shared/__tests__/InfrastructureSummaryTable.test.tsx@@ -98,7 +98,9 @@ const makeAgent = (overrides: Partial<Agent> = {}): Agent => ({describe('InfrastructureSummaryTable', () => {it('uses the shared normalized identity lookup helper', () => {expect(resourceIdentitySource).toContain('getNormalizedIdentityLookupVariants');- expect(resourceIdentitySource).not.toContain('const dedupeTrimmedValues = (values: Array<string | undefined>): string[] => {');+ expect(resourceIdentitySource).not.toContain(+ 'const asTrimmedString = (value: unknown): string | undefined => {',+ );});it('uses linked agent ids for agent-backed node metric keys', () => {diff --git a/frontend-modern/src/hooks/__tests__/useUnifiedResources.test.ts b/frontend-modern/src/hooks/__tests__/useUnifiedResources.test.tsindex 38a1b2c657..92e25cd786 100644--- a/frontend-modern/src/hooks/__tests__/useUnifiedResources.test.ts+++ b/frontend-modern/src/hooks/__tests__/useUnifiedResources.test.ts@@ -3,6 +3,7 @@ import { createStore, reconcile, type SetStoreFunction } from 'solid-js/store';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';import type { State } from '@/types/api';import useUnifiedResourcesSource from '../useUnifiedResources.ts?raw';+import stringUtilsSource from '@/utils/stringUtils.ts?raw';type UseUnifiedResourcesModule = typeof import('@/hooks/useUnifiedResources');@@ -908,5 +909,10 @@ describe('useUnifiedResources', () => {expect(useUnifiedResourcesSource).toContain('normalizeOrgScope(getOrgID())');expect(useUnifiedResourcesSource).not.toContain('const DEFAULT_ORG_SCOPE = \'default\'');expect(useUnifiedResourcesSource).not.toContain('const normalizeOrgScope =');+ expect(useUnifiedResourcesSource).toContain('asTrimmedString');+ expect(useUnifiedResourcesSource).not.toContain(+ 'const asTrimmedString = (value: unknown): string | undefined => {',+ );+ expect(stringUtilsSource).toContain('export const asTrimmedString');});});diff --git a/frontend-modern/src/hooks/useUnifiedResources.ts b/frontend-modern/src/hooks/useUnifiedResources.tsindex 2ed78e0747..9c9b28a5dc 100644--- a/frontend-modern/src/hooks/useUnifiedResources.ts+++ b/frontend-modern/src/hooks/useUnifiedResources.ts@@ -4,6 +4,7 @@ import { canonicalizeMetricsHistoryTargetType } from '@/api/charts';import { readAPIErrorMessage } from '@/api/responseUtils';import { apiFetch, getOrgID } from '@/utils/apiClient';import { normalizeOrgScope } from '@/utils/orgScope';+import { asTrimmedString } from '@/utils/stringUtils';import { getGlobalWebSocketStore } from '@/stores/websocket-global';import type {Resource,@@ -422,12 +423,6 @@ const resolveStatus = (status?: string): ResourceStatus => {return 'unknown';};-const asTrimmedString = (value: unknown): string | undefined => {- if (typeof value !== 'string') return undefined;- const trimmed = value.trim();- return trimmed.length > 0 ? trimmed : undefined;-};-const resolveType = (value?: string): ResourceType => {const normalized = (value || '').toLowerCase();switch (normalized) {diff --git a/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts b/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.tsindex a105e10f7e..5591658a41 100644--- a/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts+++ b/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts@@ -85,6 +85,7 @@ import patrolFormatSource from '@/utils/patrolFormat.ts?raw';import aiFindingPresentationSource from '@/utils/aiFindingPresentation.ts?raw';import chatIdentifiersSource from '@/utils/chatIdentifiers.ts?raw';import resourceIdentitySource from '@/utils/resourceIdentity.ts?raw';+import stringUtilsSource from '@/utils/stringUtils.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';@@ -1945,6 +1946,14 @@ describe('frontend resource type boundaries', () => {expect(infrastructureSummarySource).toContain('getNormalizedIdentityLookupVariants');expect(infrastructureSummaryTableSource).toContain('getNormalizedIdentityLookupVariants');expect(resourceIdentitySource).toContain('getNormalizedIdentityLookupVariants');+ expect(stringUtilsSource).toContain('export const asTrimmedString');+ expect(resourceIdentitySource).not.toContain('const asTrimmedString = (value: unknown): string | undefined => {');+ expect(infrastructureSummarySource).not.toContain(+ 'const asTrimmedString = (value: unknown): string | null => {',+ );+ expect(infrastructureSummaryTableSource).not.toContain(+ 'const asTrimmedString = (value: unknown): string | undefined => {',+ );expect(useUnifiedResourcesSource).not.toContain('normalizeResourcePolicyAISafeSummary(');expect(useUnifiedResourcesSource).not.toContain('normalizeResourcePolicy(');expect(useUnifiedResourcesSource).not.toContain('const resolvePolicySensitivity =');diff --git a/frontend-modern/src/utils/__tests__/stringUtils.test.ts b/frontend-modern/src/utils/__tests__/stringUtils.test.tsnew file mode 100644index 0000000000..d442e7a170--- /dev/null+++ b/frontend-modern/src/utils/__tests__/stringUtils.test.ts@@ -0,0 +1,12 @@+import { describe, expect, it } from 'vitest';++import { asTrimmedString } from '@/utils/stringUtils';++describe('stringUtils', () => {+ it('trims strings and returns undefined for empty values', () => {+ expect(asTrimmedString(' hello ')).toBe('hello');+ expect(asTrimmedString('')).toBeUndefined();+ expect(asTrimmedString(undefined)).toBeUndefined();+ expect(asTrimmedString(null)).toBeUndefined();+ });+});diff --git a/frontend-modern/src/utils/agentResources.ts b/frontend-modern/src/utils/agentResources.tsindex e3953479b1..a6069f9796 100644--- a/frontend-modern/src/utils/agentResources.ts+++ b/frontend-modern/src/utils/agentResources.ts@@ -4,6 +4,7 @@ import {isAgentDiscoveryResourceType,isAppContainerDiscoveryResourceType,} from '@/utils/discoveryTarget';+import { asTrimmedString } from '@/utils/stringUtils';const AGENT_FACET_INFRASTRUCTURE_TYPES = new Set<ResourceType>(['agent', 'pbs', 'pmg', 'truenas']);const AGENT_PROFILE_ASSIGNABLE_TYPES = new Set<ResourceType>([@@ -18,12 +19,6 @@ const AGENT_PROFILE_ASSIGNABLE_TYPES = new Set<ResourceType>([const asRecord = (value: unknown): Record<string, unknown> | undefined =>value && typeof value === 'object' ? (value as Record<string, unknown>) : undefined;-const asTrimmedString = (value: unknown): string | undefined => {- if (typeof value !== 'string') return undefined;- const trimmed = value.trim();- return trimmed.length > 0 ? trimmed : undefined;-};-export const getPlatformDataRecord = (resource: Resource): Record<string, unknown> | undefined =>resource.platformData ? (resource.platformData as Record<string, unknown>) : undefined;diff --git a/frontend-modern/src/utils/discoveryTarget.ts b/frontend-modern/src/utils/discoveryTarget.tsindex c0b64b27fa..4615db436d 100644--- a/frontend-modern/src/utils/discoveryTarget.ts+++ b/frontend-modern/src/utils/discoveryTarget.ts@@ -1,4 +1,5 @@import { canonicalizeFrontendResourceType } from '@/utils/resourceTypeCompat';+import { asTrimmedString } from '@/utils/stringUtils';type DiscoveryTargetLike = {resourceType?: string;@@ -6,12 +7,6 @@ type DiscoveryTargetLike = {agentId?: string;} | null;-const asTrimmedString = (value: unknown): string | undefined => {- if (typeof value !== 'string') return undefined;- const trimmed = value.trim();- return trimmed.length > 0 ? trimmed : undefined;-};-const normalizeDiscoveryResourceType = (resourceType: unknown): string | undefined => {return asTrimmedString(resourceType)?.toLowerCase();};diff --git a/frontend-modern/src/utils/resourceIdentity.ts b/frontend-modern/src/utils/resourceIdentity.tsindex 80b97fea3d..6ecb18ecac 100644--- a/frontend-modern/src/utils/resourceIdentity.ts+++ b/frontend-modern/src/utils/resourceIdentity.ts@@ -8,6 +8,7 @@ import {getPlatformAgentRecord,getPlatformDataRecord,} from '@/utils/agentResources';+import { asTrimmedString } from '@/utils/stringUtils';export type ResourceIdentityRow = {label: string;@@ -35,12 +36,6 @@ type NamedEntity = {name?: string;};-const asTrimmedString = (value: unknown): string | undefined => {- if (typeof value !== 'string') return undefined;- const trimmed = value.trim();- return trimmed.length > 0 ? trimmed : undefined;-};-const dedupeTrimmedValues = (values: Array<string | undefined>): string[] => {const seen = new Set<string>();const deduped: string[] = [];diff --git a/frontend-modern/src/utils/stringUtils.ts b/frontend-modern/src/utils/stringUtils.tsnew file mode 100644index 0000000000..16af650e77--- /dev/null+++ b/frontend-modern/src/utils/stringUtils.ts@@ -0,0 +1,5 @@+export const asTrimmedString = (value: unknown): string | undefined => {+ if (typeof value !== 'string') return undefined;+ const trimmed = value.trim();+ return trimmed.length > 0 ? trimmed : undefined;+};