Parcourir la source

Avisos y firmware con datos reales; layout Ajustes reordenado

- Chips de Alertas calculados del feed real (avisos/hoy/críticos con motivos
  reales: temperatura, offline, señal débil…) — antes valores mock fijos (2/14/0)
- RecentAlerts: badge = total de no leídas (igual que la campana)
- FleetCard: MAC/firmware reales del router (overview incluye mac+firmware);
  fallback mock solo en demo (sin pill de 'actualización disponible' falsa)
- Ajustes: Datos y umbrales a la izquierda, Apariencia a la derecha
gnacho il y a 4 mois
Parent
commit
2e34e4f73c

+ 7 - 1
app/public/locales/en/translation.json

@@ -39,7 +39,13 @@
     "unreadCount_one": "unread alert",
     "unreadCount_other": "unread alerts",
     "viewRouter": "View router",
-    "wgPeerCaption": "WireGuard peer · wg0"
+    "wgPeerCaption": "WireGuard peer · wg0",
+    "reason": {
+      "temp": "temperature",
+      "offline": "offline",
+      "weak": "weak signal",
+      "other": "other"
+    }
   },
   "auth": {
     "checking": "Checking session",

+ 7 - 1
app/public/locales/es/translation.json

@@ -39,7 +39,13 @@
     "unreadCount_one": "aviso sin leer",
     "unreadCount_other": "avisos sin leer",
     "viewRouter": "Ver router",
-    "wgPeerCaption": "Peer WireGuard · wg0"
+    "wgPeerCaption": "Peer WireGuard · wg0",
+    "reason": {
+      "temp": "temperatura",
+      "offline": "offline",
+      "weak": "señal débil",
+      "other": "otros"
+    }
   },
   "auth": {
     "checking": "Comprobando sesión",

+ 5 - 3
app/src/components/routers/FleetCard.tsx

@@ -11,6 +11,7 @@ import { MetricBar } from '@/components/MetricBar'
 import { Sparkline } from '@/components/Sparkline'
 import { StatusPill } from '@/components/StatusPill'
 import { getRouterExtras } from '@/components/routers/routerExtras'
+import { EMPTY_EXTRAS, useNetPulse } from '@/data/DataProvider'
 import { cn } from '@/lib/utils'
 
 function MetricRow({
@@ -55,7 +56,8 @@ interface FleetCardProps {
 /** FleetCard grande de /routers (routers.md §②) */
 export function FleetCard({ router, index = 0, refreshKey = 0 }: FleetCardProps) {
   const { t } = useTranslation()
-  const extras = getRouterExtras(router.id)
+  const { isDemo } = useNetPulse()
+  const extras = isDemo ? getRouterExtras(router.id) : EMPTY_EXTRAS
   const warn = router.status === 'warn'
   const reduce = useReducedMotion()
   const isGateway = router.id === 'flint2'
@@ -145,8 +147,8 @@ export function FleetCard({ router, index = 0, refreshKey = 0 }: FleetCardProps)
         <div className="mt-4 grid grid-cols-2 gap-x-4 gap-y-1.5 rounded-xl bg-elevated/60 px-3.5 py-3">
           {[
             ['IP', router.ip],
-            ['MAC', extras.mac],
-            ['Firmware', extras.firmwareBase ? `${extras.firmware} / ${extras.firmwareBase}` : extras.firmware],
+            ['MAC', router.mac ?? extras.mac],
+            ['Firmware', router.firmware ?? (extras.firmwareBase ? `${extras.firmware} / ${extras.firmwareBase}` : extras.firmware)],
             ['Uptime', fmtUptime(router.uptime)],
           ].map(([k, v]) => (
             <div key={k} className="min-w-0">

+ 4 - 0
app/src/data/types.ts

@@ -24,6 +24,10 @@ export interface Router {
   /** Pill de rol: "Principal" | "AP" */
   roleBadge: 'Principal' | 'AP'
   ip: string
+  /** MAC del bridge br-lan (live) */
+  mac?: string
+  /** Descripción del firmware (live, system board) */
+  firmware?: string
   status: Status
   /** Salud 0–100 */
   health: number

+ 29 - 6
app/src/pages/Alerts.tsx

@@ -445,13 +445,34 @@ export default function Alerts() {
         </div>
       </div>
 
-      {/* ② Resumen — 3 chips-stats */}
+      {/* ② Resumen — 3 chips-stats (datos reales del feed) */}
+      {(() => {
+        const warns = alertFeed.filter((ev) => ev.severity === 'warn' && !isRead(ev))
+        const crits = alertFeed.filter((ev) => ev.severity === 'critical' && !isRead(ev))
+        const today = alertFeed.filter((ev) => ev.day === 'hoy')
+        const reasonOf = (id: string) =>
+          id.startsWith('alert-temp')
+            ? t('alerts.reason.temp')
+            : id.startsWith('alert-offline')
+              ? t('alerts.reason.offline')
+              : id.startsWith('alert-weak')
+                ? t('alerts.reason.weak')
+                : id.startsWith('alert-wg')
+                  ? 'WireGuard'
+                  : t('alerts.reason.other')
+        const summarize = (list: typeof alertFeed) => {
+          const counts = new Map<string, number>()
+          for (const a of list) counts.set(reasonOf(a.id), (counts.get(reasonOf(a.id)) ?? 0) + 1)
+          return [...counts].map(([k, n]) => `${n} ${k}`).join(' · ')
+        }
+        const chips = [
+          { icon: AlertTriangle, tone: 'bg-warn/10 text-warn', value: warns.length, label: t('alerts.chipWarnings'), caption: warns.length ? summarize(warns) : null, wiggle: false },
+          { icon: Info, tone: 'bg-info/10 text-info', value: today.length, label: t('alerts.chipToday'), caption: null, wiggle: false },
+          { icon: CheckCircle2, tone: crits.length ? 'bg-danger/10 text-danger' : 'bg-ok/10 text-ok', value: crits.length, label: t('alerts.chipCritical'), caption: crits.length ? summarize(crits) : t('alerts.chipCriticalCaption'), wiggle: crits.length === 0 },
+        ]
+        return (
       <div className="mt-5 grid grid-cols-3 gap-3 md:gap-4">
-        {[
-          { icon: AlertTriangle, tone: 'bg-warn/10 text-warn', value: 2, label: t('alerts.chipWarnings'), caption: t('alerts.chipWarningsCaption'), wiggle: false },
-          { icon: Info, tone: 'bg-info/10 text-info', value: 14, label: t('alerts.chipToday'), caption: null, wiggle: false },
-          { icon: CheckCircle2, tone: 'bg-ok/10 text-ok', value: 0, label: t('alerts.chipCritical'), caption: t('alerts.chipCriticalCaption'), wiggle: true },
-        ].map((chip, i) => (
+        {chips.map((chip, i) => (
           <motion.div
             key={chip.label}
             initial={reduce ? false : { opacity: 0, y: 12 }}
@@ -482,6 +503,8 @@ export default function Alerts() {
           </motion.div>
         ))}
       </div>
+        )
+      })()}
 
       {/* ③ Filtros */}
       <div className="mt-5 flex flex-wrap items-center gap-2.5 md:gap-3">

+ 131 - 131
app/src/pages/Settings.tsx

@@ -1173,137 +1173,6 @@ export default function Settings() {
       </motion.p>
 
       <div className="mt-5 grid grid-cols-1 gap-4 md:gap-5 lg:grid-cols-12">
-        {/* ② Apariencia */}
-        <div className="lg:col-span-7">
-          <Card title={t('settings.appearance')} caption={t('settings.appearanceCaption')} index={0} reduce={reduce}>
-            {/* Tema: 3 cards visuales */}
-            <div className="grid grid-cols-3 gap-3" role="radiogroup" aria-label={t('nav.theme')}>
-              {THEME_OPTIONS.map((opt) => {
-                const active = mode === opt.value
-                return (
-                  <button
-                    key={opt.value}
-                    type="button"
-                    role="radio"
-                    aria-checked={active}
-                    onClick={() => {
-                      setMode(opt.value)
-                      notify()
-                    }}
-                    className={cn(
-                      'group relative flex flex-col gap-2 rounded-xl border p-2 text-left transition-colors duration-150',
-                      active ? 'border-accent bg-accent-soft' : 'border-border bg-elevated hover:border-accent/40',
-                    )}
-                  >
-                    <span className="relative block h-20 overflow-hidden rounded-lg sm:h-24">
-                      <ThemePreview variant={opt.value} />
-                      <AnimatePresence>
-                        {active && (
-                          <motion.span
-                            initial={{ scale: 0 }}
-                            animate={{ scale: 1 }}
-                            exit={{ scale: 0 }}
-                            transition={{ type: 'spring', stiffness: 500, damping: 25 }}
-                            className="absolute right-1.5 top-1.5 flex h-5 w-5 items-center justify-center rounded-full bg-accent text-canvas"
-                          >
-                            <Check className="h-3 w-3" strokeWidth={2.5} />
-                          </motion.span>
-                        )}
-                      </AnimatePresence>
-                    </span>
-                    <span className="flex items-center gap-1.5 px-0.5 text-xs font-medium text-text-primary">
-                      <opt.icon className={cn('h-3.5 w-3.5', active ? 'text-accent' : 'text-text-muted')} strokeWidth={1.75} />
-                      {t(opt.labelKey)}
-                    </span>
-                  </button>
-                )
-              })}
-            </div>
-
-            {/* Acento */}
-            <div className="mt-5">
-              <div className="text-caption font-semibold uppercase tracking-[0.06em] text-text-muted">{t('settings.accent')}</div>
-              <div className="mt-2.5 flex items-center gap-3">
-                {ACCENTS.map((a) => {
-                  const active = accentId === a.id
-                  return (
-                    <motion.button
-                      key={a.id}
-                      type="button"
-                      aria-label={t('settings.accentAria', { label: t(a.labelKey) })}
-                      aria-pressed={active}
-                      whileTap={reduce ? undefined : { scale: 0.8 }}
-                      onClick={() => {
-                        setAccentId(a.id)
-                        notify()
-                      }}
-                      className={cn(
-                        'flex h-9 w-9 items-center justify-center rounded-full transition-shadow duration-150',
-                        active ? 'ring-2 ring-accent ring-offset-2 ring-offset-surface' : 'hover:ring-2 hover:ring-border-strong hover:ring-offset-2 hover:ring-offset-surface',
-                      )}
-                      style={{ backgroundColor: a.swatch }}
-                    >
-                      {active && <Check className="h-4 w-4 text-[#070B12]" strokeWidth={2.5} />}
-                    </motion.button>
-                  )
-                })}
-                <span className="ml-1 text-caption text-text-muted">{t('settings.accentCaption')}</span>
-              </div>
-            </div>
-
-            {/* Densidad + idioma + animaciones */}
-            <div className="mt-5 flex flex-wrap items-center justify-between gap-3 border-t border-border pt-4">
-              <div>
-                <div className="text-sm font-medium text-text-primary">{t('settings.density')}</div>
-                <div className="text-caption text-text-muted">{t('settings.densityCaption')}</div>
-              </div>
-              <SegmentedControl
-                options={[
-                  { value: 'comoda', label: t('settings.densityComfy') },
-                  { value: 'compacta', label: t('settings.densityCompact') },
-                ]}
-                value={density}
-                onChange={(v) => {
-                  setDensity(v)
-                  notify()
-                }}
-                ariaLabel={t('settings.density')}
-              />
-            </div>
-            {/* Idioma */}
-            <div className="flex flex-wrap items-center justify-between gap-3 border-t border-border pt-4">
-              <div>
-                <div className="text-sm font-medium text-text-primary">{t('settings.language')}</div>
-                <div className="text-caption text-text-muted">{t('settings.languageCaption')}</div>
-              </div>
-              <SegmentedControl
-                options={[
-                  { value: 'auto', label: t('settings.languageAuto') },
-                  { value: 'es', label: 'Español' },
-                  { value: 'en', label: 'English' },
-                ]}
-                value={lang}
-                onChange={(v) => {
-                  setLanguage(v)
-                  notify()
-                }}
-                ariaLabel={t('settings.language')}
-              />
-            </div>
-            <div className="border-t border-border pt-2">
-              <SwitchRow
-                label={t('settings.reduceMotion')}
-                caption={t('settings.reduceMotionCaption')}
-                checked={reduceMotion}
-                onCheckedChange={(v) => {
-                  setReduceMotion(v)
-                  notify()
-                }}
-              />
-            </div>
-          </Card>
-        </div>
-
         {/* ④ Datos y umbrales */}
         <div className="lg:col-span-7">
           <Card
@@ -1467,6 +1336,137 @@ export default function Settings() {
           </Card>
         </div>
 
+        {/* ② Apariencia */}
+        <div className="lg:col-span-5">
+          <Card title={t('settings.appearance')} caption={t('settings.appearanceCaption')} index={0} reduce={reduce}>
+            {/* Tema: 3 cards visuales */}
+            <div className="grid grid-cols-3 gap-3" role="radiogroup" aria-label={t('nav.theme')}>
+              {THEME_OPTIONS.map((opt) => {
+                const active = mode === opt.value
+                return (
+                  <button
+                    key={opt.value}
+                    type="button"
+                    role="radio"
+                    aria-checked={active}
+                    onClick={() => {
+                      setMode(opt.value)
+                      notify()
+                    }}
+                    className={cn(
+                      'group relative flex flex-col gap-2 rounded-xl border p-2 text-left transition-colors duration-150',
+                      active ? 'border-accent bg-accent-soft' : 'border-border bg-elevated hover:border-accent/40',
+                    )}
+                  >
+                    <span className="relative block h-20 overflow-hidden rounded-lg sm:h-24">
+                      <ThemePreview variant={opt.value} />
+                      <AnimatePresence>
+                        {active && (
+                          <motion.span
+                            initial={{ scale: 0 }}
+                            animate={{ scale: 1 }}
+                            exit={{ scale: 0 }}
+                            transition={{ type: 'spring', stiffness: 500, damping: 25 }}
+                            className="absolute right-1.5 top-1.5 flex h-5 w-5 items-center justify-center rounded-full bg-accent text-canvas"
+                          >
+                            <Check className="h-3 w-3" strokeWidth={2.5} />
+                          </motion.span>
+                        )}
+                      </AnimatePresence>
+                    </span>
+                    <span className="flex items-center gap-1.5 px-0.5 text-xs font-medium text-text-primary">
+                      <opt.icon className={cn('h-3.5 w-3.5', active ? 'text-accent' : 'text-text-muted')} strokeWidth={1.75} />
+                      {t(opt.labelKey)}
+                    </span>
+                  </button>
+                )
+              })}
+            </div>
+
+            {/* Acento */}
+            <div className="mt-5">
+              <div className="text-caption font-semibold uppercase tracking-[0.06em] text-text-muted">{t('settings.accent')}</div>
+              <div className="mt-2.5 flex items-center gap-3">
+                {ACCENTS.map((a) => {
+                  const active = accentId === a.id
+                  return (
+                    <motion.button
+                      key={a.id}
+                      type="button"
+                      aria-label={t('settings.accentAria', { label: t(a.labelKey) })}
+                      aria-pressed={active}
+                      whileTap={reduce ? undefined : { scale: 0.8 }}
+                      onClick={() => {
+                        setAccentId(a.id)
+                        notify()
+                      }}
+                      className={cn(
+                        'flex h-9 w-9 items-center justify-center rounded-full transition-shadow duration-150',
+                        active ? 'ring-2 ring-accent ring-offset-2 ring-offset-surface' : 'hover:ring-2 hover:ring-border-strong hover:ring-offset-2 hover:ring-offset-surface',
+                      )}
+                      style={{ backgroundColor: a.swatch }}
+                    >
+                      {active && <Check className="h-4 w-4 text-[#070B12]" strokeWidth={2.5} />}
+                    </motion.button>
+                  )
+                })}
+                <span className="ml-1 text-caption text-text-muted">{t('settings.accentCaption')}</span>
+              </div>
+            </div>
+
+            {/* Densidad + idioma + animaciones */}
+            <div className="mt-5 flex flex-wrap items-center justify-between gap-3 border-t border-border pt-4">
+              <div>
+                <div className="text-sm font-medium text-text-primary">{t('settings.density')}</div>
+                <div className="text-caption text-text-muted">{t('settings.densityCaption')}</div>
+              </div>
+              <SegmentedControl
+                options={[
+                  { value: 'comoda', label: t('settings.densityComfy') },
+                  { value: 'compacta', label: t('settings.densityCompact') },
+                ]}
+                value={density}
+                onChange={(v) => {
+                  setDensity(v)
+                  notify()
+                }}
+                ariaLabel={t('settings.density')}
+              />
+            </div>
+            {/* Idioma */}
+            <div className="flex flex-wrap items-center justify-between gap-3 border-t border-border pt-4">
+              <div>
+                <div className="text-sm font-medium text-text-primary">{t('settings.language')}</div>
+                <div className="text-caption text-text-muted">{t('settings.languageCaption')}</div>
+              </div>
+              <SegmentedControl
+                options={[
+                  { value: 'auto', label: t('settings.languageAuto') },
+                  { value: 'es', label: 'Español' },
+                  { value: 'en', label: 'English' },
+                ]}
+                value={lang}
+                onChange={(v) => {
+                  setLanguage(v)
+                  notify()
+                }}
+                ariaLabel={t('settings.language')}
+              />
+            </div>
+            <div className="border-t border-border pt-2">
+              <SwitchRow
+                label={t('settings.reduceMotion')}
+                caption={t('settings.reduceMotionCaption')}
+                checked={reduceMotion}
+                onCheckedChange={(v) => {
+                  setReduceMotion(v)
+                  notify()
+                }}
+              />
+            </div>
+          </Card>
+        </div>
+
         {/* Servicios visibles (checks) */}
         <div className="lg:col-span-7">
           <ServicesCard reduce={reduce} onSaved={notify} />

+ 3 - 2
app/src/sections/RecentAlerts.tsx

@@ -12,11 +12,12 @@ import { cn } from '@/lib/utils'
 export function RecentAlerts() {
   const { t } = useTranslation()
   const navigate = useNavigate()
-  const { alerts } = useNetPulse()
+  const { alerts, unreadAlerts } = useNetPulse()
   const [readIds, setReadIds] = useState<Set<string>>(new Set())
   const [spinning, setSpinning] = useState(false)
   const recent = alerts.slice(0, 4)
-  const unread = recent.filter((a) => !a.read && !readIds.has(a.id)).length
+  // El badge muestra el total de no leídas (como la campana), no solo de las 4 visibles
+  const unread = Math.max(0, unreadAlerts - readIds.size)
 
   const markReadAndGo = (id: string) => {
     setReadIds((prev) => new Set(prev).add(id))

+ 2 - 0
server/src/adapters/index.js

@@ -234,6 +234,8 @@ function createLiveAdapter(config, dbHandle, initialRouters) {
       role: cfg.id === gatewayCfg?.id ? 'Gateway principal' : 'Punto de acceso',
       roleBadge: cfg.id === gatewayCfg?.id ? 'Principal' : 'AP',
       ip: cfg.host,
+      mac: polled.brMac ?? undefined,
+      firmware: polled.board?.release?.description ?? undefined,
       status: temp > 65 || polled.cpu > 85 ? 'warn' : 'online',
       health,
       cpu: polled.cpu,