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 commitb268eafaedfa1e1adf3aa941b492cf77a5d8bdebParent: 3d53dfd- 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
3 changed files +73 -19
- crates/forge-web/src/i18n/misc.rs +15 -0
- crates/forge-web/src/views/heatmap.rs +49 -19
- style/_heatmap.scss +9 -0
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 | |||
| 780 | } | 780 | } |
| 781 | } | 781 | } |
| 782 | 782 | ||
| 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 | + | ||
| 783 | /// The activity line for an inbox row: the verb, then the actor when there is one. English reads | 798 | /// The activity line for an inbox row: the verb, then the actor when there is one. English reads |
| 784 | /// "opened by tahinli"; Turkish reads "tahinli tarafından açıldı", or "Açıldı" with no actor. | 799 | /// "opened by tahinli"; Turkish reads "tahinli tarafından açıldı", or "Açıldı" with no actor. |
| 785 | pub fn activity_line(lang: Lang, verb: K, actor: Option<&str>) -> String { | 800 | 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 { | |||
| 266 | } | 266 | } |
| 267 | } | 267 | } |
| 268 | 268 | ||
| 269 | -/// The selected day's entries, newest first. Pushes to one branch of one repo are grouped under the | 269 | +/// Items split into runs that share a key, in the order each key is first met. Items without a |
| 270 | -/// newest of them; every other contribution is its own entry. The items come newest first, so the | 270 | +/// key (`None`) are each their own run. |
| 271 | -/// first push met for a branch is its most recent one, and the entries keep that order. | 271 | +fn group_first_seen<'a>( |
| 272 | -fn day_entries(lang: Lang, items: &[ContributionItem], now: i64) -> Vec<DayEntry> { | 272 | + items: impl IntoIterator<Item = &'a ContributionItem>, |
| 273 | + key: impl Fn(&ContributionItem) -> Option<String>, | ||
| 274 | +) -> Vec<Vec<&'a ContributionItem>> { | ||
| 273 | let mut groups: Vec<Vec<&ContributionItem>> = Vec::new(); | 275 | 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(); |
| 275 | for item in items { | 277 | for item in items { |
| 276 | - if item.kind == ContributionKind::Push { | 278 | + if let Some(k) = key(item) { |
| 277 | - let key = (item_repo(item), item_branch(item).to_owned()); | 279 | + if let Some(&i) = index.get(&k) { |
| 278 | - if let Some(&index) = push_group.get(&key) { | 280 | + groups[i].push(item); |
| 279 | - groups[index].push(item); | ||
| 280 | continue; | 281 | continue; |
| 281 | } | 282 | } |
| 282 | - push_group.insert(key, groups.len()); | 283 | + index.insert(k, groups.len()); |
| 283 | } | 284 | } |
| 284 | groups.push(vec![item]); | 285 | groups.push(vec![item]); |
| 285 | } | 286 | } |
| 286 | groups | 287 | 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 | ||
| 287 | .into_iter() | 308 | .into_iter() |
| 288 | .map(|group| { | 309 | .map(|group| { |
| 289 | - let newest = group[0]; | ||
| 290 | if group.len() == 1 { | 310 | if group.len() == 1 { |
| 291 | return DayEntry { | 311 | return DayEntry { |
| 292 | - row: day_row(lang, newest, now), | 312 | + row: day_row(lang, group[0], now), |
| 293 | pushes: Vec::new(), | 313 | pushes: Vec::new(), |
| 294 | }; | 314 | }; |
| 295 | } | 315 | } |
| 296 | - let mut row = day_row(lang, newest, now); | 316 | + let branches = group_first_seen(group.iter().copied(), |item| { |
| 297 | - (row.before, row.after) = g::push_group_words(lang, item_branch(newest), group.len()); | 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()); | ||
| 298 | DayEntry { | 327 | DayEntry { |
| 299 | row, | 328 | 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(), |
| 301 | } | 330 | } |
| 302 | }) | 331 | }) |
| 303 | .collect() | 332 | .collect() |
| @@ -669,7 +698,7 @@ mod tests { | |||
| 669 | } | 698 | } |
| 670 | 699 | ||
| 671 | #[test] | 700 | #[test] |
| 672 | - fn pushes_to_one_branch_group_under_the_newest() { | 701 | + fn pushes_to_one_repo_group_by_branch_under_the_newest() { |
| 673 | let item = |kind, ref_name: &str, at: &str| ContributionItem { | 702 | let item = |kind, ref_name: &str, at: &str| ContributionItem { |
| 674 | kind, | 703 | kind, |
| 675 | repo_owner: "Tahinli".to_owned(), | 704 | repo_owner: "Tahinli".to_owned(), |
| @@ -690,10 +719,11 @@ mod tests { | |||
| 690 | ]; | 719 | ]; |
| 691 | let entries = day_entries(Lang::En, &items, 0); | 720 | let entries = day_entries(Lang::En, &items, 0); |
| 692 | let shape: Vec<usize> = entries.iter().map(|e| e.pushes.len()).collect(); | 721 | 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]); |
| 694 | assert_eq!(entries[0].row.updated, "2026-10-16T12:00:00Z"); | 723 | assert_eq!(entries[0].row.updated, "2026-10-16T12:00:00Z"); |
| 695 | - assert_eq!(entries[0].row.before, "Pushed 3 times to main in"); | 724 | + assert_eq!(entries[0].row.before, "Pushed 4 times to 2 branches in"); |
| 696 | - assert_eq!(entries[2].row.before, "Pushed to dev 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"); | ||
| 697 | } | 727 | } |
| 698 | 728 | ||
| 699 | #[test] | 729 | #[test] |
style/_heatmap.scssmodified+9 -0
| @@ -253,6 +253,15 @@ a.cell { | |||
| 253 | color: var(--text); | 253 | color: var(--text); |
| 254 | } | 254 | } |
| 255 | 255 | ||
| 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 | + | ||
| 256 | // A group of pushes: its summary is laid out as the row, and the pushes list opens under it. | 265 | // A group of pushes: its summary is laid out as the row, and the pushes list opens under it. |
| 257 | .day-group { | 266 | .day-group { |
| 258 | display: block; | 267 | display: block; |