diff --git a/.gitignore b/.gitignore
index 0915329..9302638 100644
--- a/.gitignore
+++ b/.gitignore
@@ -45,4 +45,6 @@ core
# Ejecuciones escritas por RunLog. El jsonl es la fuente de verdad en la maquina
# que lo produce, no algo que se versione: son datos, no codigo.
-runs/
+# Anclado a la raiz: sin la barra inicial ignoraba CUALQUIER carpeta llamada `runs`, y se
+# tragaba en silencio las rutas del front (frontend/app/runs/[id]) y sus clientes.
+/runs/
diff --git a/frontend/app/not-found.tsx b/frontend/app/not-found.tsx
new file mode 100644
index 0000000..6cc6d09
--- /dev/null
+++ b/frontend/app/not-found.tsx
@@ -0,0 +1,12 @@
+import Link from "next/link";
+import { Notice } from "@/components/molecules";
+import { routes } from "@/lib/routes";
+
+/** Cualquier URL que no existe, con la interfaz de la app en vez de la página por defecto. */
+export default function NotFound() {
+ return (
+
+ Revisa la dirección, o vuelve a Ejecuciones.
+
+ );
+}
diff --git a/frontend/app/runs/[id]/[seed]/page.tsx b/frontend/app/runs/[id]/[seed]/page.tsx
new file mode 100644
index 0000000..3e4f373
--- /dev/null
+++ b/frontend/app/runs/[id]/[seed]/page.tsx
@@ -0,0 +1,12 @@
+import { notFound } from "next/navigation";
+import { RunDetailScreen } from "@/components/screens/RunDetailScreen";
+import { isUuid } from "@/lib/routes";
+
+/** Detalle de una ejecución, en el episodio de una semilla. */
+export default async function Page({ params }: PageProps<"/runs/[id]/[seed]">) {
+ const { id, seed } = await params;
+ const n = Number(seed);
+ // Un id es un UUID y una semilla, un entero: si no, es una URL que no existe.
+ if (!isUuid(id) || !Number.isInteger(n)) notFound();
+ return ;
+}
diff --git a/frontend/app/runs/[id]/page.tsx b/frontend/app/runs/[id]/page.tsx
new file mode 100644
index 0000000..3d2e15e
--- /dev/null
+++ b/frontend/app/runs/[id]/page.tsx
@@ -0,0 +1,10 @@
+import { notFound } from "next/navigation";
+import { RunDetailScreen } from "@/components/screens/RunDetailScreen";
+import { isUuid } from "@/lib/routes";
+
+/** Detalle de una ejecución, en su último episodio. */
+export default async function Page({ params }: PageProps<"/runs/[id]">) {
+ const { id } = await params;
+ if (!isUuid(id)) notFound();
+ return ;
+}
diff --git a/frontend/components/atoms/Icon/Icon.tsx b/frontend/components/atoms/Icon/Icon.tsx
index e7b48d4..444d4cd 100644
--- a/frontend/components/atoms/Icon/Icon.tsx
+++ b/frontend/components/atoms/Icon/Icon.tsx
@@ -1,6 +1,6 @@
import type { ReactNode } from "react";
-export type IconName = "check" | "arrowDown" | "crosshair" | "circleDot" | "wave" | "x" | "flag" | "chevronsUpDown" | "sun" | "moon";
+export type IconName = "check" | "arrowDown" | "crosshair" | "circleDot" | "wave" | "x" | "flag" | "chevronsUpDown" | "sun" | "moon" | "chevronLeft" | "chevronRight" | "arrowLeft";
/* Trazos de 16×16. Iconos de línea, sin relleno: ninguno lleva color propio, heredan
`currentColor` del que los use. */
@@ -15,6 +15,9 @@ const PATHS: Record = {
chevronsUpDown: ,
sun: (<>>),
moon: ,
+ chevronLeft: ,
+ chevronRight: ,
+ arrowLeft: ,
};
/** Decorativo: el significado lo lleva el texto de al lado, no el icono. */
diff --git a/frontend/components/molecules/ThemeToggle/ThemeToggle.module.css b/frontend/components/atoms/IconButton/IconButton.module.css
similarity index 58%
rename from frontend/components/molecules/ThemeToggle/ThemeToggle.module.css
rename to frontend/components/atoms/IconButton/IconButton.module.css
index 1deb729..1989e9e 100644
--- a/frontend/components/molecules/ThemeToggle/ThemeToggle.module.css
+++ b/frontend/components/atoms/IconButton/IconButton.module.css
@@ -1,6 +1,7 @@
-.toggle {
+.button {
width: 40px;
height: 40px;
+ flex-shrink: 0;
display: inline-flex;
align-items: center;
justify-content: center;
@@ -9,4 +10,5 @@
border: 1px solid var(--border);
background: var(--surface);
}
-.toggle:hover { background: var(--row-hover); color: var(--text); }
+.button:hover:not(:disabled) { background: var(--row-hover); color: var(--text); }
+.button:disabled { cursor: not-allowed; opacity: 0.4; }
diff --git a/frontend/components/atoms/IconButton/IconButton.tsx b/frontend/components/atoms/IconButton/IconButton.tsx
new file mode 100644
index 0000000..9b12dd5
--- /dev/null
+++ b/frontend/components/atoms/IconButton/IconButton.tsx
@@ -0,0 +1,21 @@
+import { Icon, type IconName } from "../Icon";
+import styles from "./IconButton.module.css";
+
+type Props = {
+ icon: IconName;
+ /** Lo que hace: es el nombre accesible y el aviso al pasar el ratón. Un botón sin texto
+ * visible no puede quedarse sin él. */
+ label: string;
+ onClick?: () => void;
+ disabled?: boolean;
+};
+
+/** Botón redondo con solo un icono. */
+export function IconButton({ icon, label, onClick, disabled }: Props) {
+ return (
+
+ );
+}
diff --git a/frontend/components/atoms/IconButton/index.ts b/frontend/components/atoms/IconButton/index.ts
new file mode 100644
index 0000000..c62ce98
--- /dev/null
+++ b/frontend/components/atoms/IconButton/index.ts
@@ -0,0 +1 @@
+export { IconButton } from "./IconButton";
diff --git a/frontend/components/atoms/index.ts b/frontend/components/atoms/index.ts
index 07a6eab..9f1d842 100644
--- a/frontend/components/atoms/index.ts
+++ b/frontend/components/atoms/index.ts
@@ -21,3 +21,4 @@ export { Swatch } from "./Swatch";
export { Table, Th, Td, Tr } from "./Table";
export { Sparkline } from "./Sparkline";
export { Logo } from "./Logo";
+export { IconButton } from "./IconButton";
diff --git a/frontend/components/molecules/EpisodePicker/EpisodePicker.module.css b/frontend/components/molecules/EpisodePicker/EpisodePicker.module.css
new file mode 100644
index 0000000..ae651bb
--- /dev/null
+++ b/frontend/components/molecules/EpisodePicker/EpisodePicker.module.css
@@ -0,0 +1 @@
+.picker { display: inline-flex; align-items: center; gap: 8px; }
diff --git a/frontend/components/molecules/EpisodePicker/EpisodePicker.tsx b/frontend/components/molecules/EpisodePicker/EpisodePicker.tsx
new file mode 100644
index 0000000..0495372
--- /dev/null
+++ b/frontend/components/molecules/EpisodePicker/EpisodePicker.tsx
@@ -0,0 +1,29 @@
+import { IconButton, Select, Text, type SelectOption } from "../../atoms";
+import styles from "./EpisodePicker.module.css";
+
+type Props = {
+ options: SelectOption[];
+ value: string;
+ onChange: (value: string) => void;
+ /** Sin manejador, el botón queda bloqueado (primer o último episodio). */
+ onPrev?: () => void;
+ onNext?: () => void;
+ /** «3 / 25»: dónde está el elegido dentro de la ejecución. */
+ counter?: string;
+};
+
+/** Elige el episodio (la semilla) que se mira dentro de una ejecución: anterior, lista y
+ * siguiente. */
+export function EpisodePicker({ options, value, onChange, onPrev, onNext, counter }: Props) {
+ return (
+
+ Episodio
+
+
+
+ {counter && {counter}}
+
+ );
+}
diff --git a/frontend/components/molecules/EpisodePicker/index.ts b/frontend/components/molecules/EpisodePicker/index.ts
new file mode 100644
index 0000000..b6d7303
--- /dev/null
+++ b/frontend/components/molecules/EpisodePicker/index.ts
@@ -0,0 +1 @@
+export { EpisodePicker } from "./EpisodePicker";
diff --git a/frontend/components/molecules/ResultCard/ResultCard.tsx b/frontend/components/molecules/ResultCard/ResultCard.tsx
index 64e6199..d26d02a 100644
--- a/frontend/components/molecules/ResultCard/ResultCard.tsx
+++ b/frontend/components/molecules/ResultCard/ResultCard.tsx
@@ -6,17 +6,18 @@ type Props = {
state: "ok" | "bad";
title: string;
description: string;
- href: string;
- linkLabel: string;
+ /** Sin enlace cuando ya se está en el detalle. */
+ href?: string;
+ linkLabel?: string;
};
-/** Cómo acabó un episodio y a dónde ir a verlo con detalle. */
+/** Cómo acabó un episodio y, si procede, a dónde ir a verlo con detalle. */
export function ResultCard({ state, title, description, href, linkLabel }: Props) {
return (
{title}{description}
- {linkLabel}
+ {href && linkLabel && {linkLabel}}
);
}
diff --git a/frontend/components/molecules/ThemeToggle/ThemeToggle.tsx b/frontend/components/molecules/ThemeToggle/ThemeToggle.tsx
index 85feff1..743a9eb 100644
--- a/frontend/components/molecules/ThemeToggle/ThemeToggle.tsx
+++ b/frontend/components/molecules/ThemeToggle/ThemeToggle.tsx
@@ -1,5 +1,4 @@
-import { Icon } from "../../atoms";
-import styles from "./ThemeToggle.module.css";
+import { IconButton } from "../../atoms";
/** Cambia entre tema claro y oscuro. Enseña el icono del tema al que llevaría. */
export function ThemeToggle({ theme, onToggle }: {
@@ -7,9 +6,7 @@ export function ThemeToggle({ theme, onToggle }: {
}) {
const next = theme === "dark" ? "claro" : "oscuro";
return (
-
+
);
}
diff --git a/frontend/components/molecules/index.ts b/frontend/components/molecules/index.ts
index 04bd3b1..b351d99 100644
--- a/frontend/components/molecules/index.ts
+++ b/frontend/components/molecules/index.ts
@@ -19,3 +19,4 @@ export { ColorLegendItem } from "./ColorLegendItem";
export { ToggleField } from "./ToggleField";
export { NavTab } from "./NavTab";
export { ThemeToggle } from "./ThemeToggle";
+export { EpisodePicker } from "./EpisodePicker";
diff --git a/frontend/components/organisms/EpisodeDashboard/EpisodeDashboard.helper.ts b/frontend/components/organisms/EpisodeDashboard/EpisodeDashboard.helper.ts
new file mode 100644
index 0000000..6d3c5f0
--- /dev/null
+++ b/frontend/components/organisms/EpisodeDashboard/EpisodeDashboard.helper.ts
@@ -0,0 +1,103 @@
+import type { Episode, PalletState, Placement, RunEvent } from "@/lib/supabase";
+import type { PalletSize } from "@/lib/pallet";
+import { failureText, mm, palletSize, seconds, signedMm } from "@/lib/ui";
+import { routes } from "@/lib/routes";
+import { buildIdentity, type IdentityMode, type IdentityView } from "../IdentityBar";
+import { buildKpis, type KpiItem } from "../KpiGrid";
+
+export type ResultView = {
+ state: "ok" | "bad";
+ title: string;
+ description: string;
+ href?: string;
+ linkLabel?: string;
+};
+
+/** Todo lo que pinta el cuadro de un episodio, ya resuelto. Lo comparten Live (el último
+ * episodio) y el detalle de una ejecución (un episodio concreto): el componente no sabe de
+ * cuál de las dos viene. */
+export type EpisodeView = {
+ identity: IdentityView;
+ kpis: KpiItem[];
+ result: ResultView | null;
+ placements: Placement[];
+ last: PalletState | null;
+ events: RunEvent[];
+ palletSize: PalletSize;
+ sideNote: string;
+ feedNote: string | undefined;
+};
+
+/** El último estado del palé por `after_seq`, no por orden de llegada. */
+export function lastPalletState(states: PalletState[]): PalletState | null {
+ return states.reduce(
+ (last, s) => (!last || s.after_seq > last.after_seq ? s : last), null);
+}
+
+/** Nota de la cabecera del alzado, con lo que el endpoint da: «4 capas · 400 mm de carga». */
+export function sideViewNote(episode: Episode, last: PalletState | null): string {
+ return [
+ episode.n_layers ? `${episode.n_layers} capas` : null,
+ episode.load_height_m ? `${mm(episode.load_height_m, 0)} de carga` : null,
+ last?.settle_drift_m ? `deriva ${mm(last.settle_drift_m, 0)}` : null,
+ ].filter(Boolean).join(" · ");
+}
+
+export function feedNote(episode: Episode): string | undefined {
+ return episode.status === "running"
+ ? undefined
+ : `episodio terminado · semilla ${episode.seed}`;
+}
+
+/** Cómo acabó, para la tarjeta de resultado. En curso no hay resultado que enseñar. Con
+ * `link`, la tarjeta lleva al detalle del episodio; en el propio detalle no tiene sentido. */
+export function resultOf(episode: Episode, link = true): ResultView | null {
+ const to = link
+ ? { href: routes.episode(episode.run_id, episode.seed) }
+ : {};
+ if (episode.status === "failure") {
+ return {
+ state: "bad",
+ title: failureText(episode.failure),
+ description: `${episode.n_placed} de ${episode.n_objects} paquetes colocados · margen final ${signedMm(episode.final_stability_m)}`,
+ ...to,
+ ...(link && { linkLabel: "Ver episodio →" }),
+ };
+ }
+ if (episode.status === "success") {
+ return {
+ state: "ok",
+ title: "Episodio completado",
+ description: `${seconds(episode.duration_s)} · ${episode.n_placed} de ${episode.n_objects} paquetes · sin derrumbe`,
+ ...to,
+ ...(link && { linkLabel: "Ver detalle →" }),
+ };
+ }
+ return null;
+}
+
+/** De un episodio y sus datos de detalle al modelo que pinta el cuadro. */
+export function buildEpisodeView(input: {
+ episode: Episode;
+ placements: Placement[];
+ states: PalletState[];
+ events: RunEvent[];
+ /** Los episodios de su ejecución, para el «3 / 25». */
+ runEpisodes: Episode[];
+ stale: boolean;
+ mode: IdentityMode;
+}): EpisodeView {
+ const { episode, placements, states, events, runEpisodes, stale, mode } = input;
+ const last = lastPalletState(states);
+ return {
+ identity: buildIdentity({ episode, runEpisodes, events, stale, mode }),
+ kpis: buildKpis(episode, last, placements),
+ result: resultOf(episode, mode === "live"),
+ placements, last, events,
+ // El palé puede ser una maqueta a escala: sin esto se dibuja a 1200x800
+ // y todas las cotas salen mal por el mismo factor.
+ palletSize: palletSize(episode),
+ sideNote: sideViewNote(episode, last),
+ feedNote: feedNote(episode),
+ };
+}
diff --git a/frontend/components/screens/LiveScreen/LiveScreen.module.css b/frontend/components/organisms/EpisodeDashboard/EpisodeDashboard.module.css
similarity index 100%
rename from frontend/components/screens/LiveScreen/LiveScreen.module.css
rename to frontend/components/organisms/EpisodeDashboard/EpisodeDashboard.module.css
diff --git a/frontend/components/organisms/EpisodeDashboard/EpisodeDashboard.tsx b/frontend/components/organisms/EpisodeDashboard/EpisodeDashboard.tsx
new file mode 100644
index 0000000..adf3b70
--- /dev/null
+++ b/frontend/components/organisms/EpisodeDashboard/EpisodeDashboard.tsx
@@ -0,0 +1,63 @@
+import type { ReactNode } from "react";
+import { Text } from "../../atoms";
+import { LegendItem, ResultCard } from "../../molecules";
+import { EventFeed } from "../EventFeed";
+import { IdentityBar } from "../IdentityBar";
+import { KpiGrid } from "../KpiGrid";
+import { PalletSideView } from "../PalletSideView";
+import { PalletTopView } from "../PalletTopView";
+import { Panel } from "../Panel";
+import type { EpisodeView } from "./EpisodeDashboard.helper";
+import styles from "./EpisodeDashboard.module.css";
+
+type Props = {
+ view: EpisodeView;
+ /** Encima de la identidad del episodio: en el detalle, el «← Ejecuciones» y el nombre. */
+ header?: ReactNode;
+ /** Debajo de la identidad: un aviso a todo el ancho (conexión perdida). */
+ banner?: ReactNode;
+ /** Sustituye al «3 / 25» de la identidad (el selector de episodio del detalle). */
+ picker?: ReactNode;
+};
+
+/** El cuadro de un episodio: identidad, vista cenital, alzado, indicadores y feed de
+ * eventos. Es la pantalla de Live y también la del detalle de una ejecución; cambia de
+ * dónde salen los datos, no cómo se ven. */
+export function EpisodeDashboard({ view, header, banner, picker }: Props) {
+ return (
+
+ {header}
+
+ {banner}
+
+
+
+
+
+
+
+ >}
+ >
+
+
+ {view.sideNote}}
+ >
+
+
+
+
+
+
+ {view.result && }
+
+
+
+
+ );
+}
diff --git a/frontend/components/organisms/EpisodeDashboard/index.ts b/frontend/components/organisms/EpisodeDashboard/index.ts
new file mode 100644
index 0000000..b5e6a8c
--- /dev/null
+++ b/frontend/components/organisms/EpisodeDashboard/index.ts
@@ -0,0 +1,3 @@
+export { EpisodeDashboard } from "./EpisodeDashboard";
+export { buildEpisodeView } from "./EpisodeDashboard.helper";
+export type { EpisodeView, ResultView } from "./EpisodeDashboard.helper";
diff --git a/frontend/components/organisms/IdentityBar/IdentityBar.helper.ts b/frontend/components/organisms/IdentityBar/IdentityBar.helper.ts
index 896b6e6..649c863 100644
--- a/frontend/components/organisms/IdentityBar/IdentityBar.helper.ts
+++ b/frontend/components/organisms/IdentityBar/IdentityBar.helper.ts
@@ -13,8 +13,20 @@ export type IdentityView = {
clock: { value: string; unit: string };
};
-function statusOf(episode: Episode, stale: boolean): IdentityView["status"] {
+/** `live`: se mira el último episodio de lo que esté corriendo. `run`: se mira un episodio
+ * concreto de una ejecución ya hecha, y el estado dice cómo acabó. */
+export type IdentityMode = "live" | "run";
+
+function statusOf(
+ episode: Episode, stale: boolean, mode: IdentityMode,
+): IdentityView["status"] {
if (stale) return { label: "Sin datos nuevos", tone: "warn", pulse: false };
+ if (mode === "run") {
+ if (episode.status === "running") return { label: "En curso", tone: "light", pulse: false };
+ return episode.status === "success"
+ ? { label: "Completado", tone: "ok", pulse: false }
+ : { label: "Fallo", tone: "bad", pulse: false };
+ }
if (episode.status === "running") return { label: "En vivo", tone: "light", pulse: true };
if (episode.status === "success") return { label: "Último", tone: "ok", pulse: false };
return { label: "Último", tone: "muted", pulse: false };
@@ -35,14 +47,16 @@ export function elapsedSeconds(episode: Episode, events: RunEvent[]): number {
export function buildIdentity(input: {
episode: Episode; runEpisodes: Episode[]; events: RunEvent[]; stale: boolean;
+ mode?: IdentityMode;
}): IdentityView {
- const { episode, runEpisodes, events, stale } = input;
+ const { episode, runEpisodes, events, stale, mode = "live" } = input;
return {
- status: statusOf(episode, stale),
+ status: statusOf(episode, stale, mode),
meta: [
{ label: "Tarea", value: TASK_TEXT[episode.task] ?? episode.task, mono: false },
{ label: "Nivel", value: episode.level, mono: true },
- { label: "Semilla", value: episode.seed, mono: true },
+ // En el detalle de una ejecución la semilla ya la dice el selector de episodio.
+ ...(mode === "run" ? [] : [{ label: "Semilla", value: episode.seed, mono: true }]),
{ label: "Commit", value: episode.git_sha || "—", mono: true },
{ label: "Velocidad", value: `x${episode.motion_speed}`, mono: true },
],
diff --git a/frontend/components/organisms/IdentityBar/IdentityBar.tsx b/frontend/components/organisms/IdentityBar/IdentityBar.tsx
index 49b8068..f99e595 100644
--- a/frontend/components/organisms/IdentityBar/IdentityBar.tsx
+++ b/frontend/components/organisms/IdentityBar/IdentityBar.tsx
@@ -1,10 +1,18 @@
+import type { ReactNode } from "react";
import { Badge, Divider, Value } from "../../atoms";
import { MetaItem, StatusIndicator } from "../../molecules";
import type { IdentityView } from "./IdentityBar.helper";
import styles from "./IdentityBar.module.css";
/** Quién es el episodio que se está viendo: estado, tarea, semilla, commit y reloj. */
-export function IdentityBar({ status, meta, oracle, synthetic, counter, clock }: IdentityView) {
+type Props = IdentityView & {
+ /** Sustituye al «3 / 25»: el selector de episodio del detalle de una ejecución. */
+ picker?: ReactNode;
+};
+
+export function IdentityBar({
+ status, meta, oracle, synthetic, counter, clock, picker,
+}: Props) {
return (
@@ -15,7 +23,7 @@ export function IdentityBar({ status, meta, oracle, synthetic, counter, clock }:
{oracle && Oracle}
{synthetic && Sembrado}
- {counter && }
+ {picker ?? (counter && )}
);
diff --git a/frontend/components/organisms/IdentityBar/index.ts b/frontend/components/organisms/IdentityBar/index.ts
index d085f97..e725a8a 100644
--- a/frontend/components/organisms/IdentityBar/index.ts
+++ b/frontend/components/organisms/IdentityBar/index.ts
@@ -1,3 +1,3 @@
export { IdentityBar } from "./IdentityBar";
export { buildIdentity } from "./IdentityBar.helper";
-export type { IdentityView } from "./IdentityBar.helper";
+export type { IdentityView, IdentityMode } from "./IdentityBar.helper";
diff --git a/frontend/components/organisms/RunHeader/RunHeader.helper.ts b/frontend/components/organisms/RunHeader/RunHeader.helper.ts
new file mode 100644
index 0000000..4ca6018
--- /dev/null
+++ b/frontend/components/organisms/RunHeader/RunHeader.helper.ts
@@ -0,0 +1,24 @@
+import type { Run } from "@/lib/supabase";
+import { pct, relativeTime } from "@/lib/ui";
+
+export type RunHeaderView = {
+ /** El commit, que es como se nombra una ejecución en toda la interfaz. */
+ title: string;
+ /** La nota a mano del que la lanzó, si la hay: lo que convierte una lista de commits en
+ * una historia. */
+ note: string | null;
+ /** «25 episodios · 64 % de éxito · hace 2 h». */
+ meta: string;
+};
+
+export function buildRunHeader(run: Run): RunHeaderView {
+ return {
+ title: run.git_sha || run.label || "Ejecución",
+ note: run.description || (run.git_sha ? run.label : null) || null,
+ meta: [
+ `${run.episodes} ${run.episodes === 1 ? "episodio" : "episodios"}`,
+ `${pct(run.success_rate)} de éxito`,
+ relativeTime(run.started_at),
+ ].join(" · "),
+ };
+}
diff --git a/frontend/components/organisms/RunHeader/RunHeader.module.css b/frontend/components/organisms/RunHeader/RunHeader.module.css
new file mode 100644
index 0000000..721a5f6
--- /dev/null
+++ b/frontend/components/organisms/RunHeader/RunHeader.module.css
@@ -0,0 +1,21 @@
+.header {
+ flex-shrink: 0;
+ display: flex;
+ align-items: center;
+ flex-wrap: wrap;
+ gap: 8px 20px;
+ margin: var(--page-gap) var(--page-pad) 0;
+}
+.back {
+ display: inline-flex;
+ align-items: center;
+ gap: 6px;
+ font-size: 13.5px;
+ font-weight: 500;
+ text-decoration: none;
+ color: var(--text-3);
+}
+.back:hover { color: var(--text); }
+.title { display: inline-flex; align-items: baseline; gap: 12px; min-width: 0; }
+.name { font-weight: 600; }
+.spacer { flex-grow: 1; }
diff --git a/frontend/components/organisms/RunHeader/RunHeader.tsx b/frontend/components/organisms/RunHeader/RunHeader.tsx
new file mode 100644
index 0000000..be94e5c
--- /dev/null
+++ b/frontend/components/organisms/RunHeader/RunHeader.tsx
@@ -0,0 +1,26 @@
+import Link from "next/link";
+import { Icon, Text } from "../../atoms";
+import type { RunHeaderView } from "./RunHeader.helper";
+import styles from "./RunHeader.module.css";
+
+type Props = RunHeaderView & {
+ backHref: string;
+ backLabel: string;
+};
+
+/** Cabecera del detalle de una ejecución: cómo volver a la lista y de cuál se trata. */
+export function RunHeader({ backHref, backLabel, title, note, meta }: Props) {
+ return (
+
+ );
+}
diff --git a/frontend/components/organisms/RunHeader/index.ts b/frontend/components/organisms/RunHeader/index.ts
new file mode 100644
index 0000000..538eafa
--- /dev/null
+++ b/frontend/components/organisms/RunHeader/index.ts
@@ -0,0 +1,3 @@
+export { RunHeader } from "./RunHeader";
+export { buildRunHeader } from "./RunHeader.helper";
+export type { RunHeaderView } from "./RunHeader.helper";
diff --git a/frontend/components/organisms/RunRow/RunRow.tsx b/frontend/components/organisms/RunRow/RunRow.tsx
index 1b33689..211db66 100644
--- a/frontend/components/organisms/RunRow/RunRow.tsx
+++ b/frontend/components/organisms/RunRow/RunRow.tsx
@@ -10,9 +10,10 @@ type Props = {
/** No se puede marcar: ya hay dos y esta no es una de ellas. */
selectionBlocked?: boolean;
onToggle: (id: string) => void;
- /** Cuando exista el detalle del run: el commit pasa a enlace. */
+ /** El commit pasa a enlace al detalle (es lo que alcanza el teclado). */
href?: string;
- /** Y la fila entera pulsable. La casilla ya corta la propagación para no disparar esto. */
+ /** Y la fila entera pulsable con el ratón. La casilla y el enlace cortan la propagación
+ * para no disparar esto además de lo suyo. */
onOpen?: () => void;
};
@@ -30,7 +31,7 @@ export function RunRow({ view: v, selected, selectionBlocked, onToggle, href, on
- {href ? {v.commit} : v.commit}
+ {href ? e.stopPropagation()}>{v.commit} : v.commit}
{v.flag && }
diff --git a/frontend/components/organisms/RunsTable/RunsTable.tsx b/frontend/components/organisms/RunsTable/RunsTable.tsx
index 06f4202..923e790 100644
--- a/frontend/components/organisms/RunsTable/RunsTable.tsx
+++ b/frontend/components/organisms/RunsTable/RunsTable.tsx
@@ -11,11 +11,17 @@ type Props = {
/** Ya hay las que se pueden comparar: las casillas sin marcar se bloquean. */
selectionFull: boolean;
onToggle: (id: string) => void;
+ /** A dónde lleva una fila: la URL de su detalle. */
+ hrefFor: (id: string) => string;
+ /** Pulsar la fila (fuera de la casilla y del enlace) abre el detalle. */
+ onOpen: (id: string) => void;
};
-/** La lista de ejecuciones. La selección para comparar va en la primera columna: el resto
- * de la fila queda libre para navegar al detalle. */
-export function RunsTable({ runs, selectedIds, selectionFull, onToggle }: Props) {
+/** La lista de ejecuciones. La selección para comparar va en la primera columna; pulsar el
+ * resto de la fila abre el detalle de esa ejecución. */
+export function RunsTable({
+ runs, selectedIds, selectionFull, onToggle, hrefFor, onOpen,
+}: Props) {
if (!runs.length) {
return (
@@ -47,7 +53,8 @@ export function RunsTable({ runs, selectedIds, selectionFull, onToggle }: Props)
{buildRows(runs, selectedIds).map(({ view, selected }) => (
+ selectionBlocked={selectionFull && !selected} onToggle={onToggle}
+ href={hrefFor(view.id)} onOpen={() => onOpen(view.id)} />
))}
diff --git a/frontend/components/organisms/index.ts b/frontend/components/organisms/index.ts
index 1fa5810..d1a0e60 100644
--- a/frontend/components/organisms/index.ts
+++ b/frontend/components/organisms/index.ts
@@ -14,3 +14,6 @@ export { ComparePanel } from "./ComparePanel";
export type { ComparePair } from "./ComparePanel";
export { RunsTotals } from "./RunsTotals";
export { TopBar } from "./TopBar";
+export { EpisodeDashboard, buildEpisodeView } from "./EpisodeDashboard";
+export type { EpisodeView } from "./EpisodeDashboard";
+export { RunHeader, buildRunHeader } from "./RunHeader";
diff --git a/frontend/components/screens/LiveScreen/LiveScreen.helper.ts b/frontend/components/screens/LiveScreen/LiveScreen.helper.ts
index 0cb04a9..a803fcd 100644
--- a/frontend/components/screens/LiveScreen/LiveScreen.helper.ts
+++ b/frontend/components/screens/LiveScreen/LiveScreen.helper.ts
@@ -1,5 +1,4 @@
-import type { Episode, PalletState } from "@/lib/supabase";
-import { clockTime, failureText, mm, seconds, signedMm } from "@/lib/ui";
+import { clockTime } from "@/lib/ui";
/** Sin nada recibido durante este tiempo, con un episodio en curso, se da la conexión
* por perdida. Generoso a propósito: un aviso en falso durante la demo es peor que
@@ -20,48 +19,3 @@ export function isStale(input: {
export function staleDetail(lastSignalAt: number): string {
return `lo que se ve es el último dato recibido · ${clockTime(new Date(lastSignalAt).toISOString())}`;
}
-
-/** El último estado del palé por `after_seq`, no por orden de llegada. */
-export function lastPalletState(states: PalletState[]): PalletState | null {
- return states.reduce(
- (last, s) => (!last || s.after_seq > last.after_seq ? s : last), null);
-}
-
-/** Nota de la cabecera del alzado, con lo que el endpoint da: «4 capas · 400 mm de carga». */
-export function sideViewNote(episode: Episode, last: PalletState | null): string {
- return [
- episode.n_layers ? `${episode.n_layers} capas` : null,
- episode.load_height_m ? `${mm(episode.load_height_m, 0)} de carga` : null,
- last?.settle_drift_m ? `deriva ${mm(last.settle_drift_m, 0)}` : null,
- ].filter(Boolean).join(" · ");
-}
-
-export function feedNote(episode: Episode): string | undefined {
- return episode.status === "running"
- ? undefined
- : `episodio terminado · semilla ${episode.seed}`;
-}
-
-/** Cómo acabó, para la tarjeta de resultado. En curso no hay resultado que enseñar. */
-export function resultOf(episode: Episode) {
- const href = `/runs/${episode.run_id}/${episode.seed}`;
- if (episode.status === "failure") {
- return {
- state: "bad" as const,
- title: failureText(episode.failure),
- description: `${episode.n_placed} de ${episode.n_objects} paquetes colocados · margen final ${signedMm(episode.final_stability_m)}`,
- href,
- linkLabel: "Ver episodio →",
- };
- }
- if (episode.status === "success") {
- return {
- state: "ok" as const,
- title: "Episodio completado",
- description: `${seconds(episode.duration_s)} · ${episode.n_placed} de ${episode.n_objects} paquetes · sin derrumbe`,
- href,
- linkLabel: "Ver detalle →",
- };
- }
- return null;
-}
diff --git a/frontend/components/screens/LiveScreen/LiveScreen.tsx b/frontend/components/screens/LiveScreen/LiveScreen.tsx
index 1b8064c..7b12098 100644
--- a/frontend/components/screens/LiveScreen/LiveScreen.tsx
+++ b/frontend/components/screens/LiveScreen/LiveScreen.tsx
@@ -1,20 +1,17 @@
"use client";
-import { Button, Text } from "../../atoms";
-import { Banner, LegendItem, Notice, ResultCard } from "../../molecules";
-import {
- EventFeed, IdentityBar, KpiGrid, PalletSideView, PalletTopView, Panel,
-} from "../../organisms";
+import { Button } from "../../atoms";
+import { Banner, Notice } from "../../molecules";
+import { EpisodeDashboard } from "../../organisms";
import { useLiveScreen } from "./useLiveScreen";
-import styles from "./LiveScreen.module.css";
-/** Composición de Live: cada pieza viene hecha, aquí solo se colocan. Live nunca se queda
- * en blanco: sin ejecución enseña el último episodio y, si se pierde la conexión, congela
- * lo último recibido y lo dice. */
+/** Live: el cuadro de un episodio con el último que haya. Nunca se queda en blanco: sin
+ * ejecución enseña el último terminado y, si se pierde la conexión, congela lo último
+ * recibido y lo dice. */
export function LiveScreen() {
- const { state, view, retry, error } = useLiveScreen();
+ const s = useLiveScreen();
- if (state === "unconfigured") {
+ if (s.state === "unconfigured") {
return (
Rellena .env en la raíz del repo con SUPABASE_URL y{" "}
@@ -22,15 +19,15 @@ export function LiveScreen() {
);
}
- if (state === "loading") return Buscando el último episodio.;
- if (state === "error") {
+ if (s.state === "loading") return Buscando el último episodio.;
+ if (s.state === "error") {
return (
- {error}
+ {s.error}
);
}
- if (state === "empty" || !view) {
+ if (s.state === "empty" || !s.view) {
return (
Lanza un benchmark con --telemetry, o siembra un histórico con{" "}
@@ -40,41 +37,12 @@ export function LiveScreen() {
}
return (
-
-
- {view.stale && (
-
+
)}
-
-
-
-
-
-
-
- >}
- >
-
-
- {view.sideNote}}
- >
-
-
-
-
-
-
- {view.result && }
-
-
-
-
+ />
);
}
diff --git a/frontend/components/screens/LiveScreen/useLiveScreen.ts b/frontend/components/screens/LiveScreen/useLiveScreen.ts
index 6ccd2fe..b75ec60 100644
--- a/frontend/components/screens/LiveScreen/useLiveScreen.ts
+++ b/frontend/components/screens/LiveScreen/useLiveScreen.ts
@@ -3,13 +3,9 @@ import {
useEpisodeDetail, useEpisodeRealtime, useEpisodes, useLatestEpisode,
} from "@/api/hooks";
import { configured } from "@/lib/supabase";
-import { palletSize } from "@/lib/ui";
import { useNow } from "@/hooks/useNow";
-import { buildIdentity } from "../../organisms/IdentityBar";
-import { buildKpis } from "../../organisms/KpiGrid";
-import {
- LATEST_POLL_MS, feedNote, isStale, lastPalletState, resultOf, sideViewNote, staleDetail,
-} from "./LiveScreen.helper";
+import { buildEpisodeView } from "../../organisms/EpisodeDashboard";
+import { LATEST_POLL_MS, isStale, staleDetail } from "./LiveScreen.helper";
/** Une los datos de Live en un solo modelo para la pantalla. Aquí no se dibuja nada. */
export function useLiveScreen() {
@@ -34,10 +30,6 @@ export function useLiveScreen() {
error: latest.error?.message };
}
- const placements = detail.placements.data ?? [];
- const states = detail.states.data ?? [];
- const events = detail.events.data ?? [];
- const last = lastPalletState(states);
// Un fallo de red con datos ya en pantalla no vacía nada: se congela y se avisa.
const stale = isStale({
running: Boolean(running), fetchFailed: latest.isError || detail.isError,
@@ -47,20 +39,15 @@ export function useLiveScreen() {
return {
state: "ready" as const,
retry,
- view: {
- stale,
- staleDetail: staleDetail(lastSignalAt),
- identity: buildIdentity({
- episode, runEpisodes: runEpisodes.data ?? [], events, stale,
- }),
- kpis: buildKpis(episode, last, placements),
- result: resultOf(episode),
- placements, last, events,
- // El palé puede ser una maqueta a escala: sin esto se dibuja a 1200x800
- // y todas las cotas salen mal por el mismo factor.
- palletSize: palletSize(episode),
- sideNote: sideViewNote(episode, last),
- feedNote: feedNote(episode),
- },
+ stale,
+ staleDetail: staleDetail(lastSignalAt),
+ view: buildEpisodeView({
+ episode,
+ placements: detail.placements.data ?? [],
+ states: detail.states.data ?? [],
+ events: detail.events.data ?? [],
+ runEpisodes: runEpisodes.data ?? [],
+ stale, mode: "live",
+ }),
};
}
diff --git a/frontend/components/screens/RunDetailScreen/RunDetailScreen.helper.ts b/frontend/components/screens/RunDetailScreen/RunDetailScreen.helper.ts
new file mode 100644
index 0000000..6a6a4e3
--- /dev/null
+++ b/frontend/components/screens/RunDetailScreen/RunDetailScreen.helper.ts
@@ -0,0 +1,32 @@
+import type { Episode } from "@/lib/supabase";
+import type { SelectOption } from "../../atoms";
+
+const STATUS_TEXT: Record = {
+ success: "éxito",
+ failure: "fallo",
+ running: "en curso",
+};
+
+/** El episodio que se mira: el de la semilla pedida, o el último si no se pidió ninguno.
+ * `undefined` si se pidió una semilla que la ejecución no tiene. */
+export function pickEpisode(episodes: Episode[], seed: number | undefined): Episode | undefined {
+ return seed == null ? episodes[episodes.length - 1] : episodes.find((e) => e.seed === seed);
+}
+
+/** Las opciones del selector: la semilla y cómo acabó, para elegir sin ir probando. */
+export function episodeOptions(episodes: Episode[]): SelectOption[] {
+ return episodes.map((e) => ({
+ value: String(e.seed),
+ label: `Semilla ${e.seed} · ${STATUS_TEXT[e.status]}`,
+ }));
+}
+
+/** Las semillas vecinas del episodio elegido, o `undefined` en los extremos. */
+export function neighbours(episodes: Episode[], current: Episode) {
+ const i = episodes.findIndex((e) => e.id === current.id);
+ return {
+ prev: i > 0 ? episodes[i - 1].seed : undefined,
+ next: i >= 0 && i < episodes.length - 1 ? episodes[i + 1].seed : undefined,
+ counter: i >= 0 ? `${i + 1} / ${episodes.length}` : undefined,
+ };
+}
diff --git a/frontend/components/screens/RunDetailScreen/RunDetailScreen.tsx b/frontend/components/screens/RunDetailScreen/RunDetailScreen.tsx
new file mode 100644
index 0000000..49028e0
--- /dev/null
+++ b/frontend/components/screens/RunDetailScreen/RunDetailScreen.tsx
@@ -0,0 +1,61 @@
+"use client";
+
+import Link from "next/link";
+import { routes } from "@/lib/routes";
+import { Button } from "../../atoms";
+import { Banner, EpisodePicker, Notice } from "../../molecules";
+import { EpisodeDashboard, RunHeader } from "../../organisms";
+import { useRunDetailScreen } from "./useRunDetailScreen";
+
+/** Detalle de una ejecución: el mismo cuadro que Live, pero con un episodio concreto de
+ * esa ejecución (por defecto el último) y un selector para recorrer los demás. */
+export function RunDetailScreen({ runId, seed }: { runId: string; seed?: number }) {
+ const s = useRunDetailScreen(runId, seed);
+ const back = Volver a Ejecuciones;
+
+ if (s.state === "unconfigured") {
+ return (
+
+ Rellena .env en la raíz del repo con SUPABASE_URL y{" "}
+ SUPABASE_ANON_KEY.
+
+ );
+ }
+ if (s.state === "loading") return Buscando la ejecución.;
+ if (s.state === "error") {
+ return (
+
+ {s.error}
+
+ );
+ }
+ if (s.state === "notFound") {
+ return {back};
+ }
+ if (s.state === "empty") {
+ return (
+
+ Cuando escriba el primero aparecerá aquí. {back}
+
+ );
+ }
+ if (s.state === "noSeed") {
+ return (
+
+ Ver su último episodio · {back}
+
+ );
+ }
+
+ return (
+ }
+ banner={s.detailFailed && (
+
+ )}
+ picker={}
+ />
+ );
+}
diff --git a/frontend/components/screens/RunDetailScreen/index.ts b/frontend/components/screens/RunDetailScreen/index.ts
new file mode 100644
index 0000000..ee508d7
--- /dev/null
+++ b/frontend/components/screens/RunDetailScreen/index.ts
@@ -0,0 +1 @@
+export { RunDetailScreen } from "./RunDetailScreen";
diff --git a/frontend/components/screens/RunDetailScreen/useRunDetailScreen.ts b/frontend/components/screens/RunDetailScreen/useRunDetailScreen.ts
new file mode 100644
index 0000000..3af75c7
--- /dev/null
+++ b/frontend/components/screens/RunDetailScreen/useRunDetailScreen.ts
@@ -0,0 +1,63 @@
+import { useRouter } from "next/navigation";
+import { useEpisodeDetail, useEpisodes, useRun } from "@/api/hooks";
+import { configured } from "@/lib/supabase";
+import { routes } from "@/lib/routes";
+import { buildEpisodeView } from "../../organisms/EpisodeDashboard";
+import { buildRunHeader } from "../../organisms/RunHeader";
+import { episodeOptions, neighbours, pickEpisode } from "./RunDetailScreen.helper";
+
+/** Une los datos del detalle de una ejecución y la navegación entre sus episodios en un
+ * solo modelo. Aquí no se dibuja nada. */
+export function useRunDetailScreen(runId: string, seed: number | undefined) {
+ const router = useRouter();
+ const run = useRun(runId);
+ const episodes = useEpisodes(runId);
+ const list = episodes.data ?? [];
+ const episode = pickEpisode(list, seed);
+ const detail = useEpisodeDetail(episode?.id);
+
+ const retry = () => {
+ void run.refetch();
+ void episodes.refetch();
+ void detail.placements.refetch();
+ void detail.states.refetch();
+ void detail.events.refetch();
+ };
+
+ if (!configured) return { state: "unconfigured" as const, retry };
+ if (run.isPending || episodes.isPending) return { state: "loading" as const, retry };
+ if (run.isError || episodes.isError) {
+ return { state: "error" as const, retry,
+ error: (run.error ?? episodes.error)?.message };
+ }
+ if (!run.data) return { state: "notFound" as const, retry };
+ if (!list.length) return { state: "empty" as const, retry, header: buildRunHeader(run.data) };
+ if (!episode) return { state: "noSeed" as const, retry, seed, header: buildRunHeader(run.data) };
+
+ const near = neighbours(list, episode);
+ const go = (s: number) => router.push(routes.episode(runId, s));
+
+ return {
+ state: "ready" as const,
+ retry,
+ header: buildRunHeader(run.data),
+ view: buildEpisodeView({
+ episode,
+ placements: detail.placements.data ?? [],
+ states: detail.states.data ?? [],
+ events: detail.events.data ?? [],
+ runEpisodes: list,
+ stale: false,
+ mode: "run",
+ }),
+ detailFailed: detail.isError,
+ picker: {
+ options: episodeOptions(list),
+ value: String(episode.seed),
+ counter: near.counter,
+ onChange: (value: string) => go(Number(value)),
+ onPrev: near.prev == null ? undefined : () => go(near.prev as number),
+ onNext: near.next == null ? undefined : () => go(near.next as number),
+ },
+ };
+}
diff --git a/frontend/components/screens/RunsScreen/RunsScreen.tsx b/frontend/components/screens/RunsScreen/RunsScreen.tsx
index 4ffb456..fa355a6 100644
--- a/frontend/components/screens/RunsScreen/RunsScreen.tsx
+++ b/frontend/components/screens/RunsScreen/RunsScreen.tsx
@@ -43,7 +43,8 @@ export function RunsScreen() {
diff --git a/frontend/components/screens/RunsScreen/useRunsScreen.ts b/frontend/components/screens/RunsScreen/useRunsScreen.ts
index d11313f..206a198 100644
--- a/frontend/components/screens/RunsScreen/useRunsScreen.ts
+++ b/frontend/components/screens/RunsScreen/useRunsScreen.ts
@@ -1,6 +1,8 @@
import { useState } from "react";
+import { useRouter } from "next/navigation";
import { useFailureBreakdown, useRuns } from "@/api/hooks";
import { configured } from "@/lib/supabase";
+import { routes } from "@/lib/routes";
import {
DEFAULT_FILTERS, applyFilters, filterOptions, type RunFilters,
} from "../../organisms/FilterBar";
@@ -11,6 +13,7 @@ const RUN_LIMIT = 200;
/** Une los datos de Ejecuciones y el estado de la pantalla (filtros y selección). */
export function useRunsScreen() {
+ const router = useRouter();
const query = useRuns(RUN_LIMIT);
const runs = query.data ?? [];
@@ -44,5 +47,7 @@ export function useRunsScreen() {
onFilter: (patch: Partial) => setFilters((f) => ({ ...f, ...patch })),
onToggle: (id: string) => setSelectedIds((prev) => toggleSelection(prev, id)),
onClear: () => setSelectedIds([]),
+ hrefFor: routes.run,
+ onOpen: (id: string) => router.push(routes.run(id)),
};
}
diff --git a/frontend/lib/routes.ts b/frontend/lib/routes.ts
new file mode 100644
index 0000000..0f8a0e7
--- /dev/null
+++ b/frontend/lib/routes.ts
@@ -0,0 +1,15 @@
+/** Las rutas de la aplicación, en un solo sitio: quien enlaza no construye la URL a mano. */
+export const routes = {
+ live: "/",
+ runs: "/runs",
+ /** Detalle de una ejecución: por defecto, su último episodio. */
+ run: (runId: string) => `/runs/${runId}`,
+ /** Detalle de una ejecución, en el episodio de esa semilla. */
+ episode: (runId: string, seed: number) => `/runs/${runId}/${seed}`,
+};
+
+const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
+
+/** Un id de ejecución es un UUID. Sin esta comprobación, `/runs/abc` llega a la base, que
+ * responde con un error de sintaxis que no le dice nada a quien escribió mal la URL. */
+export const isUuid = (value: string): boolean => UUID.test(value);