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 resource display helpers

rcourtmanf5fba35368ce
diff --git a/docs/release-control/v6/internal/subsystems/organization-settings.md b/docs/release-control/v6/internal/subsystems/organization-settings.md
index 5a75b6bdea..c889a053f2 100644
--- a/docs/release-control/v6/internal/subsystems/organization-settings.md
+++ b/docs/release-control/v6/internal/subsystems/organization-settings.md
@@ -103,5 +103,5 @@ scope through `frontend-modern/src/utils/orgScope.ts` instead of carrying
their own `getOrgID() || 'default'` fallbacks, so access, overview, and
sharing views stay aligned with the shared multi-tenant org context contract.
The organization sharing surface now also sources resource quick-pick labels
-from the shared policy-aware resource display helper, so governed resources do
+from the shared preferred resource display helper, so governed resources do
not fall back to raw names inside share creation.
diff --git a/docs/release-control/v6/internal/subsystems/performance-and-scalability.md b/docs/release-control/v6/internal/subsystems/performance-and-scalability.md
index a71eafff11..f43b257fa2 100644
--- a/docs/release-control/v6/internal/subsystems/performance-and-scalability.md
+++ b/docs/release-control/v6/internal/subsystems/performance-and-scalability.md
@@ -132,9 +132,9 @@ The same detail drawer also uses that resolver for correlation dependency and
dependent chips, so the investigation path does not fall back to raw IDs in
the drawer while the AI page keeps its broader no-catalog fallback.
The shared infrastructure selector search path now also routes through that
-same policy-aware display contract, so governed resources do not reappear via
-raw-name search candidates while the selector stays on the same hot-path
-budget.
+same preferred resource display contract, so governed resources do not
+reappear via raw-name search candidates while the selector stays on the same
+hot-path budget.
The aggregate `/api/charts/workloads-summary` endpoint now also has its own
explicit API p95 budget constant, aligned with the per-workload charts budget,
and `internal/api/slo_bench_test.go` must fail if that aggregate budget or its
diff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.md
index 2692e7dcb9..82eeb9afb4 100644
--- a/docs/release-control/v6/internal/subsystems/unified-resources.md
+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md
@@ -277,17 +277,16 @@ governed display label through the same policy-aware helper, and they suppress
the raw alternate name when policy requires governed handling, so the visible
label stays aligned with the backend redaction boundary instead of
reconstructing a local name fallback.
-The shared frontend resource identity helper now inherits the same policy-aware
-display contract, so other infrastructure surfaces that ask for the preferred
+The shared frontend resource identity helper now owns that policy-aware
+display contract, so infrastructure surfaces that ask for the preferred
resource label no longer need to re-encode the governed summary boundary by
-hand.
-The generic frontend `getDisplayName` helper in `types/resource.ts` now
-follows that same policy-aware boundary as well, so settings quick-picks and
-other shared resource selectors do not keep a second raw-name fallback fork.
+hand. Settings quick-picks, infrastructure selectors, and the connected-
+infrastructure / monitored-system projections now all stay on that same
+preferred-label helper instead of carrying a separate raw-name fallback fork.
That same contract also owns the canonical resource display-name fallback, so
name-or-ID presentation stays consistent between the unified AI adapter, the
-AI resource context, and the connected-infrastructure / monitored-system
-projections instead of being recomputed locally.
+AI resource context, and the shared resource selectors instead of being
+recomputed locally.
That same shared store now also persists append-only action lifecycle, action
audit, and export audit records, giving the control-plane verbs a durable home
diff --git a/frontend-modern/src/components/Dashboard/__tests__/Dashboard.performance.contract.test.tsx b/frontend-modern/src/components/Dashboard/__tests__/Dashboard.performance.contract.test.tsx
index 8e3699cf57..df378ce189 100644
--- a/frontend-modern/src/components/Dashboard/__tests__/Dashboard.performance.contract.test.tsx
+++ b/frontend-modern/src/components/Dashboard/__tests__/Dashboard.performance.contract.test.tsx
@@ -1,6 +1,7 @@
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { render, waitFor } from '@solidjs/testing-library';
import { createSignal, onCleanup, onMount } from 'solid-js';
+import type { Resource } from '@/types/resource';
import { Dashboard } from '../Dashboard';
import dashboardSource from '../Dashboard.tsx?raw';
import {
@@ -9,6 +10,7 @@ import {
groupWorkloads,
computeWorkloadStats,
} from '../workloadSelectors';
+import { filterResources } from '@/components/Infrastructure/infrastructureSelectors';
import { getCanonicalWorkloadId, normalizeWorkloadViewModeParam } from '@/utils/workloads';
// Stub ResizeObserver for jsdom
@@ -186,6 +188,24 @@ const makeGuest = (i: number, overrides?: Record<string, unknown>) => ({
...overrides,
});
+const makeResource = (overrides?: Partial<Resource>): Resource => ({
+ id: 'resource-1',
+ type: 'vm',
+ name: 'secret-host-1',
+ displayName: 'secret-host-1',
+ platformId: 'platform-1',
+ platformType: 'proxmox-pve',
+ sourceType: 'api',
+ status: 'running',
+ lastSeen: Date.now(),
+ policy: {
+ sensitivity: 'restricted',
+ routing: { scope: 'local-only', redact: ['hostname'] },
+ },
+ aiSafeSummary: 'Production Host',
+ ...overrides,
+});
+
const PROFILES = {
S: 400,
M: 1500,
@@ -266,6 +286,16 @@ describe('Dashboard performance contract', () => {
expect(getGuestRowCount(container)).toBe(PROFILES.S);
});
});
+
+ it('keeps governed resource search aligned with the preferred display label', () => {
+ const resources = [makeResource()];
+
+ const filtered = filterResources(resources, new Set(), new Set(), ['Production']);
+ const rawFiltered = filterResources(resources, new Set(), new Set(), ['secret-host']);
+
+ expect(filtered).toHaveLength(1);
+ expect(rawFiltered).toHaveLength(0);
+ });
});
describe('Workload windowing contracts', () => {
diff --git a/frontend-modern/src/components/Infrastructure/infrastructureSelectors.ts b/frontend-modern/src/components/Infrastructure/infrastructureSelectors.ts
index c9dd0e8518..58e3c37a20 100644
--- a/frontend-modern/src/components/Infrastructure/infrastructureSelectors.ts
+++ b/frontend-modern/src/components/Infrastructure/infrastructureSelectors.ts
@@ -1,5 +1,6 @@
import type { Resource } from '@/types/resource';
-import { getCpuPercent, getDiskPercent, getDisplayName, getMemoryPercent } from '@/types/resource';
+import { getCpuPercent, getDiskPercent, getMemoryPercent } from '@/types/resource';
+import { getPreferredResourceDisplayName } from '@/utils/resourceIdentity';
import { normalizeSourcePlatformKey, type KnownSourcePlatform } from '@/utils/sourcePlatforms';
import { getCanonicalStatusLabel, STATUS_SORT_ORDER } from '@/utils/status';
@@ -68,7 +69,7 @@ const buildIODistribution = (values: number[]): IODistributionStats => {
const getSortValue = (resource: Resource, key: string): number | string | null => {
switch (key) {
case 'name':
- return getDisplayName(resource);
+ return getPreferredResourceDisplayName(resource);
case 'uptime':
return resource.uptime ?? 0;
case 'cpu':
@@ -94,7 +95,7 @@ const defaultComparison = (a: Resource, b: Resource) => {
const aOnline = isResourceOnline(a);
const bOnline = isResourceOnline(b);
if (aOnline !== bOnline) return aOnline ? -1 : 1;
- return getDisplayName(a).localeCompare(getDisplayName(b));
+ return getPreferredResourceDisplayName(a).localeCompare(getPreferredResourceDisplayName(b));
};
const compareValues = (valueA: number | string | null, valueB: number | string | null) => {
@@ -130,7 +131,7 @@ export const matchesSearch = (resource: Resource, term: string): boolean => {
if (!term) return true;
const normalizedTerm = term.toLowerCase();
const candidates: string[] = [
- getDisplayName(resource),
+ getPreferredResourceDisplayName(resource),
resource.id,
resource.identity?.hostname ?? '',
...(resource.identity?.ips ?? []),
diff --git a/frontend-modern/src/components/Settings/OrganizationSharingPanel.tsx b/frontend-modern/src/components/Settings/OrganizationSharingPanel.tsx
index f3829e9aa1..bc1a65307c 100644
--- a/frontend-modern/src/components/Settings/OrganizationSharingPanel.tsx
+++ b/frontend-modern/src/components/Settings/OrganizationSharingPanel.tsx
@@ -48,7 +48,8 @@ import {
ORGANIZATION_SETTINGS_UNAVAILABLE_CLASS,
ORGANIZATION_SETTINGS_UNAVAILABLE_MESSAGE,
} from '@/utils/organizationSettingsPresentation';
-import { useResources, getDisplayName } from '@/hooks/useResources';
+import { useResources } from '@/hooks/useResources';
+import { getPreferredResourceDisplayName } from '@/utils/resourceIdentity';
import Share2 from 'lucide-solid/icons/share-2';
import Trash2 from 'lucide-solid/icons/trash-2';
import { PulseDataGrid } from '@/components/shared/PulseDataGrid';
@@ -99,7 +100,7 @@ export const OrganizationSharingPanel: Component<OrganizationSharingPanelProps>
.map((resource) => ({
id: resource.id,
type: resource.type,
- name: (getDisplayName(resource) || resource.id).trim(),
+ name: (getPreferredResourceDisplayName(resource) || resource.id).trim(),
}))
.sort((left, right) => left.name.localeCompare(right.name));
});
diff --git a/frontend-modern/src/components/Settings/ResourcePicker.tsx b/frontend-modern/src/components/Settings/ResourcePicker.tsx
index 72b61e2844..f8a8fea7e8 100644
--- a/frontend-modern/src/components/Settings/ResourcePicker.tsx
+++ b/frontend-modern/src/components/Settings/ResourcePicker.tsx
@@ -5,8 +5,9 @@ import XSquare from 'lucide-solid/icons/x-square';
import { formControl } from '@/components/shared/Form';
import { SearchField } from '@/components/shared/SearchField';
import { StatusDot } from '@/components/shared/StatusDot';
-import { useResources, getDisplayName } from '@/hooks/useResources';
+import { useResources } from '@/hooks/useResources';
import type { Resource, ResourceType } from '@/types/resource';
+import { getPreferredResourceDisplayName } from '@/utils/resourceIdentity';
import {
getResourcePickerEmptyState,
getResourcePickerTypeFilterLabel,
@@ -55,7 +56,7 @@ export function ResourcePicker(props: ResourcePickerProps) {
const searchTerm = search().toLowerCase().trim();
if (searchTerm) {
result = result.filter((r) => {
- const name = getDisplayName(r).toLowerCase();
+ const name = getPreferredResourceDisplayName(r).toLowerCase();
const id = r.id.toLowerCase();
return name.includes(searchTerm) || id.includes(searchTerm);
});
@@ -72,7 +73,9 @@ export function ResourcePicker(props: ResourcePickerProps) {
const aOrder = reportableResourceTypeSortOrder(a.type);
const bOrder = reportableResourceTypeSortOrder(b.type);
if (aOrder !== bOrder) return aOrder - bOrder;
- return getDisplayName(a).localeCompare(getDisplayName(b));
+ return getPreferredResourceDisplayName(a).localeCompare(
+ getPreferredResourceDisplayName(b),
+ );
});
return result;
@@ -96,7 +99,7 @@ export function ResourcePicker(props: ResourcePickerProps) {
{
id: resource.id,
type: resource.type,
- name: getDisplayName(resource),
+ name: getPreferredResourceDisplayName(resource),
},
]);
}
@@ -110,7 +113,7 @@ export function ResourcePicker(props: ResourcePickerProps) {
.map((r) => ({
id: r.id,
type: r.type,
- name: getDisplayName(r),
+ name: getPreferredResourceDisplayName(r),
}));
const newSelection = [...current, ...toAdd];
@@ -245,7 +248,7 @@ export function ResourcePicker(props: ResourcePickerProps) {
{/* Name and ID */}
<div class="flex-1 min-w-0">
<div class="text-sm text-white sm:truncate break-words">
- {getDisplayName(resource)}
+ {getPreferredResourceDisplayName(resource)}
</div>
<div class="text-xs text-slate-500 sm:truncate break-all">
{resource.id}
diff --git a/frontend-modern/src/components/Settings/__tests__/OrganizationSharingPanel.test.tsx b/frontend-modern/src/components/Settings/__tests__/OrganizationSharingPanel.test.tsx
index c10d212e9d..134e9fadd8 100644
--- a/frontend-modern/src/components/Settings/__tests__/OrganizationSharingPanel.test.tsx
+++ b/frontend-modern/src/components/Settings/__tests__/OrganizationSharingPanel.test.tsx
@@ -1,6 +1,6 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { cleanup, fireEvent, render, screen, waitFor } from '@solidjs/testing-library';
-import { getDisplayName as getResourceDisplayName, type Resource } from '@/types/resource';
+import type { Resource } from '@/types/resource';
import { OrganizationSharingPanel } from '../OrganizationSharingPanel';
import organizationSharingPanelSource from '../OrganizationSharingPanel.tsx?raw';
@@ -36,7 +36,6 @@ vi.mock('@/hooks/useResources', () => ({
useResources: () => ({
resources: () => mockResources,
}),
- getDisplayName: (resource: Resource) => getResourceDisplayName(resource),
}));
vi.mock('@/stores/license', () => ({
@@ -178,7 +177,7 @@ describe('OrganizationSharingPanel', () => {
const quickPick = screen.getByLabelText('Quick Pick Resource') as HTMLSelectElement;
const labels = Array.from(quickPick.options).map((option) => option.textContent?.trim());
- expect(labels).toEqual(['Select resource', 'Alpha VM (vm)', 'host-1 (agent)', 'Zulu VM (vm)']);
+ expect(labels).toEqual(['Select resource', 'Alpha VM (vm)', 'pve-1 (agent)', 'Zulu VM (vm)']);
expect(labels).not.toContain('Hidden (vm)');
});
diff --git a/frontend-modern/src/components/Settings/__tests__/ResourcePicker.test.tsx b/frontend-modern/src/components/Settings/__tests__/ResourcePicker.test.tsx
index 34bef310cd..856acbf982 100644
--- a/frontend-modern/src/components/Settings/__tests__/ResourcePicker.test.tsx
+++ b/frontend-modern/src/components/Settings/__tests__/ResourcePicker.test.tsx
@@ -1,7 +1,7 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { cleanup, fireEvent, render, screen, waitFor } from '@solidjs/testing-library';
import { createSignal } from 'solid-js';
-import { getDisplayName as getResourceDisplayName, type Resource } from '@/types/resource';
+import type { Resource } from '@/types/resource';
import { ResourcePicker, type SelectedResource } from '../ResourcePicker';
let mockResources: Resource[] = [];
@@ -11,7 +11,6 @@ vi.mock('@/hooks/useResources', () => ({
useResources: () => ({
resources: () => mockResources,
}),
- getDisplayName: (resource: Resource) => getResourceDisplayName(resource),
}));
vi.mock('@/utils/toast', () => ({
diff --git a/frontend-modern/src/hooks/useResources.ts b/frontend-modern/src/hooks/useResources.ts
index 3e33df0434..8d5c59580e 100644
--- a/frontend-modern/src/hooks/useResources.ts
+++ b/frontend-modern/src/hooks/useResources.ts
@@ -34,11 +34,11 @@ import type {
import {
isInfrastructure,
isWorkload,
- getDisplayName,
getCpuPercent,
getMemoryPercent,
getDiskPercent,
} from '@/types/resource';
+import { getPreferredResourceDisplayName } from '@/utils/resourceIdentity';
type ResourceStoreLike = Pick<ReturnType<typeof getGlobalWebSocketStore>, 'state'>;
export interface UseResourcesReturn {
@@ -204,7 +204,7 @@ export function useResources(storeOverride?: ResourceStoreLike): UseResourcesRet
if (filter.search && filter.search.trim()) {
const term = filter.search.toLowerCase().trim();
result = result.filter((r) => {
- const name = getDisplayName(r).toLowerCase();
+ const name = getPreferredResourceDisplayName(r).toLowerCase();
const id = r.id.toLowerCase();
return name.includes(term) || id.includes(term);
});
@@ -262,7 +262,6 @@ export type { Resource, ResourceType, PlatformType, ResourceStatus, ResourceFilt
export {
isInfrastructure,
isWorkload,
- getDisplayName,
getCpuPercent,
getMemoryPercent,
getDiskPercent,
diff --git a/frontend-modern/src/types/__tests__/resource.test.ts b/frontend-modern/src/types/__tests__/resource.test.ts
index e16d78946b..3b5da4b3b3 100644
--- a/frontend-modern/src/types/__tests__/resource.test.ts
+++ b/frontend-modern/src/types/__tests__/resource.test.ts
@@ -6,13 +6,13 @@ import {
isInfrastructure,
isWorkload,
isStorage,
- getDisplayName,
getCpuPercent,
getMemoryPercent,
getDiskPercent,
type Resource,
type ResourceType,
} from '@/types/resource';
+import { getPreferredResourceDisplayName } from '@/utils/resourceIdentity';
// Helper to create a minimal resource for testing
function createResource(overrides: Partial<Resource> = {}): Resource {
@@ -91,22 +91,22 @@ describe('Resource Type Guards', () => {
});
describe('Resource Helper Functions', () => {
- describe('getDisplayName', () => {
+ describe('getPreferredResourceDisplayName', () => {
it('returns displayName when set', () => {
const resource = createResource({ name: 'machine-1', displayName: 'Production Server' });
- expect(getDisplayName(resource)).toBe('Production Server');
+ expect(getPreferredResourceDisplayName(resource)).toBe('Production Server');
});
it('returns name when displayName is empty', () => {
const resource = createResource({ name: 'machine-1', displayName: '' });
- expect(getDisplayName(resource)).toBe('machine-1');
+ expect(getPreferredResourceDisplayName(resource)).toBe('machine-1');
});
it('returns name when displayName is undefined', () => {
const resource = createResource({ name: 'machine-1' });
// Force displayName to be falsy
(resource as any).displayName = undefined;
- expect(getDisplayName(resource)).toBe('machine-1');
+ expect(getPreferredResourceDisplayName(resource)).toBe('machine-1');
});
it('returns the safe label for governed resources', () => {
@@ -120,7 +120,7 @@ describe('Resource Helper Functions', () => {
aiSafeSummary: 'Production VM',
} as Partial<Resource>);
- expect(getDisplayName(resource)).toBe('Production VM');
+ expect(getPreferredResourceDisplayName(resource)).toBe('Production VM');
});
it('falls back to the redacted policy label when the safe summary is missing', () => {
@@ -133,7 +133,7 @@ describe('Resource Helper Functions', () => {
},
} as Partial<Resource>);
- expect(getDisplayName(resource)).toBe('redacted by policy');
+ expect(getPreferredResourceDisplayName(resource)).toBe('redacted by policy');
});
});
diff --git a/frontend-modern/src/types/resource.ts b/frontend-modern/src/types/resource.ts
index dfa66f4530..de3ff34bc1 100644
--- a/frontend-modern/src/types/resource.ts
+++ b/frontend-modern/src/types/resource.ts
@@ -501,16 +501,6 @@ export interface ResourceFilter {
search?: string;
}
-/**
- * Helper to get effective display name
- */
-export function getDisplayName(r: Resource): string {
- if (requiresGovernedResourceDisplay(r.policy)) {
- return r.aiSafeSummary?.trim() || 'redacted by policy';
- }
- return r.displayName || r.name;
-}
-
/**
* Helper to get CPU percentage
*/