From 3e3e2313359092659fdd7c1334b79ebfe1d8b045 Mon Sep 17 00:00:00 2001 From: Ashraf Masarwa Date: Thu, 12 Nov 2026 11:36:04 +0200 Subject: [PATCH] EDM-6634: Invalid GPU reporting in the UI --- libs/i18n/locales/en/translation.json | 1 + .../DeviceDetails/SidebarDescriptionList.tsx | 4 +-- .../src/utils/capabilities.test.ts | 34 +++++++++++++++++++ libs/ui-components/src/utils/capabilities.ts | 8 ++++- 4 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 libs/ui-components/src/utils/capabilities.test.ts diff --git a/libs/i18n/locales/en/translation.json b/libs/i18n/locales/en/translation.json index 7894ca373..89a184fd7 100644 --- a/libs/i18n/locales/en/translation.json +++ b/libs/i18n/locales/en/translation.json @@ -724,6 +724,7 @@ "Details": "Details", "Details for {{name}}": "Details for {{name}}", "Details: {{errorDetails}}": "Details: {{errorDetails}}", + "Detected (details unavailable)": "Detected (details unavailable)", "Detected device ownership conflict": "Detected device ownership conflict", "device": "device", "Device": "Device", diff --git a/libs/ui-components/src/components/Device/DeviceDetails/SidebarDescriptionList.tsx b/libs/ui-components/src/components/Device/DeviceDetails/SidebarDescriptionList.tsx index 391ba7f00..789f4a6ab 100644 --- a/libs/ui-components/src/components/Device/DeviceDetails/SidebarDescriptionList.tsx +++ b/libs/ui-components/src/components/Device/DeviceDetails/SidebarDescriptionList.tsx @@ -11,7 +11,7 @@ import type { DeviceGpu, DeviceStatus } from '@flightctl/types'; import { DeviceFeatureBoolean } from '@flightctl/types/alpha'; import type { SystemInfoEntry } from '../../../hooks/useDeviceSystemInfo'; import { useTranslation } from '../../../hooks/useTranslation'; -import { getKvmFeature } from '../../../utils/capabilities'; +import { getGpuLabel, getKvmFeature } from '../../../utils/capabilities'; import { OsModeLabel } from '../../common/OsModeContent'; import LabelWithHelperText from '../../common/WithHelperText'; import SystemInfoDescriptionGroup from './SystemInfoDescriptionGroup'; @@ -88,7 +88,7 @@ const GpuCapabilityValue = ({ gpus }: { gpus: DeviceGpu[] | undefined }) => { if (gpus.length === 0) { return t('No GPUs found'); } - return <>{gpus.map((gpu) => `${gpu.vendor} ${gpu.model}`).join(', ')}; + return <>{gpus.map((gpu) => getGpuLabel(gpu, t)).join(', ')}; }; export const CapabilitiesFieldsList = ({ deviceStatus }: { deviceStatus: DeviceStatus | undefined }) => { diff --git a/libs/ui-components/src/utils/capabilities.test.ts b/libs/ui-components/src/utils/capabilities.test.ts new file mode 100644 index 000000000..9f7c46d54 --- /dev/null +++ b/libs/ui-components/src/utils/capabilities.test.ts @@ -0,0 +1,34 @@ +import type { TFunction } from 'i18next'; +import { describe, expect, it } from 'vitest'; +import type { DeviceGpu } from '@flightctl/types'; + +import { getGpuLabel } from './capabilities'; + +const t = ((key: string) => key) as unknown as TFunction; + +describe('getGpuLabel', () => { + it('joins vendor and model when both are present', () => { + const gpu: DeviceGpu = { index: 0, vendor: 'NVIDIA', model: 'RTX 4090' }; + expect(getGpuLabel(gpu, t)).toBe('NVIDIA RTX 4090'); + }); + + it('shows only the vendor when the model is missing', () => { + const gpu: DeviceGpu = { index: 0, vendor: 'NVIDIA' }; + expect(getGpuLabel(gpu, t)).toBe('NVIDIA'); + }); + + it('shows only the model when the vendor is missing', () => { + const gpu: DeviceGpu = { index: 0, model: 'RTX 4090' }; + expect(getGpuLabel(gpu, t)).toBe('RTX 4090'); + }); + + it('falls back to a placeholder when both vendor and model are missing', () => { + const gpu: DeviceGpu = { index: 0 }; + expect(getGpuLabel(gpu, t)).toBe('Detected (details unavailable)'); + }); + + it('falls back when vendor and model are empty strings', () => { + const gpu: DeviceGpu = { index: 0, vendor: '', model: '' }; + expect(getGpuLabel(gpu, t)).toBe('Detected (details unavailable)'); + }); +}); diff --git a/libs/ui-components/src/utils/capabilities.ts b/libs/ui-components/src/utils/capabilities.ts index 5212aae01..060810c9b 100644 --- a/libs/ui-components/src/utils/capabilities.ts +++ b/libs/ui-components/src/utils/capabilities.ts @@ -1,4 +1,5 @@ -import { type Device, type DeviceStatus, OsModeType } from '@flightctl/types'; +import type { TFunction } from 'i18next'; +import { type Device, type DeviceGpu, type DeviceStatus, OsModeType } from '@flightctl/types'; import { DeviceFeatureBoolean } from '@flightctl/types/alpha'; import type { DeviceFeatureFilter, DeviceFeatureId } from './status/devices'; @@ -6,6 +7,11 @@ import type { DeviceFeatureFilter, DeviceFeatureId } from './status/devices'; export const hasPackageModeCapability = (device: Device): boolean => device.status?.systemInfo?.osMode === OsModeType.OsModePackage; +export const getGpuLabel = (gpu: DeviceGpu, t: TFunction): string => { + const parts = [gpu.vendor, gpu.model].filter(Boolean); + return parts.length > 0 ? parts.join(' ') : t('Detected (details unavailable)'); +}; + export const getGpuFeature = (deviceStatus?: DeviceStatus): DeviceFeatureBoolean | undefined => { const gpus = deviceStatus?.systemInfo?.gpus; if (!gpus) {