feat(yahweh-widget-stat-card): promover patrón stat card como widget

Iter 15. El patrón "tarjeta de dashboard con border-l accent +
label + value grande + descripción + listing opcional" tenía 2
consumers (minga-explorer + brahman-broker-explorer). Ahora vale
extraer al stack yahweh.

crates/modules/ui_engine/widgets/stat-card/:
- pub fn stat_card(cx, label, value: impl Into<SharedString>,
  description, accent, text, text_dim, recent_items: &[String])
  -> impl IntoElement.
- Compone yahweh-widget-card::card_themed; sin theme directo
  (caller pasa text/text_dim ya resueltos).
- 3 tests #[gpui::test] con TestAppContext + theme: smoke con/sin
  items, type-check value.

minga-explorer:
- Borra fn stat_card local (~60 líneas).
- Borra dep yahweh-widget-card.
- 3 callsites pasan value.to_string() (widget acepta
  Into<SharedString>).

brahman-broker-explorer:
- fn state_card refactorizada como wrap del stat_card compartido,
  preservando la traducción ProbeState→(accent,value,description)
  como helper local app-specific.
- Borra dep yahweh-widget-card.

Sub-header del listing: pasa de "recent (N de TOTAL):" a
"recent (N):" — el widget no conoce TOTAL; el caller lo pone en
label si quiere ("Nodos AST (5 de 247)"). Trade-off aceptable
por reusabilidad genérica.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Sergio
2026-05-10 12:33:02 +00:00
parent 1493d616fd
commit af7417ce08
9 changed files with 276 additions and 97 deletions
@@ -10,7 +10,7 @@ brahman-handshake = { path = "../../core/brahman-handshake" }
brahman-sidecar = { path = "../../shared/brahman-sidecar" }
yahweh-theme = { path = "../../modules/ui_engine/libs/theme" }
yahweh-widget-banner = { path = "../../modules/ui_engine/widgets/banner" }
yahweh-widget-card = { path = "../../modules/ui_engine/widgets/card" }
yahweh-widget-stat-card = { path = "../../modules/ui_engine/widgets/stat-card" }
yahweh-widget-theme-switcher = { path = "../../modules/ui_engine/widgets/theme-switcher" }
gpui = { workspace = true }
@@ -34,7 +34,7 @@ use gpui::{
};
use yahweh_theme::Theme;
use yahweh_widget_banner::{banner_themed, Banner};
use yahweh_widget_card::card_themed;
use yahweh_widget_stat_card::stat_card;
use yahweh_widget_theme_switcher::theme_switcher;
const POLL_INTERVAL: Duration = Duration::from_secs(5);
@@ -225,6 +225,10 @@ impl Render for Explorer {
}
}
/// Wrap del `stat_card` compartido con el mapeo de
/// `ProbeState` → (label/accent/value/description). Mantenemos
/// este helper local porque la traducción del enum a strings es
/// específica del explorer (no es un patrón cross-app).
#[allow(clippy::too_many_arguments)]
fn state_card(
cx: &mut Context<Explorer>,
@@ -236,21 +240,18 @@ fn state_card(
accent_down: gpui::Rgba,
accent_pending: gpui::Rgba,
) -> impl IntoElement {
let (label, accent, value, description): (&str, gpui::Rgba, String, String) = match state {
let (accent, value, description): (gpui::Rgba, String, String) = match state {
ProbeState::Pending => (
"Estado",
accent_pending,
"PENDING".into(),
"esperando primer probe…".into(),
),
ProbeState::Down { reason } => (
"Estado",
accent_down,
"DOWN".into(),
format!("connect failed: {reason}"),
),
ProbeState::UpNoProvider { flow } => (
"Estado",
accent_partial,
"UP / NO PROVIDER".into(),
format!("broker reachable; sin productor para flow `{flow}`"),
@@ -259,7 +260,6 @@ fn state_card(
flow,
producer_socket,
} => (
"Estado",
accent_up,
"UP / PROVIDER".into(),
format!(
@@ -269,27 +269,7 @@ fn state_card(
),
};
card_themed(cx)
.border_l_4()
.border_color(accent)
.child(
div()
.text_color(accent)
.text_size(px(11.))
.child(SharedString::from(label.to_string())),
)
.child(
div()
.text_color(text)
.text_size(px(28.))
.child(SharedString::from(value)),
)
.child(
div()
.text_color(text_dim)
.text_size(px(11.))
.child(SharedString::from(description)),
)
stat_card(cx, "Estado", value, &description, accent, text, text_dim, &[])
}
#[cfg(test)]
+1 -1
View File
@@ -9,7 +9,7 @@ description = "Dashboard GPUI del repo Minga: counts de nodos AST, atestaciones,
minga-store = { path = "../../modules/semantic_dht/minga-store" }
yahweh-theme = { path = "../../modules/ui_engine/libs/theme" }
yahweh-widget-banner = { path = "../../modules/ui_engine/widgets/banner" }
yahweh-widget-card = { path = "../../modules/ui_engine/widgets/card" }
yahweh-widget-stat-card = { path = "../../modules/ui_engine/widgets/stat-card" }
yahweh-widget-theme-switcher = { path = "../../modules/ui_engine/widgets/theme-switcher" }
gpui = { workspace = true }
+6 -66
View File
@@ -33,7 +33,7 @@ use gpui::{
use minga_store::PersistentRepo;
use yahweh_theme::Theme;
use yahweh_widget_banner::{banner_themed, Banner};
use yahweh_widget_card::card_themed;
use yahweh_widget_stat_card::stat_card;
use yahweh_widget_theme_switcher::theme_switcher;
const REFRESH_INTERVAL: Duration = Duration::from_secs(2);
@@ -274,7 +274,7 @@ impl Render for Explorer {
.child(stat_card(
cx,
"Nodos AST",
snap.nodes,
snap.nodes.to_string(),
"fragments parseados del código",
accent_nodes,
text,
@@ -284,7 +284,7 @@ impl Render for Explorer {
.child(stat_card(
cx,
"Atestaciones",
snap.attestations,
snap.attestations.to_string(),
"firmas Ed25519 sobre los nodos",
accent_attestations,
text,
@@ -294,7 +294,7 @@ impl Render for Explorer {
.child(stat_card(
cx,
"Claves MST",
snap.mst_keys,
snap.mst_keys.to_string(),
"entradas del Merkle Search Tree",
accent_mst,
text,
@@ -315,68 +315,8 @@ impl Render for Explorer {
}
}
/// Card visual para una estadística del dashboard. Border-l por
/// kind, label arriba + número grande + descripción + listing de
/// items recientes (puede estar vacío). Items se renderean en
/// `monospace`-look (text_size chico) — útil para hashes/dids.
fn stat_card(
cx: &mut Context<Explorer>,
label: &str,
value: usize,
description: &str,
accent: gpui::Rgba,
text: gpui::Hsla,
text_dim: gpui::Hsla,
recent_items: &[String],
) -> impl IntoElement {
let mut card = card_themed(cx)
.border_l_4()
.border_color(accent)
.child(
div()
.text_color(accent)
.text_size(px(11.))
.child(SharedString::from(label.to_string())),
)
.child(
div()
.text_color(text)
.text_size(px(28.))
.child(SharedString::from(value.to_string())),
)
.child(
div()
.text_color(text_dim)
.text_size(px(11.))
.child(SharedString::from(description.to_string())),
);
if !recent_items.is_empty() {
// Header de la sub-section.
card = card.child(
div()
.mt(px(6.))
.text_color(text_dim)
.text_size(px(10.))
.child(SharedString::from(format!(
"recent ({} de {}):",
recent_items.len(),
value
))),
);
// Una linea por item.
for it in recent_items {
card = card.child(
div()
.text_color(text)
.text_size(px(11.))
.child(SharedString::from(it.clone())),
);
}
}
card
}
// `stat_card` se promovió a `yahweh-widget-stat-card` y se importa
// arriba. La fn local fue eliminada en la iter 15 del refactor.
#[cfg(test)]
mod tests {