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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user