From 98b537a1a53a9312b3e958f5ca897460ea954ba6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sat, 17 Oct 2026 21:47:06 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=84=20feat(ci):=20modern=20runs=20list?= =?UTF-8?q?=20with=20status=20icons,=20commit=20titles=20and=20header=20me?= =?UTF-8?q?nus?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Runs render as rows: state icon, commit subject, `#n · trigger · branch · commit · actor`, duration and age; branches drop `refs/heads/`. - Run workflow and Status badge move from cards into header dropdowns. - Live swaps keep open dropdowns open instead of closing them. --- crates/forge-web/assets/nav.js | 56 +++- crates/forge-web/src/i18n/releases_ci.rs | 30 +-- crates/forge-web/src/pages/ci_runs.rs | 230 ++++++++++------ style/main.scss | 325 ++++++++++++++++++++++- 4 files changed, 520 insertions(+), 121 deletions(-) diff --git a/crates/forge-web/assets/nav.js b/crates/forge-web/assets/nav.js index 1b7b015..0d2b85a 100644 --- a/crates/forge-web/assets/nav.js +++ b/crates/forge-web/assets/nav.js @@ -125,7 +125,7 @@ }); } - function adopt(doc, keepFields) { + function adopt(doc, keepFields, dd) { document.title = doc.title; ['lang', 'data-theme', 'data-ui'].forEach(function (name) { if (doc.documentElement.hasAttribute(name)) { root.setAttribute(name, doc.documentElement.getAttribute(name)); } @@ -143,7 +143,10 @@ s.textContent = old.textContent; old.replaceWith(s); }); + // Dropdowns reopen before the fields come back: a field inside a closed
cannot take focus. + if (dd) { openDropdowns(dd); } if (kept) { restoreFields(kept); } + if (dd) { focusDropdown(dd); } followTail(); syncUnread(); syncLive(); @@ -173,7 +176,7 @@ // how: 'nav' (link or GET form: push, top), 'pop' (history: push nothing, restore scroll), // 'post' (form post: replace, keep scroll), 'query' (in place: replace, keep scroll), 'live' (a - // live page's change: no history entry, keep scroll, no fragment jump). + // live page's change: no history entry, keep scroll, no fragment jump, open dropdowns stay open). function swap(html, dest, how, keepFields) { var doc = new DOMParser().parseFromString(html, 'text/html'); if (!doc.body) { location.assign(dest.href); return; } @@ -182,8 +185,10 @@ // A live swap keeps the log tail where the reader had it: at the end it stays at the end. var tail = how === 'live' ? document.querySelector('[data-live-log]') : null; var tailAt = tail ? { top: tail.scrollTop, end: tail.scrollTop + tail.clientHeight >= tail.scrollHeight - 24 } : null; - closeDropdowns(null); - adopt(doc, keepFields); + // A live change must not shut a menu the reader has open (a run's branch picker, say). + var dd = how === 'live' ? captureDropdowns() : null; + if (how !== 'live') { closeDropdowns(null); } + adopt(doc, keepFields, dd); if (tailAt) { var nextTail = document.querySelector('[data-live-log]'); if (nextTail) { nextTail.scrollTop = tailAt.end ? nextTail.scrollHeight : tailAt.top; } @@ -258,6 +263,49 @@ }); } + // Each dropdown gets a key that survives a re-render: its id when it has one, else its summary + // text plus a count for repeats (two menus with the same text stay apart, in document order). + function dropdownKeys() { + var seen = Object.create(null); + return Array.prototype.map.call(document.querySelectorAll(DROPDOWN), function (d) { + if (d.id) { return { key: 'id:' + d.id, el: d }; } + var s = d.querySelector('summary'); + var text = s ? s.textContent.replace(/\s+/g, ' ').trim() : ''; + seen[text] = (seen[text] || 0) + 1; + return { key: 'text:' + text + '#' + seen[text], el: d }; + }); + } + + // Before a live swap: the keys of the open dropdowns, and the key of the one holding focus. + function captureDropdowns() { + var active = document.activeElement; + var out = { open: [], focus: null }; + dropdownKeys().forEach(function (item) { + if (!item.el.open) { return; } + out.open.push(item.key); + if (active && item.el.contains(active)) { out.focus = item.key; } + }); + return out; + } + + function openDropdowns(kept) { + dropdownKeys().forEach(function (item) { + if (kept.open.indexOf(item.key) >= 0) { item.el.open = true; } + }); + } + + // Focus was in a dropdown but no field took it back (a button or the summary): the dropdown's + // summary gets it instead. + function focusDropdown(kept) { + if (!kept.focus) { return; } + var active = document.activeElement; + if (active && active !== document.body) { return; } + dropdownKeys().forEach(function (item) { + var s = item.key === kept.focus ? item.el.querySelector('summary') : null; + if (s) { s.focus({ preventScroll: true }); } + }); + } + // A click outside an open dropdown closes it. A click inside one (a select, a form field) keeps // it open. Opening a dropdown by its summary closes the others: the browser toggles it after this. document.addEventListener('click', function (e) { diff --git a/crates/forge-web/src/i18n/releases_ci.rs b/crates/forge-web/src/i18n/releases_ci.rs index bea5551..fe43b17 100644 --- a/crates/forge-web/src/i18n/releases_ci.rs +++ b/crates/forge-web/src/i18n/releases_ci.rs @@ -29,16 +29,11 @@ pub enum K { Rerun, Runs, NoRunsYet, + NoRunsHint, Jobs, JobGraph, NoJobs, - ColRun, ColState, - ColTrigger, - ColRef, - ColCommit, - ColActor, - ColAge, ColJob, ColDuration, ColRunner, @@ -174,26 +169,18 @@ pub fn t(lang: Lang, key: K) -> &'static str { (Runs, Tr) => "Çalıştırmalar", (NoRunsYet, En) => "No runs yet.", (NoRunsYet, Tr) => "Henüz çalıştırma yok.", + (NoRunsHint, En) => "Add a .forge/ci.toml to the repo, then push a commit or start a run.", + (NoRunsHint, Tr) => { + ".forge/ci.toml dosyası ekleyin, ardından bir commit gönderin ya da bir çalıştırma başlatın." + } (Jobs, En) => "Jobs", (Jobs, Tr) => "İşler", (JobGraph, En) => "Job graph", (JobGraph, Tr) => "İş grafiği", (NoJobs, En) => "No jobs.", (NoJobs, Tr) => "İş yok.", - (ColRun, En) => "Run", - (ColRun, Tr) => "Çalıştırma", (ColState, En) => "State", (ColState, Tr) => "Durum", - (ColTrigger, En) => "Trigger", - (ColTrigger, Tr) => "Tetikleyici", - (ColRef, En) => "Ref", - (ColRef, Tr) => "Referans", - (ColCommit, En) => "Commit", - (ColCommit, Tr) => "Commit", - (ColActor, En) => "Actor", - (ColActor, Tr) => "Kullanıcı", - (ColAge, En) => "Age", - (ColAge, Tr) => "Zaman", (ColJob, En) => "Job", (ColJob, Tr) => "İş", (ColDuration, En) => "Duration", @@ -473,16 +460,11 @@ mod tests { K::Rerun, K::Runs, K::NoRunsYet, + K::NoRunsHint, K::Jobs, K::JobGraph, K::NoJobs, - K::ColRun, K::ColState, - K::ColTrigger, - K::ColRef, - K::ColCommit, - K::ColActor, - K::ColAge, K::ColJob, K::ColDuration, K::ColRunner, diff --git a/crates/forge-web/src/pages/ci_runs.rs b/crates/forge-web/src/pages/ci_runs.rs index 0a1e070..5fc0e87 100644 --- a/crates/forge-web/src/pages/ci_runs.rs +++ b/crates/forge-web/src/pages/ci_runs.rs @@ -218,6 +218,14 @@ pub fn run_finished(state: &RunState) -> bool { ) } +/// A ref as the lists show it: `refs/heads/main` reads `main`, and so does a tag without its prefix. +fn short_ref(git_ref: &str) -> &str { + git_ref + .strip_prefix("refs/heads/") + .or_else(|| git_ref.strip_prefix("refs/tags/")) + .unwrap_or(git_ref) +} + /// Branch names of the repo, the default branch first. fn branch_choices(refs: &[RefInfo], default_branch: &str) -> Vec { let mut names: Vec = refs @@ -271,16 +279,20 @@ async fn after_change(state: &AppState, run_id: &str, before: &[CiJob]) -> Resul Ok(()) } -/// One run in the list, with its values already shown as text. +/// One run in the list, with its values already shown as text. `state_key` is the raw state word +/// that picks the row's icon. struct RunRow { href: String, number: i64, + title: String, state: String, - state_class: String, + state_key: String, trigger: String, - git_ref: String, + branch: String, + commit_href: String, commit: String, actor: String, + duration: String, when: String, } @@ -382,7 +394,26 @@ async fn action_button(action: String, csrf: String, label: &'static str) -> Res }) } -/// The run list body: the manual run form for writers, the runs, and the pager. +/// The state icon of a run row, labelled with its state word. Finished runs get a disc with a glyph. +/// Running and queued runs have no glyph: their ring is drawn in CSS, and the running ring turns. +#[component] +async fn run_icon(state: String, label: String) -> Result { + let class = format!("ci-run-icon ci-{state}"); + Ok(view! { + + if state == "success" { + + } else if state == "failure" || state == "error" { + + } else if state == "cancelled" || state == "blocked" || state == "skipped" { + + } + + }) +} + +/// The run list body. The header holds the manual run and badge menus and the run count, outside +/// the live region's card. The live region wraps the count and the card, so a live swap refreshes both. #[component] async fn runs_body( head: RepoHead, @@ -391,6 +422,7 @@ async fn runs_body( manual: Option, badge: BadgeInfo, rows: Vec, + total: u64, newer_href: Option, older_href: Option, page_label: String, @@ -405,80 +437,87 @@ async fn runs_body(
(text)
} } - if let Some(form) = manual { -
-

(g::t(lang, K::RunWorkflow))

-

(g::t(lang, K::RunWorkflowHelp))

-
- - - -
-
- } -
-
- (g::t(lang, K::BadgeHeading)) -

(g::t(lang, K::BadgeHelp))

-

CI

- -
-
-
-
-

(g::t(lang, K::Runs))

- if rows.is_empty() { -

(g::t(lang, K::NoRunsYet))

- } else { -
- - - - - - - - - - - - - +
+

(g::t(lang, K::Runs))

+
+ if let Some(form) = manual { + + } + +
+
+ (total) +
+ if rows.is_empty() { +
+

(g::t(lang, K::NoRunsYet))

+

(g::t(lang, K::NoRunsHint))

+
+ } else { +
    for row in rows.iter() { -
- - - - - - - - +
  • + run_icon(state: row.state_key.clone(), label: row.state.clone()) +
    +

    (row.title.as_str())

    +

    + "#" (row.number) + " \u{b7} " (row.trigger.as_str()) + " \u{b7} " (row.branch.as_str()) + " \u{b7} " (row.commit.as_str()) + if !row.actor.is_empty() { + " \u{b7} " (row.actor.as_str()) + } +

    +
    +
    + if !row.duration.is_empty() { + (row.duration.as_str()) + } + (row.when.as_str()) +
    +
  • } - -
    (g::t(lang, K::ColRun))(g::t(lang, K::ColState))(g::t(lang, K::ColTrigger))(g::t(lang, K::ColRef))(g::t(lang, K::ColCommit))(g::t(lang, K::ColActor))(g::t(lang, K::ColAge))
    "#" (row.number)(row.state.as_str())(row.trigger.as_str())(row.git_ref.as_str())(row.commit.as_str())(row.actor.as_str())(row.when.as_str())
    -
    - } - -
    + + } + + +
    }) } @@ -494,22 +533,51 @@ async fn runs_list_page(cx: &Cx) -> Result { let page = page_from_query(cx); let (runs, total) = state.store.list_runs(&ctx.repo.id, page, PER_PAGE).await?; let names = usernames(state, lang, runs.iter().map(|run| run.actor_id.as_str())).await?; + // Each row's title is its commit's first line, read for this page's runs only. A commit that + // cannot be read leaves the row's trigger as its title. + let path = ctx.path.clone(); + let oids: Vec = runs.iter().map(|run| run.commit_oid.clone()).collect(); + let subjects = tokio::task::spawn_blocking(move || { + oids.iter() + .map(|oid| { + read_commit(&path, oid) + .ok() + .flatten() + .map(|commit| commit.summary) + .filter(|summary| !summary.is_empty()) + }) + .collect::>() + }) + .await?; + let base = ci_href(&title_of(&ctx)); let rows: Vec = runs .iter() - .map(|run| RunRow { + .zip(subjects) + .map(|(run, subject)| RunRow { href: run_href(&title_of(&ctx), run.number), number: run.number, + title: subject.unwrap_or_else(|| run.trigger.clone()), state: state_text(lang, run.state.as_str()), - state_class: format!("ci-state ci-{}", run.state.as_str()), + state_key: run.state.as_str().to_owned(), trigger: run.trigger.clone(), - git_ref: run.git_ref.clone(), + branch: short_ref(&run.git_ref).to_owned(), + commit_href: format!("/{}/commit/{}", title_of(&ctx), run.commit_oid), commit: short_oid(&run.commit_oid).to_owned(), actor: names.get(&run.actor_id).cloned().unwrap_or_default(), + // Only a run that has started or finished has a duration. A queued run has none yet. + duration: if run_finished(&run.state) || run.state == RunState::Running { + duration_text( + lang, + Some(run.created_at.as_str()), + run.finished_at.as_deref(), + ) + } else { + String::new() + }, when: age_text(lang, &run.created_at), }) .collect(); let last_page = total.div_ceil(u64::from(PER_PAGE)).max(1); - let base = ci_href(&title_of(&ctx)); let newer_href = (page > 1).then(|| format!("{base}?page={}", page - 1)); let older_href = (u64::from(page) < last_page).then(|| format!("{base}?page={}", page + 1)); let page_label = g::page_label(lang, page); @@ -536,7 +604,7 @@ async fn runs_list_page(cx: &Cx) -> Result { Ok(view! { shell(title: title.as_str(), viewer: ctx.viewer.as_ref(), runs_body(head: head, lang: lang, notice: notice, manual: manual, badge: badge, rows: rows, - newer_href: newer_href, older_href: older_href, page_label: page_label, live: live)) + total: total, newer_href: newer_href, older_href: older_href, page_label: page_label, live: live)) }) } diff --git a/style/main.scss b/style/main.scss index d083861..86d8065 100644 --- a/style/main.scss +++ b/style/main.scss @@ -3574,10 +3574,138 @@ span.reaction { padding-left: 20px; } -// CI runs list: whole-row links. -// The run number link stretches over its row (no JS). Other controls in the row sit above it. -.ci-runs tbody tr { +// CI runs list. The header holds the title, the run count and two menus (Run workflow and the +// status badge). The count and the card sit in the live region, which is display: contents, so +// they share the header's flex row and the card wraps onto its own line. +.ci-list-head { + display: flex; + flex-wrap: wrap; + align-items: center; + gap: 8px 12px; + margin-bottom: 12px; +} + +.ci-list-title { + margin: 0; + font-size: 1.25rem; +} + +.ci-tools { + display: flex; + flex-wrap: wrap; + align-items: center; + gap: 8px; + order: 1; + margin-left: auto; +} + +.ci-live { + display: contents; +} + +.ci-count { + align-self: center; + padding: 1px 8px; + border-radius: 999px; + background: var(--surface-2); + color: var(--muted); + font-size: 0.8125rem; + font-weight: 600; +} + +.ci-list-card { + order: 2; + flex: 1 1 100%; + min-width: 0; + margin: 0; + padding: 0; + overflow: hidden; +} + +// The header menus reuse the `.menu` dropdown. The trigger is a compact button with a chevron. +.ci-tool > summary { + display: inline-flex; + align-items: center; + gap: 8px; + padding: 6px 12px; + background: var(--surface); + color: var(--text); + font-size: 0.875rem; + font-weight: 600; + + &::after { + content: ""; + width: 6px; + height: 6px; + border-right: 1.5px solid currentColor; + border-bottom: 1.5px solid currentColor; + transform: translateY(-2px) rotate(45deg); + } +} + +.ci-tool[open] > summary::after { + transform: translateY(1px) rotate(-135deg); +} + +.ci-pop { + width: min(340px, calc(100vw - 32px)); + padding: 14px; + text-align: left; + + p { + margin: 0 0 10px; + } + + .ci-manual-form { + flex-direction: column; + align-items: stretch; + gap: 10px; + margin-top: 0; + + label { + display: grid; + gap: 6px; + } + + select { + width: 100%; + } + + button { + align-self: flex-end; + } + } +} + +.ci-empty { + padding: 40px 16px; + text-align: center; + + p { + margin: 0 0 6px; + } +} + +.ci-list-card .pager { + margin: 0; + padding: 12px 16px; + border-top: 1px solid var(--border); +} + +.ci-run-list { + margin: 0; + padding: 0; + list-style: none; +} + +// Each row is a grid: state icon, title and meta, then the duration and age on the right. +.ci-run-row { position: relative; + display: grid; + grid-template-columns: auto minmax(0, 1fr) auto; + align-items: center; + gap: 12px; + padding: 12px 16px; cursor: pointer; &:hover { @@ -3585,21 +3713,194 @@ span.reaction { } } -.ci-runs .ci-run-link::after { - content: ""; - position: absolute; - inset: 0; +.ci-run-row + .ci-run-row { + border-top: 1px solid var(--border); } -.ci-runs tbody a:not(.ci-run-link), -.ci-runs tbody button, -.ci-runs tbody input, -.ci-runs tbody select, -.ci-runs tbody textarea { +// The title link stretches over its row (no JS). The commit link sits above it. +.ci-run-link { + color: var(--text); + text-decoration: none; + + &::after { + content: ""; + position: absolute; + inset: 0; + } + + &:hover { + color: var(--accent-ink); + } +} + +.ci-run-commit { position: relative; z-index: 1; } +.ci-run-body { + min-width: 0; +} + +.ci-run-title { + margin: 0 0 2px; + overflow: hidden; + font-weight: 600; + text-overflow: ellipsis; + white-space: nowrap; +} + +.ci-run-sub { + margin: 0; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + + code { + font-size: 0.8125rem; + } +} + +.ci-branch { + padding: 0 6px; + border: 1px solid var(--border); + border-radius: 999px; + background: var(--surface); + color: var(--text-2); +} + +.ci-run-side { + display: flex; + flex-direction: column; + align-items: flex-end; + gap: 2px; + text-align: right; + white-space: nowrap; + font-variant-numeric: tabular-nums; +} + +.ci-run-dur { + display: inline-flex; + align-items: center; + gap: 4px; +} + +.ci-clock { + width: 12px; + height: 12px; + flex-shrink: 0; + fill: none; + stroke: currentColor; + stroke-width: 1.75; + stroke-linecap: round; + stroke-linejoin: round; +} + +// The state icon: a disc with a glyph for finished runs, a ring for running and queued ones. +.ci-run-icon { + --ci-icon: var(--muted); + + display: inline-flex; + align-items: center; + justify-content: center; + box-sizing: border-box; + width: 20px; + height: 20px; + border-radius: 50%; + background: var(--ci-icon); + color: var(--accent-text); + + svg { + width: 12px; + height: 12px; + fill: none; + stroke: currentColor; + stroke-width: 2; + stroke-linecap: round; + stroke-linejoin: round; + } + + &.ci-success { + --ci-icon: var(--public-text); + } + + &.ci-failure, + &.ci-error { + --ci-icon: var(--danger); + } + + &.ci-cancelled, + &.ci-blocked, + &.ci-skipped { + --ci-icon: var(--muted); + } + + &.ci-running, + &.ci-queued, + &.ci-waiting_approval { + --ci-icon: var(--warning); + + background: transparent; + border: 2px solid var(--ci-icon); + } + + &.ci-running { + border-top-color: transparent; + animation: ci-spin 0.9s linear infinite; + } + + &.ci-queued::after, + &.ci-waiting_approval::after { + content: ""; + width: 4px; + height: 4px; + border-radius: 50%; + background: var(--ci-icon); + } +} + +@keyframes ci-spin { + to { + transform: rotate(360deg); + } +} + +@media (prefers-reduced-motion: reduce) { + .ci-run-icon.ci-running { + animation: none; + } +} + +// Phone width: the duration and age move under the meta line, and the row keeps its icon. +@media (max-width: 600px) { + .ci-run-row { + grid-template-columns: auto minmax(0, 1fr); + row-gap: 6px; + } + + .ci-run-icon { + grid-row: 1 / span 2; + } + + .ci-run-body, + .ci-run-side { + grid-column: 2; + } + + .ci-run-side { + flex-direction: row; + align-items: center; + gap: 10px; + text-align: left; + } + + // The meta line wraps here, so the commit and the author stay in view. + .ci-run-sub { + white-space: normal; + overflow-wrap: anywhere; + } +} + // CI run page: header and job graph. // Sizes below match the GRAPH_* constants in crates/forge-web/src/pages/ci_runs.rs: the card is // 200x56, columns are 48px apart, cards in a column 16px apart, and the box is padded 16px.