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) <noreply@anthropic.com>
This commit is contained in:
Jason Staack
2026-03-22 08:04:44 -05:00
parent 1888f850af
commit d2f48552bd
2 changed files with 4 additions and 4 deletions

View File

@@ -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',
)

View File

@@ -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