Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libs/i18n/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 }) => {
Expand Down
34 changes: 34 additions & 0 deletions libs/ui-components/src/utils/capabilities.test.ts
Original file line number Diff line number Diff line change
@@ -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)');
});
});
8 changes: 7 additions & 1 deletion libs/ui-components/src/utils/capabilities.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
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';

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) {
Expand Down
Loading