Kaynağa Gözat

ux(snmp): label the community field as read-only and fix the poll hint

The community field read like a password prompt and the hint claimed SNMP replaces SSH entirely. The field is now labelled read-only with a line saying what it is, and the hint explains that inventory is read over SNMP while upgrades, config backups and console probes still use SSH.
Nacho 2 hafta önce
ebeveyn
işleme
c6e77bbf85

+ 3 - 2
app/public/locales/en/translation.json

@@ -1861,8 +1861,9 @@
       "firmwareTargetPlaceholder": "e.g. 25.12.5",
       "firmwareTargetHint": "Optional. If the installed firmware doesn't match this version, NetPulse alerts.",
       "snmpEnabled": "SNMP polling",
-      "snmpEnabledHint": "SNMP polling replaces SSH: no SSH connection is attempted on this unit.",
-      "snmpCommunity": "SNMP community",
+      "snmpEnabledHint": "Inventory is read over SNMP instead of SSH. Upgrades, config backups and console probes still use SSH when the unit supports it.",
+      "snmpCommunity": "SNMP community (read-only)",
+      "snmpCommunityHint": "String configured on the device itself, not a user or password. v1/v2c send it unencrypted.",
       "snmpCommunityConfigured": "Configured. Leave blank to keep it.",
       "snmpCommunityClear": "Remove community",
       "snmpPort": "Port",

+ 3 - 2
app/public/locales/es/translation.json

@@ -1861,8 +1861,9 @@
       "firmwareTargetPlaceholder": "p. ej. 25.12.5",
       "firmwareTargetHint": "Opcional. Si el firmware instalado no coincide con esta versión, NetPulse lo avisa.",
       "snmpEnabled": "Sondeo SNMP",
-      "snmpEnabledHint": "El sondeo SNMP sustituye a SSH: no se intenta ninguna conexión SSH con esta unidad.",
-      "snmpCommunity": "SNMP community",
+      "snmpEnabledHint": "El inventario se lee por SNMP en lugar de SSH. Las actualizaciones, las copias de configuración y el sondeo por consola siguen usando SSH cuando la unidad lo soporta.",
+      "snmpCommunity": "SNMP community (solo lectura)",
+      "snmpCommunityHint": "Cadena configurada en el propio equipo, no un usuario ni una contraseña. v1/v2c la envían sin cifrar.",
       "snmpCommunityConfigured": "Configurada. Déjala vacía para conservarla.",
       "snmpCommunityClear": "Borrar comunidad",
       "snmpPort": "Puerto",

+ 149 - 0
app/src/components/routers/SnmpCommunityField.tsx

@@ -0,0 +1,149 @@
+import { useEffect, useRef, useState } from 'react'
+import { ChevronDown } from 'lucide-react'
+
+import { cn } from '@/lib/utils'
+
+/**
+ * #2079: the SNMP community is an arbitrary string defined on the device, so it
+ * cannot be a closed select. This field keeps it free-text but opens its own
+ * suggestion list (not the browser datalist) with the values seen most often.
+ */
+export const SNMP_COMMUNITY_SUGGESTIONS = ['public', 'private', 'monitor', 'monitor-ro']
+
+interface Props {
+  id: string
+  value: string
+  onChange: (value: string) => void
+  ariaLabel: string
+  placeholder?: string
+  suggestions?: string[]
+}
+
+export default function SnmpCommunityField({
+  id,
+  value,
+  onChange,
+  ariaLabel,
+  placeholder = 'public',
+  suggestions = SNMP_COMMUNITY_SUGGESTIONS,
+}: Props) {
+  const [open, setOpen] = useState(false)
+  const [active, setActive] = useState(-1)
+  const boxRef = useRef<HTMLDivElement>(null)
+
+  const query = value.trim().toLowerCase()
+  const filtered = query ? suggestions.filter((s) => s.toLowerCase().includes(query)) : suggestions
+
+  useEffect(() => {
+    if (!open) return
+    const onPointerDown = (event: MouseEvent) => {
+      if (boxRef.current && !boxRef.current.contains(event.target as Node)) setOpen(false)
+    }
+    document.addEventListener('mousedown', onPointerDown)
+    return () => document.removeEventListener('mousedown', onPointerDown)
+  }, [open])
+
+  const close = () => {
+    setOpen(false)
+    setActive(-1)
+  }
+
+  const pick = (option: string) => {
+    onChange(option)
+    close()
+  }
+
+  const onKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
+    if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
+      event.preventDefault()
+      if (!open) {
+        setOpen(true)
+        return
+      }
+      if (filtered.length === 0) return
+      const step = event.key === 'ArrowDown' ? 1 : -1
+      setActive((prev) => {
+        const next = prev + step
+        if (next < 0) return filtered.length - 1
+        if (next >= filtered.length) return 0
+        return next
+      })
+      return
+    }
+    if (event.key === 'Enter' && open && active >= 0) {
+      const option = filtered[active]
+      if (option) {
+        event.preventDefault()
+        pick(option)
+      }
+      return
+    }
+    if (event.key === 'Escape' && open) {
+      event.preventDefault()
+      event.stopPropagation()
+      close()
+    }
+  }
+
+  return (
+    <div ref={boxRef} className="relative">
+      <div className="flex items-stretch gap-1">
+        <input
+          id={id}
+          type="text"
+          value={value}
+          onChange={(event) => {
+            onChange(event.target.value)
+            setOpen(true)
+            setActive(-1)
+          }}
+          onFocus={() => setOpen(true)}
+          onKeyDown={onKeyDown}
+          placeholder={placeholder}
+          aria-label={ariaLabel}
+          role="combobox"
+          aria-expanded={open}
+          aria-controls={`${id}-suggestions`}
+          aria-autocomplete="list"
+          autoComplete="off"
+          spellCheck={false}
+          className="w-full rounded-lg border border-border bg-elevated px-3 py-2 text-sm text-text-primary placeholder:text-text-muted focus:border-accent focus:outline-none"
+        />
+        <button
+          type="button"
+          onClick={() => setOpen((prev) => !prev)}
+          aria-label={ariaLabel}
+          aria-expanded={open}
+          aria-controls={`${id}-suggestions`}
+          className="flex w-8 shrink-0 items-center justify-center rounded-lg border border-border bg-elevated text-text-muted hover:bg-hover hover:text-text-secondary"
+        >
+          <ChevronDown className={cn('h-3.5 w-3.5 transition-transform', open && 'rotate-180')} strokeWidth={1.75} />
+        </button>
+      </div>
+      {open && filtered.length > 0 && (
+        <ul
+          id={`${id}-suggestions`}
+          role="listbox"
+          aria-label={ariaLabel}
+          className="absolute left-0 right-0 top-full z-50 mt-1 overflow-hidden rounded-lg border border-border bg-elevated py-1 shadow-lg"
+        >
+          {filtered.map((option, index) => (
+            <li key={option} role="option" aria-selected={index === active}>
+              <button
+                type="button"
+                onMouseEnter={() => setActive(index)}
+                onClick={() => pick(option)}
+                className={cn(
+                  'block w-full px-3 py-1.5 text-left text-sm',
+                  index === active ? 'bg-hover text-text-primary' : 'text-text-secondary',
+                )}
+              >
+                {option}
+              </button>
+            </li>
+          ))}
+        </ul>
+      )}
+    </div>
+  )
+}

+ 20 - 18
app/src/pages/Settings.tsx

@@ -5,6 +5,7 @@ import { AnimatePresence, motion, useReducedMotion } from 'framer-motion'
 import { BadgeCheck, CalendarClock, Check, ChevronDown, ChevronRight, ChevronUp, CircleAlert, Copy, Database, Download, ExternalLink, Eye, EyeOff, FileText, FlaskConical, Gauge, HardDrive, History, KeyRound, Loader2, Lock, LogOut, MonitorSmartphone, Moon, Pencil, Plus, Power, Radar, RefreshCw, Send, RotateCcw, RotateCw, Router as RouterIcon, Server, Settings2, Shield, ShieldCheck, Star, Sun, Trash2, TriangleAlert, UserCog, Users, Volume2, Wifi, X } from 'lucide-react'
 import type { LucideIcon } from 'lucide-react'
 import Integrations from './Integrations'
+import SnmpCommunityField from '@/components/routers/SnmpCommunityField'
 import { HealthRing } from '@/components/HealthRing'
 import { KnownMacsManager } from '@/components/KnownMacsManager'
 import { SegmentedControl } from '@/components/SegmentedControl'
@@ -322,6 +323,7 @@ type SnmpVersion = '1' | '2c' | '3'
 const SNMP_V3_AUTH_PROTOS = ['MD5', 'SHA', 'SHA224', 'SHA256', 'SHA384', 'SHA512']
 const SNMP_V3_PRIV_PROTOS = ['DES', 'AES', 'AES192', 'AES256', 'AES192C', 'AES256C']
 
+
 interface ConfigRouter {
   id: string
   name: string | null
@@ -1155,17 +1157,17 @@ function RoutersManager({ reduce, onSaved }: { reduce: boolean; onSaved: () => v
                   />
                 ) : (
                   <div>
-                    <label htmlFor="add-snmp-community" className="mb-1 block text-caption font-medium uppercase tracking-[0.06em] text-text-muted">
-                      {t('settings.routers.snmpCommunity')}
-                    </label>
-                    <input
+                    <div className="mb-1 flex items-center gap-1">
+                      <label htmlFor="add-snmp-community" className="block text-caption font-medium uppercase tracking-[0.06em] text-text-muted">
+                        {t('settings.routers.snmpCommunity')}
+                      </label>
+                      <InfoTip text={t('settings.routers.snmpCommunityHint')} />
+                    </div>
+                    <SnmpCommunityField
                       id="add-snmp-community"
-                      type="text"
                       value={addSnmpCommunity}
-                      onChange={(e) => setAddSnmpCommunity(e.target.value)}
-                      placeholder="public"
-                      aria-label={t('settings.routers.snmpCommunity')}
-                      className="w-full rounded-lg border border-border bg-elevated px-3 py-2 text-sm text-text-primary placeholder:text-text-muted focus:border-accent focus:outline-none"
+                      onChange={setAddSnmpCommunity}
+                      ariaLabel={t('settings.routers.snmpCommunity')}
                     />
                   </div>
                 )}
@@ -1420,17 +1422,17 @@ function RoutersManager({ reduce, onSaved }: { reduce: boolean; onSaved: () => v
                         />
                       ) : (
                         <div>
-                          <label htmlFor="snmp-community" className="mb-1 block text-caption font-medium uppercase tracking-[0.06em] text-text-muted">
-                            {t('settings.routers.snmpCommunity')}
-                          </label>
-                          <input
+                          <div className="mb-1 flex items-center gap-1">
+                            <label htmlFor="snmp-community" className="block text-caption font-medium uppercase tracking-[0.06em] text-text-muted">
+                              {t('settings.routers.snmpCommunity')}
+                            </label>
+                            <InfoTip text={t('settings.routers.snmpCommunityHint')} />
+                          </div>
+                          <SnmpCommunityField
                             id="snmp-community"
-                            type="text"
                             value={editSnmpCommunity}
-                            onChange={(e) => { setEditSnmpCommunity(e.target.value); setEditSnmpCommunityTouched(true) }}
-                            placeholder="public"
-                            aria-label={t('settings.routers.snmpCommunity')}
-                            className="w-full rounded-lg border border-border bg-elevated px-3 py-2 text-sm text-text-primary placeholder:text-text-muted focus:border-accent focus:outline-none"
+                            onChange={(v) => { setEditSnmpCommunity(v); setEditSnmpCommunityTouched(true) }}
+                            ariaLabel={t('settings.routers.snmpCommunity')}
                           />
                           {editSnmpCommunitySet && !editSnmpCommunityTouched && (
                             <div className="mt-1 flex items-center gap-2 text-xs text-muted-foreground">