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