Просмотр исходного кода

fix(alerts): derive relative time from the alert ts in the summary (#698) (#704)

AlertItem and the RouterDetail temp banner rendered the legacy time
field, which the backend hardcodes to a just-now string for live
alerts, so an alert from yesterday still read just now. Both now use
alertRelTime, which prefers the real ts and only falls back to the
legacy string when the timestamp is missing.

Co-authored-by: gnacho <hnacho@proton.me>
Nacho 2 месяцев назад
Родитель
Сommit
089212da00
3 измененных файлов с 5 добавлено и 4 удалено
  1. 1 0
      CHANGELOG.md
  2. 2 2
      app/src/components/AlertItem.tsx
  3. 2 2
      app/src/pages/RouterDetail.tsx

+ 1 - 0
CHANGELOG.md

@@ -9,6 +9,7 @@ y este proyecto se adhiere a [Versionado Semántico](https://semver.org/lang/es/
 
 ### Fixed
 
+- **El resumen de alertas de la Home ya no muestra "ahora mismo" para todo (#698)**: `AlertItem` (y el aviso de temperatura del detalle de router) pintaban el campo `time` legacy, que el backend rellena con "ahora mismo" fijo en las alertas en vivo; una alerta de ayer seguía diciendo "ahora mismo". Ahora usan `alertRelTime`, que calcula el relativo real desde `ts` y solo cae al string legacy si falta el timestamp.
 - **El "Visto" de la flota de agentes ya no oscila (#691)**: el contador de "último push" solo se recalculaba en renders esporádicos (con la llegada de snapshots), así que se congelaba entre actualizaciones y saltaba hacia atrás con cada push del agente (oscilación tipo 39-44-18-23 s). Un único reloj compartido de 1 s alimenta ahora toda la tabla: la celda avanza segundo a segundo y solo cae cuando llega un push realmente nuevo.
 
 - **El hostname de las reservas DHCP se valida y se escapa (#693)**: el `hostname` del endpoint `PUT /api/devices/{mac}/reservation` se interpolaba sin sanitizar en el comando `uci set` que corre por SSH como root en el router; una comilla simple rompía el quoting e inyectaba comandos arbitrarios. Ahora solo se aceptan hostnames DNS (letras, dígitos, guiones y puntos, hasta 253 caracteres; el resto recibe 400 `invalid_hostname`) y todos los valores interpolados en comandos uci -incluidos los rollbacks que re-leen config del router- viajan escapados. La UI manda el hostname solo cuando el nombre del dispositivo es un hostname DNS válido.

+ 2 - 2
app/src/components/AlertItem.tsx

@@ -1,7 +1,7 @@
 import { AlertTriangle, CheckCircle2, Info, OctagonX } from 'lucide-react'
 import type { LucideIcon } from 'lucide-react'
 import { useTranslation } from 'react-i18next'
-import { relTime } from '@/i18n'
+import { alertRelTime } from '@/i18n'
 import type { AlertSeverity, AlertEvent } from '@/data/mock'
 import { alertDescription, alertHint, alertTitle } from '@/lib/alerts-i18n'
 import { cn } from '@/lib/utils'
@@ -42,7 +42,7 @@ export function AlertItem({ alert, onClick, className }: AlertItemProps) {
       <div className="min-w-0 flex-1">
         <div className="flex items-center justify-between gap-2">
           <span className="truncate text-sm font-medium text-text-primary">{alertTitle(t, alert)}</span>
-          <span className="shrink-0 text-caption text-text-muted">{relTime(alert.time)}</span>
+          <span className="shrink-0 text-caption text-text-muted">{alertRelTime(alert)}</span>
         </div>
         <p className="mt-0.5 truncate text-caption text-text-secondary">{alertDescription(t, alert)}</p>
         {hint && (

+ 2 - 2
app/src/pages/RouterDetail.tsx

@@ -3,7 +3,7 @@ import { useTranslation } from 'react-i18next'
 import { Link, useLocation, useParams } from 'react-router'
 import { AlertTriangle, ArrowLeft, Gauge, Router as RouterIcon, ShieldAlert } from 'lucide-react'
 import { motion, useReducedMotion } from 'framer-motion'
-import { relTime } from '@/i18n'
+import { alertRelTime } from '@/i18n'
 import { useNetPulse } from '@/data/DataProvider'
 import type { RouterDetailData } from '@/data/DataProvider'
 import { useAuth } from '@/data/AuthContext'
@@ -159,7 +159,7 @@ export default function RouterDetail() {
               </p>
             </div>
             {tempAlert && (
-              <span className="shrink-0 font-mono text-caption text-text-muted">{relTime(tempAlert.time)}</span>
+              <span className="shrink-0 font-mono text-caption text-text-muted">{alertRelTime(tempAlert)}</span>
             )}
           </div>
         </motion.div>