A day's contributions group pushes to one branch into a row that opens to list them
Browse files at this commit3d53dfd79c35bd64433757f7d43e1e649f438e7dParent: d2d2dd3- feat
- a day's contributions group pushes to one branch into a row that opens to list them
3 changed files +177 -20
- crates/forge-web/src/i18n/misc.rs +15 -0
- crates/forge-web/src/views/heatmap.rs +120 -20
- style/_heatmap.scss +42 -0
crates/forge-web/src/i18n/misc.rsmodified+15 -0
| @@ -765,6 +765,21 @@ pub fn day_item_words( | ||
| 765 | 765 | } |
| 766 | 766 | } |
| 767 | 767 | |
| 768 | +/// The words either side of a grouped row for `count` pushes to one branch, e.g. `Pushed 7 times to | |
| 769 | +/// main in` with the repo as the link. The link is the repo, as for a single push. | |
| 770 | +pub fn push_group_words(lang: Lang, branch: &str, count: usize) -> (String, String) { | |
| 771 | + match lang { | |
| 772 | + Lang::En => ( | |
| 773 | + format!("Pushed {count} times to {branch} in"), | |
| 774 | + String::new(), | |
| 775 | + ), | |
| 776 | + Lang::Tr => ( | |
| 777 | + String::new(), | |
| 778 | + format!("deposunda {branch} dalına {count} gönderim"), | |
| 779 | + ), | |
| 780 | + } | |
| 781 | +} | |
| 782 | + | |
| 768 | 783 | /// The activity line for an inbox row: the verb, then the actor when there is one. English reads |
| 769 | 784 | /// "opened by tahinli"; Turkish reads "tahinli tarafından açıldı", or "Açıldı" with no actor. |
| 770 | 785 | pub fn activity_line(lang: Lang, verb: K, actor: Option<&str>) -> String { |
crates/forge-web/src/views/heatmap.rsmodified+120 -20
| @@ -194,10 +194,18 @@ struct DayRow { | ||
| 194 | 194 | relative: String, |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | -/// The selected day's heading and rows, ready for the view. | |
| 197 | +/// One entry in the selected day's list: a single contribution, or a group of pushes to one branch | |
| 198 | +/// of one repo. `row` is the entry's own line (for a group, its newest push, with the count), and | |
| 199 | +/// `pushes` lists the group's pushes, newest first; it is empty for a single contribution. | |
| 200 | +struct DayEntry { | |
| 201 | + row: DayRow, | |
| 202 | + pushes: Vec<DayRow>, | |
| 203 | +} | |
| 204 | + | |
| 205 | +/// The selected day's heading and entries, ready for the view. | |
| 198 | 206 | struct DayView { |
| 199 | 207 | heading: String, |
| 200 | - rows: Vec<DayRow>, | |
| 208 | + rows: Vec<DayEntry>, | |
| 201 | 209 | } |
| 202 | 210 | |
| 203 | 211 | /// The link for a calendar day: the day's contributions below the calendar, or back to the |
| @@ -213,14 +221,22 @@ fn day_href(date: (i64, i64, i64), selected: bool) -> String { | ||
| 213 | 221 | } |
| 214 | 222 | } |
| 215 | 223 | |
| 224 | +/// The repo an item landed in, as `owner/name`. | |
| 225 | +fn item_repo(item: &ContributionItem) -> String { | |
| 226 | + format!("{}/{}", item.repo_owner, item.repo_name) | |
| 227 | +} | |
| 228 | + | |
| 229 | +/// The branch a push went to: its ref without `refs/heads/`. Empty for everything else. | |
| 230 | +fn item_branch(item: &ContributionItem) -> &str { | |
| 231 | + item.ref_name | |
| 232 | + .strip_prefix("refs/heads/") | |
| 233 | + .unwrap_or(&item.ref_name) | |
| 234 | +} | |
| 235 | + | |
| 216 | 236 | /// The row for one contribution in the selected day's list. |
| 217 | 237 | fn day_row(lang: Lang, item: &ContributionItem, now: i64) -> DayRow { |
| 218 | - let repo = format!("{}/{}", item.repo_owner, item.repo_name); | |
| 219 | - let branch = item | |
| 220 | - .ref_name | |
| 221 | - .strip_prefix("refs/heads/") | |
| 222 | - .unwrap_or(&item.ref_name); | |
| 223 | - let (before, after) = g::day_item_words(lang, item.kind, branch, &repo); | |
| 238 | + let repo = item_repo(item); | |
| 239 | + let (before, after) = g::day_item_words(lang, item.kind, item_branch(item), &repo); | |
| 224 | 240 | let (href, link) = match item.kind { |
| 225 | 241 | ContributionKind::Push => (format!("/{repo}"), repo.clone()), |
| 226 | 242 | ContributionKind::Issue | ContributionKind::Comment => ( |
| @@ -250,6 +266,43 @@ fn day_row(lang: Lang, item: &ContributionItem, now: i64) -> DayRow { | ||
| 250 | 266 | } |
| 251 | 267 | } |
| 252 | 268 | |
| 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> { | |
| 273 | + let mut groups: Vec<Vec<&ContributionItem>> = Vec::new(); | |
| 274 | + let mut push_group: HashMap<(String, String), usize> = HashMap::new(); | |
| 275 | + 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); | |
| 280 | + continue; | |
| 281 | + } | |
| 282 | + push_group.insert(key, groups.len()); | |
| 283 | + } | |
| 284 | + groups.push(vec![item]); | |
| 285 | + } | |
| 286 | + groups | |
| 287 | + .into_iter() | |
| 288 | + .map(|group| { | |
| 289 | + let newest = group[0]; | |
| 290 | + if group.len() == 1 { | |
| 291 | + return DayEntry { | |
| 292 | + row: day_row(lang, newest, now), | |
| 293 | + pushes: Vec::new(), | |
| 294 | + }; | |
| 295 | + } | |
| 296 | + let mut row = day_row(lang, newest, now); | |
| 297 | + (row.before, row.after) = g::push_group_words(lang, item_branch(newest), group.len()); | |
| 298 | + DayEntry { | |
| 299 | + row, | |
| 300 | + pushes: group.iter().map(|item| day_row(lang, item, now)).collect(), | |
| 301 | + } | |
| 302 | + }) | |
| 303 | + .collect() | |
| 304 | +} | |
| 305 | + | |
| 253 | 306 | /// The contribution card: heading and date range, the four stats, the month labels and the |
| 254 | 307 | /// 53-week grid, then the motivating line and the Less/More legend, then the selected day's |
| 255 | 308 | /// contributions when a day is picked. |
| @@ -293,11 +346,7 @@ pub async fn contribution_calendar( | ||
| 293 | 346 | lang, |
| 294 | 347 | &g::date_text(lang, detail.date.0, detail.date.1, detail.date.2), |
| 295 | 348 | ), |
| 296 | - rows: detail | |
| 297 | - .items | |
| 298 | - .iter() | |
| 299 | - .map(|item| day_row(lang, item, now)) | |
| 300 | - .collect(), | |
| 349 | + rows: day_entries(lang, &detail.items, now), | |
| 301 | 350 | }); |
| 302 | 351 | |
| 303 | 352 | // Month labels: one slot per column, empty where no label starts. |
| @@ -411,13 +460,36 @@ pub async fn contribution_calendar( | ||
| 411 | 460 | <p class="muted">(empty_day)</p> |
| 412 | 461 | } else { |
| 413 | 462 | <ul> |
| 414 | - for row in day.rows.into_iter() { | |
| 415 | - <li> | |
| 416 | - <span>(row.before.as_str())</span> | |
| 417 | - <a href=(row.href.as_str())>(row.link.as_str())</a> | |
| 418 | - <span>(row.after.as_str())</span> | |
| 419 | - <time data-rel="true" datetime=(row.updated.as_str())>(row.relative.as_str())</time> | |
| 420 | - </li> | |
| 463 | + for entry in day.rows.into_iter() { | |
| 464 | + if entry.pushes.is_empty() { | |
| 465 | + <li> | |
| 466 | + <span>(entry.row.before.as_str())</span> | |
| 467 | + <a href=(entry.row.href.as_str())>(entry.row.link.as_str())</a> | |
| 468 | + <span>(entry.row.after.as_str())</span> | |
| 469 | + <time data-rel="true" datetime=(entry.row.updated.as_str())>(entry.row.relative.as_str())</time> | |
| 470 | + </li> | |
| 471 | + } else { | |
| 472 | + <li class="day-group"> | |
| 473 | + <details> | |
| 474 | + <summary> | |
| 475 | + <span>(entry.row.before.as_str())</span> | |
| 476 | + <a href=(entry.row.href.as_str())>(entry.row.link.as_str())</a> | |
| 477 | + <span>(entry.row.after.as_str())</span> | |
| 478 | + <time data-rel="true" datetime=(entry.row.updated.as_str())>(entry.row.relative.as_str())</time> | |
| 479 | + </summary> | |
| 480 | + <ul> | |
| 481 | + for push in entry.pushes.into_iter() { | |
| 482 | + <li> | |
| 483 | + <span>(push.before.as_str())</span> | |
| 484 | + <a href=(push.href.as_str())>(push.link.as_str())</a> | |
| 485 | + <span>(push.after.as_str())</span> | |
| 486 | + <time data-rel="true" datetime=(push.updated.as_str())>(push.relative.as_str())</time> | |
| 487 | + </li> | |
| 488 | + } | |
| 489 | + </ul> | |
| 490 | + </details> | |
| 491 | + </li> | |
| 492 | + } | |
| 421 | 493 | } |
| 422 | 494 | </ul> |
| 423 | 495 | } |
| @@ -596,6 +668,34 @@ mod tests { | ||
| 596 | 668 | assert_eq!(civil_from_days(days_from_civil(2000, 2, 29)), (2000, 2, 29)); |
| 597 | 669 | } |
| 598 | 670 | |
| 671 | + #[test] | |
| 672 | + fn pushes_to_one_branch_group_under_the_newest() { | |
| 673 | + let item = |kind, ref_name: &str, at: &str| ContributionItem { | |
| 674 | + kind, | |
| 675 | + repo_owner: "Tahinli".to_owned(), | |
| 676 | + repo_name: "forge".to_owned(), | |
| 677 | + created_at: at.to_owned(), | |
| 678 | + ref_name: ref_name.to_owned(), | |
| 679 | + number: 0, | |
| 680 | + title: String::new(), | |
| 681 | + commit: String::new(), | |
| 682 | + }; | |
| 683 | + let push = |branch: &str, at: &str| item(ContributionKind::Push, branch, at); | |
| 684 | + let items = [ | |
| 685 | + push("refs/heads/main", "2026-10-16T12:00:00Z"), | |
| 686 | + push("refs/heads/main", "2026-10-16T11:00:00Z"), | |
| 687 | + item(ContributionKind::Issue, "", "2026-10-16T10:30:00Z"), | |
| 688 | + push("refs/heads/dev", "2026-10-16T09:00:00Z"), | |
| 689 | + push("refs/heads/main", "2026-10-16T08:00:00Z"), | |
| 690 | + ]; | |
| 691 | + let entries = day_entries(Lang::En, &items, 0); | |
| 692 | + let shape: Vec<usize> = entries.iter().map(|e| e.pushes.len()).collect(); | |
| 693 | + assert_eq!(shape, [3, 0, 0]); | |
| 694 | + 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"); | |
| 697 | + } | |
| 698 | + | |
| 599 | 699 | #[test] |
| 600 | 700 | fn days_from_civil_inverts_civil_from_days() { |
| 601 | 701 | for days in [-1, 0, 1, 10_957, 20_454, 47_000] { |
style/_heatmap.scssmodified+42 -0
| @@ -253,6 +253,48 @@ a.cell { | ||
| 253 | 253 | color: var(--text); |
| 254 | 254 | } |
| 255 | 255 | |
| 256 | + // A group of pushes: its summary is laid out as the row, and the pushes list opens under it. | |
| 257 | + .day-group { | |
| 258 | + display: block; | |
| 259 | + } | |
| 260 | + | |
| 261 | + summary { | |
| 262 | + display: flex; | |
| 263 | + flex-wrap: wrap; | |
| 264 | + align-items: baseline; | |
| 265 | + gap: 2px 6px; | |
| 266 | + font-size: 14px; | |
| 267 | + color: var(--text); | |
| 268 | + cursor: pointer; | |
| 269 | + list-style: none; | |
| 270 | + | |
| 271 | + &::-webkit-details-marker { | |
| 272 | + display: none; | |
| 273 | + } | |
| 274 | + | |
| 275 | + // A chevron that points right when closed and down when open. | |
| 276 | + &::before { | |
| 277 | + content: ''; | |
| 278 | + align-self: center; | |
| 279 | + width: 6px; | |
| 280 | + height: 6px; | |
| 281 | + margin-right: 4px; | |
| 282 | + border-right: 1.5px solid var(--muted); | |
| 283 | + border-bottom: 1.5px solid var(--muted); | |
| 284 | + transform: rotate(-45deg); | |
| 285 | + transition: transform 0.15s ease; | |
| 286 | + } | |
| 287 | + } | |
| 288 | + | |
| 289 | + details[open] > summary::before { | |
| 290 | + transform: rotate(45deg); | |
| 291 | + } | |
| 292 | + | |
| 293 | + details > ul { | |
| 294 | + margin-top: 10px; | |
| 295 | + padding-left: 20px; | |
| 296 | + } | |
| 297 | + | |
| 256 | 298 | time { |
| 257 | 299 | margin-left: auto; |
| 258 | 300 | font-size: 13px; |