4
0
Эх сурвалжийг харах

feat(update): center the update dialog on the news (#1223)

- Drop the 'several steps / takes a few minutes' description and the
  'Estimated time' line; the dialog leads with the version card and the
  changelog
- Version card shows real semver (currentVersion/latestVersion from
  /api/update/status) with the commit as a small secondary detail. Rolling
  layouts used to show bare short SHAs on both sides; latestVersion is the
  latest release tag, so 2.32.0 -> 2.34.0 instead of 5557426 -> abc1234
- Prerequisites collapse behind a toggle, expanded on demand
- Changelog entries go from text-caption to text-sm

The updater tests mock GitHub per test: rolling checks now also hit
/releases/latest, so the rolling mocks answer it.

Closes #1222
Nacho 2 сар өмнө
parent
commit
2b7ae18de3

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

@@ -1981,7 +1981,6 @@
     },
     "dialog": {
       "title": "Update NetPulse",
-      "desc": "The update runs in several steps and takes a few minutes.",
       "start": "Update now",
       "cancel": "Cancel",
       "close": "Close",
@@ -1998,7 +1997,6 @@
       "changelogLink": "View release notes on GitHub",
       "downNotice": "The service will be down while it restarts",
       "versionUpdate": "Version update",
-      "eta": "Estimated time: 2-5 minutes",
       "backupNote": "A backup will be created automatically before the update",
       "prerequisites": "Prerequisites",
       "ack": "I understand the service will be briefly unavailable during the update"

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

@@ -1981,7 +1981,6 @@
     },
     "dialog": {
       "title": "Actualizar NetPulse",
-      "desc": "La actualización se aplica en varios pasos y tarda unos minutos.",
       "start": "Actualizar ahora",
       "cancel": "Cancelar",
       "close": "Cerrar",
@@ -1998,7 +1997,6 @@
       "changelogLink": "Ver notas del release en GitHub",
       "downNotice": "El servicio estará caído mientras se reinicia",
       "versionUpdate": "Actualización de versión",
-      "eta": "Tiempo estimado: 2-5 minutos",
       "backupNote": "Se creará una copia de seguridad automática antes de actualizar",
       "prerequisites": "Prerrequisitos",
       "ack": "Entiendo que el servicio quedará no disponible brevemente durante la actualización"

+ 44 - 18
app/src/components/UpdateDialog.tsx

@@ -12,8 +12,9 @@ import {
   ArrowRight,
   Check,
   CheckCircle2,
+  ChevronDown,
+  ChevronUp,
   Circle,
-  Clock,
   DownloadCloud,
   ExternalLink,
   Loader2,
@@ -21,7 +22,6 @@ import {
 import {
   Dialog,
   DialogContent,
-  DialogDescription,
   DialogFooter,
   DialogHeader,
   DialogTitle,
@@ -41,6 +41,9 @@ export interface UpdateCommit {
 export interface UpdateStatusInfo {
   current: string
   latest: string | null
+  /** Semver legible (#1222): versión del binario y del último release. */
+  currentVersion?: string
+  latestVersion?: string
   latestMsg: string | null
   /** Cuerpo del commit (rolling) o notas del release (estable): changelog. */
   latestBody?: string | null
@@ -114,6 +117,7 @@ export function UpdateDialog({ open, onOpenChange, initialStatus }: UpdateDialog
   // Confirmación explícita de la caída del servicio (patrón Pulse): sin
   // marcarla, el botón de actualizar no se habilita.
   const [ackDowntime, setAckDowntime] = useState(false)
+  const [showPrereq, setShowPrereq] = useState(false)
 
   const esRef = useRef<EventSource | null>(null)
   const pollRef = useRef<number | null>(null)
@@ -349,29 +353,37 @@ export function UpdateDialog({ open, onOpenChange, initialStatus }: UpdateDialog
             <DownloadCloud className="h-5 w-5 text-accent" strokeWidth={1.75} aria-hidden="true" />
             {t('update.dialog.title')}
           </DialogTitle>
-          {phase === 'confirm' && <DialogDescription>{t('update.dialog.desc')}</DialogDescription>}
         </DialogHeader>
 
         {phase === 'confirm' && (
           <div className="flex flex-col gap-4 flex-1 min-h-0 overflow-y-auto">
-            {/* Tarjeta de versión destacada (estilo Pulse) */}
+            {/* Tarjeta de versión destacada (estilo Pulse): versionado real
+                (#1222) con el commit/hash como detalle secundario. */}
             <div className="flex flex-col gap-1.5">
               <p className="text-xs font-semibold uppercase tracking-wider text-text-muted">
                 {t('update.dialog.versionUpdate')}
               </p>
               <div className="flex items-center justify-center gap-4 rounded-xl border border-accent/40 bg-accent-soft px-4 py-3.5">
-                <span className="font-mono text-base text-text-secondary">{status?.current ?? '—'}</span>
+                <div className="flex flex-col items-center">
+                  <span className="text-base font-semibold text-text-secondary">
+                    {status?.currentVersion || status?.current || '—'}
+                  </span>
+                  {status?.currentVersion && status.currentVersion !== status.current && (
+                    <span className="font-mono text-xs text-text-muted">{status.current}</span>
+                  )}
+                </div>
                 <ArrowRight className="h-4 w-4 text-text-muted" strokeWidth={1.75} aria-hidden="true" />
-                <span className="font-mono text-base font-semibold text-accent">
-                  {status?.latest ?? '—'}
-                </span>
+                <div className="flex flex-col items-center">
+                  <span className="text-base font-semibold text-accent">
+                    {status?.latestVersion || status?.latest || '—'}
+                  </span>
+                  {status?.latest && (!status.latestVersion || status.latestVersion !== status.latest) && (
+                    <span className="font-mono text-xs text-text-muted">{status.latest}</span>
+                  )}
+                </div>
               </div>
             </div>
             <div className="flex flex-col gap-1.5 text-caption">
-              <span className="flex items-center gap-2 text-text-secondary">
-                <Clock className="h-3.5 w-3.5 shrink-0 text-text-muted" strokeWidth={1.75} aria-hidden="true" />
-                {t('update.dialog.eta')}
-              </span>
               <span className="flex items-center gap-2 text-ok">
                 <CheckCircle2 className="h-3.5 w-3.5 shrink-0" strokeWidth={1.75} aria-hidden="true" />
                 {t('update.dialog.backupNote')}
@@ -398,7 +410,7 @@ export function UpdateDialog({ open, onOpenChange, initialStatus }: UpdateDialog
                     {status!.commits!.map((c) => (
                       <li
                         key={c.sha + c.subject}
-                        className="flex items-start gap-2 text-caption leading-snug text-text-secondary"
+                        className="flex items-start gap-2 text-sm leading-relaxed text-text-secondary"
                       >
                         <span className="shrink-0 font-mono text-text-muted">{c.sha}</span>
                         <span className="min-w-0 break-words">{c.subject}</span>
@@ -427,7 +439,7 @@ export function UpdateDialog({ open, onOpenChange, initialStatus }: UpdateDialog
                 <div className="max-h-44 overflow-y-auto rounded-xl border border-border bg-surface px-3.5 py-2.5 md:max-h-none md:flex-1 md:min-h-0">
                   <ul className="flex flex-col gap-1">
                     {changelogLines.map((l, i) => (
-                        <li key={i} className="flex items-start gap-2 text-caption leading-snug text-text-secondary">
+                        <li key={i} className="flex items-start gap-2 text-sm leading-relaxed text-text-secondary">
                           <span className="mt-1 h-1 w-1 shrink-0 rounded-full bg-text-muted/60" aria-hidden="true" />
                           {l.replace(/^[-*]\s+/, '')}
                         </li>
@@ -466,10 +478,24 @@ export function UpdateDialog({ open, onOpenChange, initialStatus }: UpdateDialog
             )}
             {status?.readiness && (
               <div className="flex flex-col gap-1.5">
-                <p className="text-xs font-semibold uppercase tracking-wider text-text-muted">
-                  {t('update.dialog.prerequisites')}
-                </p>
-                <ReadinessPanel readiness={status.readiness} compact />
+                {/* #1222: prerrequisitos plegados por defecto; la atención va
+                    a las novedades. */}
+                <button
+                  type="button"
+                  onClick={() => setShowPrereq((v) => !v)}
+                  aria-expanded={showPrereq}
+                  className="flex items-center justify-between rounded-lg border border-border px-3 py-2 transition-colors hover:bg-hover"
+                >
+                  <span className="text-xs font-semibold uppercase tracking-wider text-text-muted">
+                    {t('update.dialog.prerequisites')}
+                  </span>
+                  {showPrereq ? (
+                    <ChevronUp className="h-4 w-4 text-text-muted" strokeWidth={1.75} aria-hidden="true" />
+                  ) : (
+                    <ChevronDown className="h-4 w-4 text-text-muted" strokeWidth={1.75} aria-hidden="true" />
+                  )}
+                </button>
+                {showPrereq && <ReadinessPanel readiness={status.readiness} compact />}
               </div>
             )}
             {/* Aviso downtime (caja ámbar) + confirmación por separado */}

+ 26 - 2
server-go/internal/updater/updater.go

@@ -74,8 +74,13 @@ const stepDefaultWeight = 50
 // updater.js): updating es false | {step, progress 0-100}; lastLog son los
 // últimos 800 chars.
 type Status struct {
-	Current         string  `json:"current"`
-	Latest          *string `json:"latest"`
+	Current string  `json:"current"`
+	Latest  *string `json:"latest"`
+	// CurrentVersion/LatestVersion (#1222): semver legible (sin prefijo v)
+	// para la tarjeta de versión de la UI. LatestVersion puede ir vacío en
+	// rolling si la consulta del último release falló.
+	CurrentVersion  string  `json:"currentVersion"`
+	LatestVersion   string  `json:"latestVersion,omitempty"`
 	LatestMsg       *string `json:"latestMsg"`
 	UpdateAvailable bool    `json:"updateAvailable"`
 	CanApply        bool    `json:"canApply"`
@@ -129,6 +134,12 @@ type Updater struct {
 	latest     *string
 	latestMsg  *string
 	latestBody *string // cuerpo del commit/notas del release (changelog #280)
+	// currentVersion/latestVersion (#1222): semver legible del binario en
+	// marcha y del último release publicado. En rolling current es el hash
+	// corto (gitShort) y latest el sha de main: la UI muestra estos semver
+	// en la tarjeta de versión con el hash como detalle secundario.
+	currentVersion string
+	latestVersion  string
 	// compare de GitHub cacheado (issue #490): commits current→latest y
 	// clave "current|latest" del último fetch para no repetir la consulta.
 	commits      []CommitRef
@@ -471,6 +482,8 @@ func parseSemver(s string) [3]int {
 func (u *Updater) Check(ctx context.Context) Status {
 	var current, latest, latestMsg, latestBody, errCode string
 	var latestSHA string
+	currentVersion := u.version
+	var latestVersion string
 
 	if u.mode == "stable" {
 		current = u.version
@@ -478,12 +491,19 @@ func (u *Updater) Check(ctx context.Context) Status {
 			current = "desconocido"
 		}
 		latest, latestMsg, latestBody, errCode = u.fetchLatestRelease(ctx)
+		latestVersion = strings.TrimPrefix(latest, "v")
 	} else {
 		current = gitShort(u.repoRoot)
 		if current == "" {
 			current = "desconocido"
 		}
 		latest, latestSHA, latestMsg, latestBody, errCode = u.fetchLatestCommit(ctx)
+		// #1222: el versionado real público en rolling es el tag del último
+		// release (main puede ir por delante). Fallo -> se queda vacío y la
+		// UI cae al sha.
+		if tag, _, _, relErr := u.fetchLatestRelease(ctx); relErr == "" {
+			latestVersion = strings.TrimPrefix(tag, "v")
+		}
 		// Issue #404: si el body del commit está vacío, intentar usar las
 		// notas del release asociado a ese commit (rolling en CTs reales).
 		if errCode == "" && latestBody == "" && latestSHA != "" {
@@ -523,6 +543,8 @@ func (u *Updater) Check(ctx context.Context) Status {
 	u.mu.Lock()
 	defer u.mu.Unlock()
 	u.current = current
+	u.currentVersion = currentVersion
+	u.latestVersion = latestVersion
 	u.lastCheck = &now
 	if errCode != "" {
 		u.err = &errCode
@@ -849,6 +871,8 @@ func (u *Updater) statusLocked() Status {
 	return Status{
 		Current:         u.current,
 		Latest:          u.latest,
+		CurrentVersion:  u.currentVersion,
+		LatestVersion:   u.latestVersion,
 		LatestMsg:       u.latestMsg,
 		LatestBody:      u.latestBody,
 		Commits:         u.commits,

+ 9 - 0
server-go/internal/updater/updater_compare_test.go

@@ -33,6 +33,9 @@ func TestCheckFetchesCompareCommits(t *testing.T) {
 		case strings.HasPrefix(r.URL.Path, "/repos/owner/netpulse/compare/"):
 			w.Header().Set("Content-Type", "application/json")
 			fmt.Fprint(w, compareBody)
+		case r.URL.Path == "/repos/owner/netpulse/releases/latest":
+			w.Header().Set("Content-Type", "application/json")
+			fmt.Fprint(w, `{"tag_name":"v2.5.0"}`)
 		default:
 			t.Errorf("path inesperado: %s", r.URL.Path)
 		}
@@ -102,6 +105,9 @@ func TestCheckCompareFailureTolerated(t *testing.T) {
 		case r.URL.Path == "/repos/owner/netpulse/releases":
 			// #404: body no vacío en el mock → no llega aquí, pero por si acaso.
 			fmt.Fprint(w, `[]`)
+		case r.URL.Path == "/repos/owner/netpulse/releases/latest":
+			w.Header().Set("Content-Type", "application/json")
+			fmt.Fprint(w, `{"tag_name":"v2.5.0"}`)
 		default:
 			t.Errorf("path inesperado: %s", r.URL.Path)
 		}
@@ -133,6 +139,9 @@ func TestCheckCompareCachedPerPair(t *testing.T) {
 			compareCalls++
 			w.Header().Set("Content-Type", "application/json")
 			fmt.Fprint(w, compareBody)
+		case r.URL.Path == "/repos/owner/netpulse/releases/latest":
+			w.Header().Set("Content-Type", "application/json")
+			fmt.Fprint(w, `{"tag_name":"v2.5.0"}`)
 		default:
 			t.Errorf("path inesperado: %s", r.URL.Path)
 		}

+ 17 - 11
server-go/internal/updater/updater_test.go

@@ -36,19 +36,22 @@ func TestCheckUpdateAvailable(t *testing.T) {
 		switch r.URL.Path {
 		case "/repos/owner/netpulse/commits/main":
 			w.Header().Set("Content-Type", "application/json")
-		fmt.Fprint(w, `{"sha":"abc1234deadbeef","commit":{"message":"feat: algo\n\nbody"}}`)
-	case "/repos/owner/netpulse/releases":
-		w.Header().Set("Content-Type", "application/json")
-		fmt.Fprint(w, `[]`)
-	default:
-		// Compare del changelog (issue #490): cualquier path /compare/.
-		if strings.Contains(r.URL.Path, "/compare/") {
+			fmt.Fprint(w, `{"sha":"abc1234deadbeef","commit":{"message":"feat: algo\n\nbody"}}`)
+		case "/repos/owner/netpulse/releases":
 			w.Header().Set("Content-Type", "application/json")
-			fmt.Fprint(w, `{"commits":[{"sha":"abc1234deadbeef","commit":{"message":"feat: algo"}}]}`)
-			return
+			fmt.Fprint(w, `[]`)
+		case "/repos/owner/netpulse/releases/latest":
+			w.Header().Set("Content-Type", "application/json")
+			fmt.Fprint(w, `{"tag_name":"v2.5.0"}`)
+		default:
+			// Compare del changelog (issue #490): cualquier path /compare/.
+			if strings.Contains(r.URL.Path, "/compare/") {
+				w.Header().Set("Content-Type", "application/json")
+				fmt.Fprint(w, `{"commits":[{"sha":"abc1234deadbeef","commit":{"message":"feat: algo"}}]}`)
+				return
+			}
+			t.Errorf("path: %s", r.URL.Path)
 		}
-		t.Errorf("path: %s", r.URL.Path)
-	}
 	})
 	// repoRoot con git válido (commit distinto) para updateAvailable.
 	// deploy/update.sh → modo rolling (compara contra main HEAD).
@@ -95,6 +98,9 @@ func TestCheckUsesReleaseBodyWhenCommitBodyEmpty(t *testing.T) {
 		case "/repos/owner/netpulse/releases":
 			w.Header().Set("Content-Type", "application/json")
 			fmt.Fprint(w, `[{"body":"Release notes line 1\nRelease notes line 2","target_commitish":"deadbeefabc1234"}]`)
+		case "/repos/owner/netpulse/releases/latest":
+			w.Header().Set("Content-Type", "application/json")
+			fmt.Fprint(w, `{"tag_name":"v2.5.0"}`)
 		default:
 			// Compare del changelog (issue #490).
 			if strings.Contains(r.URL.Path, "/compare/") {