From d2f48552bd85dc11fdeb28ef6ba38c1826d31295 Mon Sep 17 00:00:00 2001 From: Jason Staack Date: Sun, 22 Mar 2026 08:04:44 -0500 Subject: [PATCH] fix(ui): handle unwrapped credential profile arrays in AddDevice and BulkAdd The list API now returns a flat array but AddDeviceForm and BulkAddForm still accessed .profiles on the result. Now handles both shapes with Array.isArray fallback for safety. Co-Authored-By: Claude Opus 4.6 (1M context) --- frontend/src/components/fleet/AddDeviceForm.tsx | 6 +++--- frontend/src/components/fleet/BulkAddForm.tsx | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/frontend/src/components/fleet/AddDeviceForm.tsx b/frontend/src/components/fleet/AddDeviceForm.tsx index ab59003..eb475b7 100644 --- a/frontend/src/components/fleet/AddDeviceForm.tsx +++ b/frontend/src/components/fleet/AddDeviceForm.tsx @@ -247,11 +247,11 @@ export function AddDeviceForm({ tenantId, open, onClose }: Props) { ) - // Helper to get profile list as array + // Helper to get profile list as array (list() already unwraps the wrapper) const rosProfileList: CredentialProfileResponse[] = - rosProfiles?.profiles ?? [] + Array.isArray(rosProfiles) ? rosProfiles : (rosProfiles?.profiles ?? []) const snmpCredProfileList: CredentialProfileResponse[] = - (snmpCredProfiles?.profiles ?? []).filter( + (Array.isArray(snmpCredProfiles) ? snmpCredProfiles : (snmpCredProfiles?.profiles ?? [])).filter( (p) => p.credential_type === 'snmp_v2c' || p.credential_type === 'snmp_v3', ) diff --git a/frontend/src/components/fleet/BulkAddForm.tsx b/frontend/src/components/fleet/BulkAddForm.tsx index f91fca5..cb9d73d 100644 --- a/frontend/src/components/fleet/BulkAddForm.tsx +++ b/frontend/src/components/fleet/BulkAddForm.tsx @@ -87,7 +87,7 @@ export function BulkAddForm({ enabled: deviceType === 'snmp', }) - const allProfiles: CredentialProfileResponse[] = profiles?.profiles ?? [] + const allProfiles: CredentialProfileResponse[] = Array.isArray(profiles) ? profiles : (profiles?.profiles ?? []) const profileList = deviceType === 'snmp' ? allProfiles.filter((p) => p.credential_type === 'snmp_v2c' || p.credential_type === 'snmp_v3') : allProfiles