Humanize vSphere Networks Type column

vCenter exposes the network type as a raw enum: STANDARD_PORTGROUP,
DISTRIBUTED_PORTGROUP, OPAQUE_NETWORK. The Datastores table shows
raw enums too (NFS41 / VMFS / vSAN) but those are recognizable
shorthand every vSphere operator already speaks; the network
enums are not, and rendering them as-is reads as API exhaust.

Map the three known values to the names vCenter uses in its own
UI:

  STANDARD_PORTGROUP    -> Standard port group
  DISTRIBUTED_PORTGROUP -> vDS port group
  OPAQUE_NETWORK        -> NSX network

Unknown future enum values fall back to the raw string rather
than getting silently dropped or guessed.
This commit is contained in:
rcourtman
2026-05-23 16:07:14 +01:00
parent a57217b194
commit 68dbaf5102
2 changed files with 22 additions and 4 deletions
@@ -56,8 +56,23 @@ const VSPHERE_NETWORK_STATUS_OPTIONS: PlatformTableFilterOption<VmwareNetworkSta
const networkName = (resource: Resource): string =>
asTrimmedString(resource.displayName) || asTrimmedString(resource.name) || resource.id;
const networkType = (resource: Resource): string =>
asTrimmedString(resource.vmware?.networkType) || '—';
// vCenter exposes the network type as a raw enum like `STANDARD_PORTGROUP`,
// `DISTRIBUTED_PORTGROUP`, or `OPAQUE_NETWORK`. The Datastores table shows
// raw enums too (NFS41 / VMFS / vSAN) but those are recognizable shorthand
// every vSphere operator already speaks; the network enums are not. Map the
// known ones to the names vCenter itself uses in the UI, and leave any
// unknown future enum value as-is (uppercased) rather than guessing.
const NETWORK_TYPE_LABELS: Record<string, string> = {
STANDARD_PORTGROUP: 'Standard port group',
DISTRIBUTED_PORTGROUP: 'vDS port group',
OPAQUE_NETWORK: 'NSX network',
};
const networkType = (resource: Resource): string => {
const raw = asTrimmedString(resource.vmware?.networkType);
if (!raw) return '—';
return NETWORK_TYPE_LABELS[raw.toUpperCase()] ?? raw;
};
const compactList = (values: Array<string | undefined>): string[] =>
values.map((value) => asTrimmedString(value)).filter((value): value is string => Boolean(value));
@@ -66,8 +66,11 @@ describe('VsphereNetworksTable', () => {
expect(within(table).getByText('Hosts')).toBeInTheDocument();
expect(within(table).getByText('Connected VMs')).toBeInTheDocument();
expect(within(table).queryByRole('columnheader', { name: 'State' })).not.toBeInTheDocument();
expect(screen.getByText('STANDARD_PORTGROUP')).toBeInTheDocument();
expect(screen.getByText('DISTRIBUTED_PORTGROUP')).toBeInTheDocument();
// vCenter's raw enums (STANDARD_PORTGROUP / DISTRIBUTED_PORTGROUP) are
// mapped to operator-friendly labels matching the names vCenter uses
// in its own UI; the raw enum is no longer surfaced.
expect(screen.getByText('Standard port group')).toBeInTheDocument();
expect(screen.getByText('vDS port group')).toBeInTheDocument();
expect(screen.getByText('esxi-01.lab.local, esxi-02.lab.local')).toBeInTheDocument();
expect(screen.getByText('warehouse-api-01, etl-batch-01')).toBeInTheDocument();