From b268eafaedfa1e1adf3aa941b492cf77a5d8bdeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 27 Oct 2026 19:42:46 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20a=20day's=20pushes=20group?= =?UTF-8?q?=20by=20repo,=20a=20group=20across=20branches=20opens=20to=20a?= =?UTF-8?q?=20row=20per=20branch,=20and=20every=20row's=20text=20lines=20u?= =?UTF-8?q?p=20with=20the=20chevron?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/forge-web/src/i18n/misc.rs | 15 ++++++ crates/forge-web/src/views/heatmap.rs | 68 +++++++++++++++++++-------- style/_heatmap.scss | 9 ++++ 3 files changed, 73 insertions(+), 19 deletions(-) diff --git a/crates/forge-web/src/i18n/misc.rs b/crates/forge-web/src/i18n/misc.rs index 6addd83..994dfcd 100644 --- a/crates/forge-web/src/i18n/misc.rs +++ b/crates/forge-web/src/i18n/misc.rs @@ -780,6 +780,21 @@ pub fn push_group_words(lang: Lang, branch: &str, count: usize) -> (String, Stri } } +/// The words either side of a grouped row for `count` pushes across `branches` branches of one +/// repo, e.g. `Pushed 9 times to 6 branches in` with the repo as the link. +pub fn push_repo_group_words(lang: Lang, branches: usize, count: usize) -> (String, String) { + match lang { + Lang::En => ( + format!("Pushed {count} times to {branches} branches in"), + String::new(), + ), + Lang::Tr => ( + String::new(), + format!("deposunda {branches} dala {count} gönderim"), + ), + } +} + /// The activity line for an inbox row: the verb, then the actor when there is one. English reads /// "opened by tahinli"; Turkish reads "tahinli tarafından açıldı", or "Açıldı" with no actor. pub fn activity_line(lang: Lang, verb: K, actor: Option<&str>) -> String { diff --git a/crates/forge-web/src/views/heatmap.rs b/crates/forge-web/src/views/heatmap.rs index 82f9d96..f40aa7e 100644 --- a/crates/forge-web/src/views/heatmap.rs +++ b/crates/forge-web/src/views/heatmap.rs @@ -266,38 +266,67 @@ fn day_row(lang: Lang, item: &ContributionItem, now: i64) -> DayRow { } } -/// The selected day's entries, newest first. Pushes to one branch of one repo are grouped under the -/// newest of them; every other contribution is its own entry. The items come newest first, so the -/// first push met for a branch is its most recent one, and the entries keep that order. -fn day_entries(lang: Lang, items: &[ContributionItem], now: i64) -> Vec { +/// Items split into runs that share a key, in the order each key is first met. Items without a +/// key (`None`) are each their own run. +fn group_first_seen<'a>( + items: impl IntoIterator, + key: impl Fn(&ContributionItem) -> Option, +) -> Vec> { let mut groups: Vec> = Vec::new(); - let mut push_group: HashMap<(String, String), usize> = HashMap::new(); + let mut index: HashMap = HashMap::new(); for item in items { - if item.kind == ContributionKind::Push { - let key = (item_repo(item), item_branch(item).to_owned()); - if let Some(&index) = push_group.get(&key) { - groups[index].push(item); + if let Some(k) = key(item) { + if let Some(&i) = index.get(&k) { + groups[i].push(item); continue; } - push_group.insert(key, groups.len()); + index.insert(k, groups.len()); } groups.push(vec![item]); } groups +} + +/// The row for a branch's pushes: the newest push, with the count when there is more than one. +fn branch_row(lang: Lang, pushes: &[&ContributionItem], now: i64) -> DayRow { + let mut row = day_row(lang, pushes[0], now); + if pushes.len() > 1 { + (row.before, row.after) = g::push_group_words(lang, item_branch(pushes[0]), pushes.len()); + } + row +} + +/// The selected day's entries, newest first. Pushes to one repo are grouped under the newest of +/// them: a group on one branch lists its pushes, a group across branches lists one row per branch. +/// Every other contribution is its own entry. The items come newest first, so the first push met +/// for a repo or branch is its most recent one, and the entries keep that order. +fn day_entries(lang: Lang, items: &[ContributionItem], now: i64) -> Vec { + let by_repo = group_first_seen(items, |item| { + (item.kind == ContributionKind::Push).then(|| item_repo(item)) + }); + by_repo .into_iter() .map(|group| { - let newest = group[0]; if group.len() == 1 { return DayEntry { - row: day_row(lang, newest, now), + row: day_row(lang, group[0], now), pushes: Vec::new(), }; } - let mut row = day_row(lang, newest, now); - (row.before, row.after) = g::push_group_words(lang, item_branch(newest), group.len()); + let branches = group_first_seen(group.iter().copied(), |item| { + Some(item_branch(item).to_owned()) + }); + if branches.len() == 1 { + return DayEntry { + row: branch_row(lang, &group, now), + pushes: group.iter().map(|item| day_row(lang, item, now)).collect(), + }; + } + let mut row = day_row(lang, group[0], now); + (row.before, row.after) = g::push_repo_group_words(lang, branches.len(), group.len()); DayEntry { row, - pushes: group.iter().map(|item| day_row(lang, item, now)).collect(), + pushes: branches.iter().map(|b| branch_row(lang, b, now)).collect(), } }) .collect() @@ -669,7 +698,7 @@ mod tests { } #[test] - fn pushes_to_one_branch_group_under_the_newest() { + fn pushes_to_one_repo_group_by_branch_under_the_newest() { let item = |kind, ref_name: &str, at: &str| ContributionItem { kind, repo_owner: "Tahinli".to_owned(), @@ -690,10 +719,11 @@ mod tests { ]; let entries = day_entries(Lang::En, &items, 0); let shape: Vec = entries.iter().map(|e| e.pushes.len()).collect(); - assert_eq!(shape, [3, 0, 0]); + assert_eq!(shape, [2, 0]); assert_eq!(entries[0].row.updated, "2026-10-16T12:00:00Z"); - assert_eq!(entries[0].row.before, "Pushed 3 times to main in"); - assert_eq!(entries[2].row.before, "Pushed to dev in"); + assert_eq!(entries[0].row.before, "Pushed 4 times to 2 branches in"); + assert_eq!(entries[0].pushes[0].before, "Pushed 3 times to main in"); + assert_eq!(entries[0].pushes[1].before, "Pushed to dev in"); } #[test] diff --git a/style/_heatmap.scss b/style/_heatmap.scss index 8301dcb..fe54bdb 100644 --- a/style/_heatmap.scss +++ b/style/_heatmap.scss @@ -253,6 +253,15 @@ a.cell { color: var(--text); } + // A single row keeps an empty slot the size of a group's chevron, so every row's text lines up. + > ul > li:not(.day-group)::before { + content: ''; + flex: none; + width: 6px; + margin-right: 4px; + border-right: 1.5px solid transparent; + } + // A group of pushes: its summary is laid out as the row, and the pushes list opens under it. .day-group { display: block;