From f6fb206d4d1fd24751ffa7ea4ad1c65259043137 Mon Sep 17 00:00:00 2001 From: Jason Staack Date: Sat, 21 Mar 2026 20:41:04 -0500 Subject: [PATCH] fix(20): add SNMP profiles settings link and device_count to profile list Adds SNMP Device Profiles card to SettingsPage for discoverability. Adds device_count correlated subquery to profile list SQL and schema field so the frontend profile cards show accurate device counts. Co-Authored-By: Claude Opus 4.6 (1M context) --- backend/app/routers/snmp_profiles.py | 16 +++++++++++----- backend/app/schemas/snmp_profile.py | 1 + .../src/components/settings/SettingsPage.tsx | 17 +++++++++++++++++ 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/backend/app/routers/snmp_profiles.py b/backend/app/routers/snmp_profiles.py index 119c966..173e860 100644 --- a/backend/app/routers/snmp_profiles.py +++ b/backend/app/routers/snmp_profiles.py @@ -79,11 +79,17 @@ async def list_profiles( result = await db.execute( text(""" - SELECT id, tenant_id, name, description, sys_object_id, vendor, - category, is_system, created_at, updated_at - FROM snmp_profiles - WHERE tenant_id = :tenant_id OR tenant_id IS NULL - ORDER BY is_system DESC, name ASC + SELECT sp.id, sp.tenant_id, sp.name, sp.description, sp.sys_object_id, sp.vendor, + sp.category, sp.is_system, sp.created_at, sp.updated_at, + COALESCE(dc.device_count, 0) AS device_count + FROM snmp_profiles sp + LEFT JOIN LATERAL ( + SELECT COUNT(*) AS device_count + FROM devices d + WHERE d.snmp_profile_id = sp.id + ) dc ON true + WHERE sp.tenant_id = :tenant_id OR sp.tenant_id IS NULL + ORDER BY sp.is_system DESC, sp.name ASC """), {"tenant_id": str(tenant_id)}, ) diff --git a/backend/app/schemas/snmp_profile.py b/backend/app/schemas/snmp_profile.py index c0a2a8e..1546b53 100644 --- a/backend/app/schemas/snmp_profile.py +++ b/backend/app/schemas/snmp_profile.py @@ -75,6 +75,7 @@ class SNMPProfileResponse(BaseModel): vendor: Optional[str] = None category: Optional[str] = None is_system: bool + device_count: int = 0 created_at: datetime updated_at: datetime diff --git a/frontend/src/components/settings/SettingsPage.tsx b/frontend/src/components/settings/SettingsPage.tsx index 83a5c0f..3ca01fe 100644 --- a/frontend/src/components/settings/SettingsPage.tsx +++ b/frontend/src/components/settings/SettingsPage.tsx @@ -167,6 +167,23 @@ export function SettingsPage() { )} + {/* SNMP Profiles */} + {isTenantAdmin(user) && ( +
+ + +
+ SNMP Device Profiles +

Manage OID collection profiles, upload MIBs, test against live devices

+
+ + +
+ )} + {/* Maintenance — super_admin only */} {isSuperAdmin(user) && (