forge
Explore
Log in

Don't you dare go Hollow

A day's pushes group by repo, a group across branches opens to a row per branch, and every row's text lines up with the chevron

Browse files at this commit

b268eafaedfa1e1adf3aa941b492cf77a5d8bdebAhmet Kaan GümüşParent: 3d53dfd
Some checks failed
Show checks
  • feat
    • a day's pushes group by repo, a group across branches opens to a row per branch, and every row's text lines up with the chevron
Show full message
✨ feat: a day's pushes group by repo, a group across branches opens to a row per branch, and every row's text lines up with the chevron
crates/forge-web/src/i18n/misc.rsmodified+15 -0
@@ -780,6 +780,21 @@ pub fn push_group_words(lang: Lang, branch: &str, count: usize) -> (String, Stri
780780 }
781781 }
782782
783+/// The words either side of a grouped row for `count` pushes across `branches` branches of one
784+/// repo, e.g. `Pushed 9 times to 6 branches in` with the repo as the link.
785+pub fn push_repo_group_words(lang: Lang, branches: usize, count: usize) -> (String, String) {
786+ match lang {
787+ Lang::En => (
788+ format!("Pushed {count} times to {branches} branches in"),
789+ String::new(),
790+ ),
791+ Lang::Tr => (
792+ String::new(),
793+ format!("deposunda {branches} dala {count} gönderim"),
794+ ),
795+ }
796+}
797+
783798 /// The activity line for an inbox row: the verb, then the actor when there is one. English reads
784799 /// "opened by tahinli"; Turkish reads "tahinli tarafından açıldı", or "Açıldı" with no actor.
785800 pub fn activity_line(lang: Lang, verb: K, actor: Option<&str>) -> String {
crates/forge-web/src/views/heatmap.rsmodified+49 -19
@@ -266,38 +266,67 @@ fn day_row(lang: Lang, item: &ContributionItem, now: i64) -> DayRow {
266266 }
267267 }
268268
269-/// The selected day's entries, newest first. Pushes to one branch of one repo are grouped under the
270-/// newest of them; every other contribution is its own entry. The items come newest first, so the
271-/// first push met for a branch is its most recent one, and the entries keep that order.
272-fn day_entries(lang: Lang, items: &[ContributionItem], now: i64) -> Vec<DayEntry> {
269+/// Items split into runs that share a key, in the order each key is first met. Items without a
270+/// key (`None`) are each their own run.
271+fn group_first_seen<'a>(
272+ items: impl IntoIterator<Item = &'a ContributionItem>,
273+ key: impl Fn(&ContributionItem) -> Option<String>,
274+) -> Vec<Vec<&'a ContributionItem>> {
273275 let mut groups: Vec<Vec<&ContributionItem>> = Vec::new();
274- let mut push_group: HashMap<(String, String), usize> = HashMap::new();
276+ let mut index: HashMap<String, usize> = HashMap::new();
275277 for item in items {
276- if item.kind == ContributionKind::Push {
277- let key = (item_repo(item), item_branch(item).to_owned());
278- if let Some(&index) = push_group.get(&key) {
279- groups[index].push(item);
278+ if let Some(k) = key(item) {
279+ if let Some(&i) = index.get(&k) {
280+ groups[i].push(item);
280281 continue;
281282 }
282- push_group.insert(key, groups.len());
283+ index.insert(k, groups.len());
283284 }
284285 groups.push(vec![item]);
285286 }
286287 groups
288+}
289+
290+/// The row for a branch's pushes: the newest push, with the count when there is more than one.
291+fn branch_row(lang: Lang, pushes: &[&ContributionItem], now: i64) -> DayRow {
292+ let mut row = day_row(lang, pushes[0], now);
293+ if pushes.len() > 1 {
294+ (row.before, row.after) = g::push_group_words(lang, item_branch(pushes[0]), pushes.len());
295+ }
296+ row
297+}
298+
299+/// The selected day's entries, newest first. Pushes to one repo are grouped under the newest of
300+/// them: a group on one branch lists its pushes, a group across branches lists one row per branch.
301+/// Every other contribution is its own entry. The items come newest first, so the first push met
302+/// for a repo or branch is its most recent one, and the entries keep that order.
303+fn day_entries(lang: Lang, items: &[ContributionItem], now: i64) -> Vec<DayEntry> {
304+ let by_repo = group_first_seen(items, |item| {
305+ (item.kind == ContributionKind::Push).then(|| item_repo(item))
306+ });
307+ by_repo
287308 .into_iter()
288309 .map(|group| {
289- let newest = group[0];
290310 if group.len() == 1 {
291311 return DayEntry {
292- row: day_row(lang, newest, now),
312+ row: day_row(lang, group[0], now),
293313 pushes: Vec::new(),
294314 };
295315 }
296- let mut row = day_row(lang, newest, now);
297- (row.before, row.after) = g::push_group_words(lang, item_branch(newest), group.len());
316+ let branches = group_first_seen(group.iter().copied(), |item| {
317+ Some(item_branch(item).to_owned())
318+ });
319+ if branches.len() == 1 {
320+ return DayEntry {
321+ row: branch_row(lang, &group, now),
322+ pushes: group.iter().map(|item| day_row(lang, item, now)).collect(),
323+ };
324+ }
325+ let mut row = day_row(lang, group[0], now);
326+ (row.before, row.after) = g::push_repo_group_words(lang, branches.len(), group.len());
298327 DayEntry {
299328 row,
300- pushes: group.iter().map(|item| day_row(lang, item, now)).collect(),
329+ pushes: branches.iter().map(|b| branch_row(lang, b, now)).collect(),
301330 }
302331 })
303332 .collect()
@@ -669,7 +698,7 @@ mod tests {
669698 }
670699
671700 #[test]
672- fn pushes_to_one_branch_group_under_the_newest() {
701+ fn pushes_to_one_repo_group_by_branch_under_the_newest() {
673702 let item = |kind, ref_name: &str, at: &str| ContributionItem {
674703 kind,
675704 repo_owner: "Tahinli".to_owned(),
@@ -690,10 +719,11 @@ mod tests {
690719 ];
691720 let entries = day_entries(Lang::En, &items, 0);
692721 let shape: Vec<usize> = entries.iter().map(|e| e.pushes.len()).collect();
693- assert_eq!(shape, [3, 0, 0]);
722+ assert_eq!(shape, [2, 0]);
694723 assert_eq!(entries[0].row.updated, "2026-10-16T12:00:00Z");
695- assert_eq!(entries[0].row.before, "Pushed 3 times to main in");
696- assert_eq!(entries[2].row.before, "Pushed to dev in");
724+ assert_eq!(entries[0].row.before, "Pushed 4 times to 2 branches in");
725+ assert_eq!(entries[0].pushes[0].before, "Pushed 3 times to main in");
726+ assert_eq!(entries[0].pushes[1].before, "Pushed to dev in");
697727 }
698728
699729 #[test]
style/_heatmap.scssmodified+9 -0
@@ -253,6 +253,15 @@ a.cell {
253253 color: var(--text);
254254 }
255255
256+ // A single row keeps an empty slot the size of a group's chevron, so every row's text lines up.
257+ > ul > li:not(.day-group)::before {
258+ content: '';
259+ flex: none;
260+ width: 6px;
261+ margin-right: 4px;
262+ border-right: 1.5px solid transparent;
263+ }
264+
256265 // A group of pushes: its summary is laid out as the row, and the pushes list opens under it.
257266 .day-group {
258267 display: block;