use forge_core::ci::RunState; use topcoat::Result; use topcoat::context::Cx; use topcoat::view::{View, component, view}; use super::{repo_href, short_oid}; use crate::i18n::Lang; use crate::i18n::timeline as tl; pub const MIN_BAR_PERCENT: u32 = 6; pub struct StripBar { pub oid: String, pub lines: u64, pub ci: Option, } pub fn bar_percent(lines: u64, max: u64) -> u32 { if max == 0 { return MIN_BAR_PERCENT; } let share = (lines as f64 + 1.0).ln() / (max as f64 + 1.0).ln(); let pct = (share * 100.0).round() as u32; pct.clamp(MIN_BAR_PERCENT, 100) } fn tone(ci: Option, newest: bool) -> &'static str { match ci { Some(RunState::Running | RunState::Queued) if newest => "hs-live", Some(RunState::Success) => "hs-ok", Some(RunState::Failure | RunState::Error) => "hs-bad", _ => "hs-neutral", } } struct BarView { class: String, href: String, label: String, oid: String, } #[component] pub async fn history_strip( cx: &Cx, lang: Lang, owner: String, repo: String, bars: Vec, ) -> Result { let show = bars.len() >= 2; let max = bars.iter().map(|bar| bar.lines).max().unwrap_or(0); let newest = bars.len().saturating_sub(1); let heading = tl::last_commits(lang, bars.len()); let aria = crate::i18n::t(lang, crate::i18n::Key::Timeline); let items: Vec = bars .into_iter() .enumerate() .map(|(i, bar)| BarView { class: format!( "hs-bar {} hs-h-{}", tone(bar.ci, i == newest), bar_percent(bar.lines, max) ), href: repo_href(&owner, &repo, "commit", &bar.oid), label: format!( "{} \u{b7} {}", short_oid(&bar.oid), tl::lines_changed(lang, bar.lines) ), oid: bar.oid, }) .collect(); Ok(view! { if show {

(heading.as_str())

for item in items.iter() { }
} }) }