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 workload presentation helpers
rcourtman0b0090450cf5
diff --git a/frontend-modern/src/components/Dashboard/GuestDrawer.tsx b/frontend-modern/src/components/Dashboard/GuestDrawer.tsxindex 9eb204b05a..095c65d66e 100644--- a/frontend-modern/src/components/Dashboard/GuestDrawer.tsx+++ b/frontend-modern/src/components/Dashboard/GuestDrawer.tsx@@ -4,8 +4,11 @@ import type { WorkloadGuest } from '@/types/workloads';import { formatBytes, formatUptime } from '@/utils/format';import { DiskList } from './DiskList';import { DiscoveryTab } from '../Discovery/DiscoveryTab';-import type { ResourceType as DiscoveryResourceType } from '@/types/discovery';-import { resolveWorkloadType } from '@/utils/workloads';+import {+ getDiscoveryResourceTypeForWorkload,+ getWebInterfaceTargetLabelForWorkload,+ resolveWorkloadType,+} from '@/utils/workloads';import { buildInfrastructureHrefForWorkload } from './infrastructureLink';import { WebInterfaceUrlField } from '@/components/shared/WebInterfaceUrlField';import { getDiscoveryLoadingState } from '@/utils/discoveryPresentation';@@ -101,28 +104,12 @@ export const GuestDrawer: Component<GuestDrawerProps> = (props) => {const switchTab = (tab: 'overview' | 'discovery') => {setActiveTab(tab);};-- // Get discovery resource type for the guest- const discoveryResourceType = (): DiscoveryResourceType => {- const type = resolveWorkloadType(props.guest);- if (type === 'vm') return 'vm';- if (type === 'app-container') return 'app-container';- if (type === 'pod') return 'pod';- return 'system-container';- };const discoveryAgentId = () => {return getDiscoveryHostIdForWorkload(props.guest);};const discoveryResourceId = () => {return getDiscoveryResourceIdForWorkload(props.guest);};-- const urlTargetLabel = () => {- const type = resolveWorkloadType(props.guest);- if (type === 'app-container') return 'container';- if (type === 'pod') return 'workload';- return 'workload';- };return (<div class="space-y-3">{/* Tabs */}@@ -402,7 +389,7 @@ export const GuestDrawer: Component<GuestDrawerProps> = (props) => {<WebInterfaceUrlFieldmetadataKind="guest"metadataId={guestId()}- targetLabel={urlTargetLabel()}+ targetLabel={getWebInterfaceTargetLabelForWorkload(props.guest)}customUrl={props.customUrl}onCustomUrlChange={(url) => props.onCustomUrlChange?.(guestId(), url)}/>@@ -425,7 +412,7 @@ export const GuestDrawer: Component<GuestDrawerProps> = (props) => {}><DiscoveryTab- resourceType={discoveryResourceType()}+ resourceType={getDiscoveryResourceTypeForWorkload(props.guest)}agentId={discoveryAgentId()}resourceId={discoveryResourceId()}hostname={props.guest.name}diff --git a/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts b/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.tsindex 79da25ee18..3df517e74c 100644--- a/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts+++ b/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts@@ -59,6 +59,7 @@ import guestRowSource from '@/components/Dashboard/GuestRow.tsx?raw';import dashboardDiskListSource from '@/components/Dashboard/DiskList.tsx?raw';import guestDrawerSource from '@/components/Dashboard/GuestDrawer.tsx?raw';import dashboardGuestPresentationSource from '@/utils/dashboardGuestPresentation.ts?raw';+import workloadsSource from '@/utils/workloads.ts?raw';import dashboardAlertPresentationSource from '@/utils/dashboardAlertPresentation.ts?raw';import dashboardStoragePresentationSource from '@/utils/dashboardStoragePresentation.ts?raw';import dashboardRecoveryPresentationSource from '@/utils/dashboardRecoveryPresentation.ts?raw';@@ -1843,7 +1844,13 @@ describe('frontend resource type boundaries', () => {expect(discoveryTabSource).toContain('getDiscoveryLoadingState');expect(discoveryTabSource).toContain('getDiscoverySuggestedURLFallback');expect(discoveryTabSource).toContain('getDiscoveryNotesEmptyState');+ expect(guestDrawerSource).toContain('getDiscoveryResourceTypeForWorkload');+ expect(guestDrawerSource).toContain('getWebInterfaceTargetLabelForWorkload');expect(guestDrawerSource).toContain('getDiscoveryLoadingState');+ expect(guestDrawerSource).not.toContain('const discoveryResourceType = () =>');+ expect(guestDrawerSource).not.toContain('const urlTargetLabel = () =>');+ expect(workloadsSource).toContain('export const getDiscoveryResourceTypeForWorkload');+ expect(workloadsSource).toContain('export const getWebInterfaceTargetLabelForWorkload');expect(infrastructureDetailsDrawerSource).toContain('getDiscoveryLoadingState');expect(resourceDetailDrawerSource).toContain('getDiscoveryLoadingState');expect(discoveryTabSource).not.toContain('const getURLSuggestionSourceLabel =');diff --git a/frontend-modern/src/utils/__tests__/workloads.test.ts b/frontend-modern/src/utils/__tests__/workloads.test.tsindex f3d2cd067d..b60f50ef88 100644--- a/frontend-modern/src/utils/__tests__/workloads.test.ts+++ b/frontend-modern/src/utils/__tests__/workloads.test.ts@@ -1,10 +1,12 @@import { describe, expect, it } from 'vitest';import {canonicalizeWorkloadFilterType,+ getDiscoveryResourceTypeForWorkload,resolveWorkloadType,resolveWorkloadTypeFromString,getWorkloadMetricsKind,getCanonicalWorkloadId,+ getWebInterfaceTargetLabelForWorkload,} from '@/utils/workloads';import type { WorkloadGuest } from '@/types/workloads';@@ -201,3 +203,37 @@ describe('getCanonicalWorkloadId', () => {expect(getCanonicalWorkloadId(guest)).toBe('test');});});++describe('getDiscoveryResourceTypeForWorkload', () => {+ it('returns the canonical discovery resource type for VM workloads', () => {+ const guest = { workloadType: 'vm' as const, type: 'vm' };+ expect(getDiscoveryResourceTypeForWorkload(guest)).toBe('vm');+ });++ it('returns the canonical discovery resource type for app-container workloads', () => {+ const guest = { workloadType: 'app-container' as const, type: 'docker' };+ expect(getDiscoveryResourceTypeForWorkload(guest)).toBe('app-container');+ });++ it('returns the canonical discovery resource type for pod workloads', () => {+ const guest = { workloadType: 'pod' as const, type: 'k8s' };+ expect(getDiscoveryResourceTypeForWorkload(guest)).toBe('pod');+ });+});++describe('getWebInterfaceTargetLabelForWorkload', () => {+ it('labels app-container workloads as container', () => {+ const guest = { workloadType: 'app-container' as const, type: 'docker' };+ expect(getWebInterfaceTargetLabelForWorkload(guest)).toBe('container');+ });++ it('labels pod workloads as workload', () => {+ const guest = { workloadType: 'pod' as const, type: 'pod' };+ expect(getWebInterfaceTargetLabelForWorkload(guest)).toBe('workload');+ });++ it('labels vm workloads as workload', () => {+ const guest = { workloadType: 'vm' as const, type: 'qemu' };+ expect(getWebInterfaceTargetLabelForWorkload(guest)).toBe('workload');+ });+});diff --git a/frontend-modern/src/utils/workloads.ts b/frontend-modern/src/utils/workloads.tsindex 683fa49d00..445688f3f2 100644--- a/frontend-modern/src/utils/workloads.ts+++ b/frontend-modern/src/utils/workloads.ts@@ -1,4 +1,5 @@import type { WorkloadGuest, WorkloadType } from '@/types/workloads';+import type { ResourceType as DiscoveryResourceType } from '@/types/discovery';import type { MetricResourceKind } from '@/utils/metricsKeys';import { canonicalizeFrontendResourceType } from '@/utils/resourceTypeCompat';@@ -76,3 +77,12 @@ export const getCanonicalWorkloadId = (}return guest.id;};++export const getDiscoveryResourceTypeForWorkload = (+ guest: Pick<WorkloadGuest, 'workloadType' | 'type'>,+): DiscoveryResourceType => resolveWorkloadType(guest) as DiscoveryResourceType;++export const getWebInterfaceTargetLabelForWorkload = (+ guest: Pick<WorkloadGuest, 'workloadType' | 'type'>,+): 'container' | 'workload' =>+ resolveWorkloadType(guest) === 'app-container' ? 'container' : 'workload';