R reruns the selected finished run in the CI list and / focuses the page's search field, or opens the palette when it has none
Browse files at this commit474bafa36136c5889a020f39578b2d833ff57484Parent: f74e69e- feat
- r reruns the selected finished run in the CI list and / focuses the page's search field, or opens the palette when it has none
- the palette lists Copy clone URL and Assign to me, and text typed after the opening path searches the page's actions by name
- a run page's log appends line by line while its job runs, with no ANSI codes and only whole lines
- each Needs you section has a paged full list
- the row you click grows into each page's real title, not only an h1
- perf
- a long job log's line count resumes from a cache rather than rescanning the file
- fix
- a palette action still runs after a live update replaced its button, and says so if it is gone
- on issue and pull pages the palette opens with the repo path, not the title
- style
- muted labels pass 4.5:1 in the fern and spark light themes
16 changed files +816 -242
- crates/forge-core/src/store/needs.rs +204 -95
- crates/forge-web/assets/nav.js +52 -13
- crates/forge-web/src/accent_palette.rs +2 -2
- crates/forge-web/src/i18n/code.rs +12 -0
- crates/forge-web/src/i18n/issues.rs +4 -0
- crates/forge-web/src/i18n/needs.rs +48 -0
- crates/forge-web/src/pages/ci_job.rs +79 -13
- crates/forge-web/src/pages/ci_runs.rs +26 -9
- crates/forge-web/src/pages/issue_parts.rs +19 -1
- crates/forge-web/src/pages/issue_view.rs +2 -1
- crates/forge-web/src/pages/needs_you.rs +287 -107
- crates/forge-web/src/pages/pull_view.rs +2 -1
- crates/forge-web/src/pages/repo.rs +2 -0
- style/_kb_rerun.scss +52 -0
- style/_needs.scss +24 -0
- style/main.scss +1 -0
crates/forge-core/src/store/needs.rsmodified+204 -95
| @@ -1,15 +1,17 @@ | |||
| 1 | //! What is waiting on the signed-in user, for the `/needs-you` page: their failing CI runs, their | 1 | //! What is waiting on the signed-in user, for the `/needs-you` page: their failing CI runs, their |
| 2 | -//! own open pull requests that carry a review verdict, and their assigned open issues. Reads only. | 2 | +//! own open pull requests that carry a review verdict, their assigned open issues and their unread |
| 3 | -//! Every query applies the viewer's readable-repo rule (`readable_repo`), as the other per-user | 3 | +//! mentions. Reads only. Every query applies the viewer's readable-repo rule (`readable_repo`), as |
| 4 | -//! lists do. Review requests and mentions come from `review_requests_for_user` and `waiting_on`. | 4 | +//! the other per-user lists do. Review requests come from `review_requests_for_user`. |
| 5 | 5 | ||
| 6 | use std::time::Duration; | 6 | use std::time::Duration; |
| 7 | 7 | ||
| 8 | use turso::Value; | 8 | use turso::Value; |
| 9 | 9 | ||
| 10 | use super::notifications::{readable_params, readable_repo}; | 10 | use super::notifications::{readable_params, readable_repo}; |
| 11 | +use super::shell_activity::WaitingItem; | ||
| 11 | use super::{Store, col_int, col_text, fetch_all}; | 12 | use super::{Store, col_int, col_text, fetch_all}; |
| 12 | use crate::error::Result; | 13 | use crate::error::Result; |
| 14 | +use crate::notifications::Reason; | ||
| 13 | use crate::time::stamp_ago; | 15 | use crate::time::stamp_ago; |
| 14 | 16 | ||
| 15 | /// How far back a failing run counts. The same window as the profile corner's failing count. | 17 | /// How far back a failing run counts. The same window as the profile corner's failing count. |
| @@ -48,7 +50,7 @@ pub struct OwnPull { | |||
| 48 | pub number: i64, | 50 | pub number: i64, |
| 49 | /// Title of the pull request. | 51 | /// Title of the pull request. |
| 50 | pub title: String, | 52 | pub title: String, |
| 51 | - /// The verdict from `review_summary`. | 53 | + /// The verdict from the latest review of each reviewer. |
| 52 | pub verdict: Verdict, | 54 | pub verdict: Verdict, |
| 53 | /// When the pull request last changed. | 55 | /// When the pull request last changed. |
| 54 | pub updated_at: String, | 56 | pub updated_at: String, |
| @@ -69,29 +71,112 @@ pub struct AssignedIssue { | |||
| 69 | pub updated_at: String, | 71 | pub updated_at: String, |
| 70 | } | 72 | } |
| 71 | 73 | ||
| 74 | +/// The failing runs query without its page, newest first. | ||
| 75 | +fn failing_runs_sql(readable: &str) -> String { | ||
| 76 | + format!( | ||
| 77 | + "SELECT owner, name, number, git_ref, created_at FROM ( \ | ||
| 78 | + SELECT ci_runs.state, ci_runs.created_at, ci_runs.number, ci_runs.git_ref, \ | ||
| 79 | + o.username AS owner, r.name AS name, ROW_NUMBER() OVER ( \ | ||
| 80 | + PARTITION BY ci_runs.repo_id, ci_runs.git_ref ORDER BY ci_runs.number DESC) AS rn \ | ||
| 81 | + FROM ci_runs JOIN repos r ON r.id = ci_runs.repo_id \ | ||
| 82 | + JOIN users o ON o.id = r.owner_id \ | ||
| 83 | + WHERE ci_runs.actor_id = ? AND {readable} \ | ||
| 84 | + ) WHERE rn = 1 AND state IN ('failure', 'error') AND created_at >= ? \ | ||
| 85 | + ORDER BY created_at DESC, number DESC" | ||
| 86 | + ) | ||
| 87 | +} | ||
| 88 | + | ||
| 89 | +/// The open pull requests with a verdict, without their page, newest first. Each row's last | ||
| 90 | +/// column is 1 when the latest review of some reviewer asks for changes, 0 when all approve. | ||
| 91 | +fn own_pulls_sql(readable: &str) -> String { | ||
| 92 | + format!( | ||
| 93 | + "SELECT o.username, r.name, i.number, i.title, i.updated_at, v.changes_requested \ | ||
| 94 | + FROM issues i \ | ||
| 95 | + JOIN repos r ON r.id = i.repo_id \ | ||
| 96 | + JOIN users o ON o.id = r.owner_id \ | ||
| 97 | + JOIN ( SELECT issue_id, MAX(CASE WHEN state = 'changes_requested' THEN 1 ELSE 0 END) \ | ||
| 98 | + AS changes_requested FROM ( \ | ||
| 99 | + SELECT issue_id, state, ROW_NUMBER() OVER ( \ | ||
| 100 | + PARTITION BY issue_id, author_id ORDER BY submitted_at DESC, id DESC) AS rn \ | ||
| 101 | + FROM pull_reviews WHERE state IN ('approved', 'changes_requested') \ | ||
| 102 | + ) WHERE rn = 1 GROUP BY issue_id ) v ON v.issue_id = i.id \ | ||
| 103 | + WHERE i.kind = 'pull' AND i.state = 'open' AND i.author_id = ? AND {readable} \ | ||
| 104 | + ORDER BY i.updated_at DESC, i.number DESC" | ||
| 105 | + ) | ||
| 106 | +} | ||
| 107 | + | ||
| 108 | +/// The assigned open issues without their page, newest first. | ||
| 109 | +fn assigned_issues_sql(readable: &str) -> String { | ||
| 110 | + format!( | ||
| 111 | + "SELECT o.username, r.name, i.number, i.title, i.updated_at FROM issue_assignees ia \ | ||
| 112 | + JOIN issues i ON i.id = ia.issue_id AND i.kind = 'issue' AND i.state = 'open' \ | ||
| 113 | + JOIN repos r ON r.id = i.repo_id \ | ||
| 114 | + JOIN users o ON o.id = r.owner_id \ | ||
| 115 | + WHERE ia.user_id = ? AND {readable} \ | ||
| 116 | + ORDER BY i.updated_at DESC, i.number DESC" | ||
| 117 | + ) | ||
| 118 | +} | ||
| 119 | + | ||
| 120 | +/// The unread mentions without their page, newest first. The same rule as `waiting_on`, with the | ||
| 121 | +/// reason fixed to a mention. | ||
| 122 | +fn mentions_sql(readable: &str) -> String { | ||
| 123 | + format!( | ||
| 124 | + "SELECT o.username, r.name, i.number, i.kind, i.title, n.updated_at \ | ||
| 125 | + FROM notifications n \ | ||
| 126 | + JOIN repos r ON r.id = n.repo_id \ | ||
| 127 | + JOIN users o ON o.id = r.owner_id \ | ||
| 128 | + JOIN issues i ON i.id = n.issue_id \ | ||
| 129 | + WHERE n.user_id = ? AND n.unread = 1 \ | ||
| 130 | + AND n.reason = 'mention' AND {readable} \ | ||
| 131 | + ORDER BY n.updated_at DESC, n.id DESC" | ||
| 132 | + ) | ||
| 133 | +} | ||
| 134 | + | ||
| 135 | +/// Binds the viewer id, then the readable-repo parameters, as every query here does. | ||
| 136 | +fn viewer_params(user_id: &str) -> Vec<Value> { | ||
| 137 | + let mut params = vec![Value::Text(user_id.to_string())]; | ||
| 138 | + params.extend(readable_params(user_id)); | ||
| 139 | + params | ||
| 140 | +} | ||
| 141 | + | ||
| 142 | +/// `base` with its page: `LIMIT` and `OFFSET` are the last two placeholders. | ||
| 143 | +fn paged(base: &str) -> String { | ||
| 144 | + format!("{base} LIMIT ? OFFSET ?") | ||
| 145 | +} | ||
| 146 | + | ||
| 72 | impl Store { | 147 | impl Store { |
| 148 | + /// The number of rows a query without its page returns. | ||
| 149 | + async fn count_rows(&self, base: &str, params: Vec<Value>) -> Result<u64> { | ||
| 150 | + let conn = self.read_conn().await; | ||
| 151 | + let counts = fetch_all( | ||
| 152 | + &conn, | ||
| 153 | + &format!("SELECT COUNT(*) FROM ({base})"), | ||
| 154 | + params, | ||
| 155 | + |row| col_int(row, 0), | ||
| 156 | + ) | ||
| 157 | + .await?; | ||
| 158 | + Ok(counts | ||
| 159 | + .first() | ||
| 160 | + .and_then(|n| u64::try_from(*n).ok()) | ||
| 161 | + .unwrap_or(0)) | ||
| 162 | + } | ||
| 163 | + | ||
| 73 | /// The user's newest run per (repo, ref) when it failed within the failing window, newest | 164 | /// The user's newest run per (repo, ref) when it failed within the failing window, newest |
| 74 | - /// first, at most `limit`. Runs in repos the user cannot read are left out. | 165 | + /// first, one page at a time. Runs in repos the user cannot read are left out. |
| 75 | - pub async fn failing_runs(&self, actor_id: &str, limit: i64) -> Result<Vec<FailingRun>> { | 166 | + pub async fn failing_runs( |
| 76 | - let readable = readable_repo(); | 167 | + &self, |
| 77 | - let mut params = vec![Value::Text(actor_id.to_string())]; | 168 | + actor_id: &str, |
| 78 | - params.extend(readable_params(actor_id)); | 169 | + limit: i64, |
| 170 | + offset: i64, | ||
| 171 | + ) -> Result<Vec<FailingRun>> { | ||
| 172 | + let mut params = viewer_params(actor_id); | ||
| 79 | params.push(Value::Text(stamp_ago(FAILING_WINDOW))); | 173 | params.push(Value::Text(stamp_ago(FAILING_WINDOW))); |
| 80 | params.push(Value::Integer(limit)); | 174 | params.push(Value::Integer(limit)); |
| 175 | + params.push(Value::Integer(offset)); | ||
| 81 | let conn = self.read_conn().await; | 176 | let conn = self.read_conn().await; |
| 82 | fetch_all( | 177 | fetch_all( |
| 83 | &conn, | 178 | &conn, |
| 84 | - &format!( | 179 | + &paged(&failing_runs_sql(&readable_repo())), |
| 85 | - "SELECT owner, name, number, git_ref, created_at FROM ( \ | ||
| 86 | - SELECT ci_runs.state, ci_runs.created_at, ci_runs.number, ci_runs.git_ref, \ | ||
| 87 | - o.username AS owner, r.name AS name, ROW_NUMBER() OVER ( \ | ||
| 88 | - PARTITION BY ci_runs.repo_id, ci_runs.git_ref ORDER BY ci_runs.number DESC) AS rn \ | ||
| 89 | - FROM ci_runs JOIN repos r ON r.id = ci_runs.repo_id \ | ||
| 90 | - JOIN users o ON o.id = r.owner_id \ | ||
| 91 | - WHERE ci_runs.actor_id = ? AND {readable} \ | ||
| 92 | - ) WHERE rn = 1 AND state IN ('failure', 'error') AND created_at >= ? \ | ||
| 93 | - ORDER BY created_at DESC, number DESC LIMIT ?" | ||
| 94 | - ), | ||
| 95 | params, | 180 | params, |
| 96 | |row| { | 181 | |row| { |
| 97 | Ok(FailingRun { | 182 | Ok(FailingRun { |
| @@ -106,91 +191,71 @@ impl Store { | |||
| 106 | .await | 191 | .await |
| 107 | } | 192 | } |
| 108 | 193 | ||
| 194 | + /// How many failing runs `failing_runs` lists in all. | ||
| 195 | + pub async fn failing_runs_total(&self, actor_id: &str) -> Result<u64> { | ||
| 196 | + let mut params = viewer_params(actor_id); | ||
| 197 | + params.push(Value::Text(stamp_ago(FAILING_WINDOW))); | ||
| 198 | + self.count_rows(&failing_runs_sql(&readable_repo()), params) | ||
| 199 | + .await | ||
| 200 | + } | ||
| 201 | + | ||
| 109 | /// Open pull requests the user authored that have a changes-requested or an approving review, | 202 | /// Open pull requests the user authored that have a changes-requested or an approving review, |
| 110 | - /// newest first, at most `limit`. The verdict is `review_summary`'s, so a pull with a change | 203 | + /// newest first, one page at a time. A pull with a change request is listed as changes |
| 111 | - /// request is listed as such even when someone else approved it. Pulls in repos the user cannot | 204 | + /// requested even when someone else approved it. Pulls in repos the user cannot read are left |
| 112 | - /// read are left out. | 205 | + /// out. |
| 113 | pub async fn own_pulls_with_verdict( | 206 | pub async fn own_pulls_with_verdict( |
| 114 | &self, | 207 | &self, |
| 115 | author_id: &str, | 208 | author_id: &str, |
| 116 | - limit: usize, | 209 | + limit: i64, |
| 210 | + offset: i64, | ||
| 117 | ) -> Result<Vec<OwnPull>> { | 211 | ) -> Result<Vec<OwnPull>> { |
| 118 | - let readable = readable_repo(); | 212 | + let mut params = viewer_params(author_id); |
| 119 | - let mut params = vec![Value::Text(author_id.to_string())]; | 213 | + params.push(Value::Integer(limit)); |
| 120 | - params.extend(readable_params(author_id)); | 214 | + params.push(Value::Integer(offset)); |
| 121 | - // Candidates: the pulls with at least one approving or changes-requesting review. Each is | 215 | + let conn = self.read_conn().await; |
| 122 | - // then checked with `review_summary`, which ignores dismissed and comment-only reviews. | 216 | + fetch_all( |
| 123 | - let candidates = { | 217 | + &conn, |
| 124 | - let conn = self.read_conn().await; | 218 | + &paged(&own_pulls_sql(&readable_repo())), |
| 125 | - fetch_all( | 219 | + params, |
| 126 | - &conn, | 220 | + |row| { |
| 127 | - &format!( | 221 | + Ok(OwnPull { |
| 128 | - "SELECT i.id, o.username, r.name, i.number, i.title, i.updated_at FROM issues i \ | 222 | + owner: col_text(row, 0)?, |
| 129 | - JOIN repos r ON r.id = i.repo_id \ | 223 | + repo: col_text(row, 1)?, |
| 130 | - JOIN users o ON o.id = r.owner_id \ | 224 | + number: col_int(row, 2)?, |
| 131 | - WHERE i.kind = 'pull' AND i.state = 'open' AND i.author_id = ? AND {readable} \ | 225 | + title: col_text(row, 3)?, |
| 132 | - AND EXISTS (SELECT 1 FROM pull_reviews pr WHERE pr.issue_id = i.id \ | 226 | + updated_at: col_text(row, 4)?, |
| 133 | - AND pr.state IN ('approved', 'changes_requested')) \ | 227 | + verdict: if col_int(row, 5)? == 1 { |
| 134 | - ORDER BY i.updated_at DESC, i.number DESC" | 228 | + Verdict::ChangesRequested |
| 135 | - ), | 229 | + } else { |
| 136 | - params, | 230 | + Verdict::Approved |
| 137 | - |row| { | 231 | + }, |
| 138 | - Ok(( | 232 | + }) |
| 139 | - col_text(row, 0)?, | 233 | + }, |
| 140 | - col_text(row, 1)?, | 234 | + ) |
| 141 | - col_text(row, 2)?, | 235 | + .await |
| 142 | - col_int(row, 3)?, | 236 | + } |
| 143 | - col_text(row, 4)?, | 237 | + |
| 144 | - col_text(row, 5)?, | 238 | + /// How many pull requests `own_pulls_with_verdict` lists in all. |
| 145 | - )) | 239 | + pub async fn own_pulls_total(&self, author_id: &str) -> Result<u64> { |
| 146 | - }, | 240 | + self.count_rows(&own_pulls_sql(&readable_repo()), viewer_params(author_id)) |
| 147 | - ) | 241 | + .await |
| 148 | - .await? | ||
| 149 | - }; | ||
| 150 | - | ||
| 151 | - let mut out = Vec::new(); | ||
| 152 | - for (id, owner, repo, number, title, updated_at) in candidates { | ||
| 153 | - if out.len() >= limit { | ||
| 154 | - break; | ||
| 155 | - } | ||
| 156 | - let summary = self.review_summary(&id).await?; | ||
| 157 | - let verdict = if !summary.changes_requested_by.is_empty() { | ||
| 158 | - Verdict::ChangesRequested | ||
| 159 | - } else if !summary.approved_by.is_empty() { | ||
| 160 | - Verdict::Approved | ||
| 161 | - } else { | ||
| 162 | - continue; | ||
| 163 | - }; | ||
| 164 | - out.push(OwnPull { | ||
| 165 | - owner, | ||
| 166 | - repo, | ||
| 167 | - number, | ||
| 168 | - title, | ||
| 169 | - verdict, | ||
| 170 | - updated_at, | ||
| 171 | - }); | ||
| 172 | - } | ||
| 173 | - Ok(out) | ||
| 174 | } | 242 | } |
| 175 | 243 | ||
| 176 | - /// Open issues assigned to the user, newest first, at most `limit`. Pull requests are not | 244 | + /// Open issues assigned to the user, newest first, one page at a time. Pull requests are not |
| 177 | /// listed. Issues in repos the user cannot read are left out. | 245 | /// listed. Issues in repos the user cannot read are left out. |
| 178 | - pub async fn assigned_issues(&self, user_id: &str, limit: i64) -> Result<Vec<AssignedIssue>> { | 246 | + pub async fn assigned_issues( |
| 179 | - let readable = readable_repo(); | 247 | + &self, |
| 180 | - let mut params = vec![Value::Text(user_id.to_string())]; | 248 | + user_id: &str, |
| 181 | - params.extend(readable_params(user_id)); | 249 | + limit: i64, |
| 250 | + offset: i64, | ||
| 251 | + ) -> Result<Vec<AssignedIssue>> { | ||
| 252 | + let mut params = viewer_params(user_id); | ||
| 182 | params.push(Value::Integer(limit)); | 253 | params.push(Value::Integer(limit)); |
| 254 | + params.push(Value::Integer(offset)); | ||
| 183 | let conn = self.read_conn().await; | 255 | let conn = self.read_conn().await; |
| 184 | fetch_all( | 256 | fetch_all( |
| 185 | &conn, | 257 | &conn, |
| 186 | - &format!( | 258 | + &paged(&assigned_issues_sql(&readable_repo())), |
| 187 | - "SELECT o.username, r.name, i.number, i.title, i.updated_at FROM issue_assignees ia \ | ||
| 188 | - JOIN issues i ON i.id = ia.issue_id AND i.kind = 'issue' AND i.state = 'open' \ | ||
| 189 | - JOIN repos r ON r.id = i.repo_id \ | ||
| 190 | - JOIN users o ON o.id = r.owner_id \ | ||
| 191 | - WHERE ia.user_id = ? AND {readable} \ | ||
| 192 | - ORDER BY i.updated_at DESC, i.number DESC LIMIT ?" | ||
| 193 | - ), | ||
| 194 | params, | 259 | params, |
| 195 | |row| { | 260 | |row| { |
| 196 | Ok(AssignedIssue { | 261 | Ok(AssignedIssue { |
| @@ -204,6 +269,49 @@ impl Store { | |||
| 204 | ) | 269 | ) |
| 205 | .await | 270 | .await |
| 206 | } | 271 | } |
| 272 | + | ||
| 273 | + /// How many issues `assigned_issues` lists in all. | ||
| 274 | + pub async fn assigned_issues_total(&self, user_id: &str) -> Result<u64> { | ||
| 275 | + self.count_rows(&assigned_issues_sql(&readable_repo()), viewer_params(user_id)) | ||
| 276 | + .await | ||
| 277 | + } | ||
| 278 | + | ||
| 279 | + /// The user's unread mentions, newest first, one page at a time. Mentions in repos the user | ||
| 280 | + /// cannot read are left out. | ||
| 281 | + pub async fn mentions_waiting( | ||
| 282 | + &self, | ||
| 283 | + user_id: &str, | ||
| 284 | + limit: i64, | ||
| 285 | + offset: i64, | ||
| 286 | + ) -> Result<Vec<WaitingItem>> { | ||
| 287 | + let mut params = viewer_params(user_id); | ||
| 288 | + params.push(Value::Integer(limit)); | ||
| 289 | + params.push(Value::Integer(offset)); | ||
| 290 | + let conn = self.read_conn().await; | ||
| 291 | + fetch_all( | ||
| 292 | + &conn, | ||
| 293 | + &paged(&mentions_sql(&readable_repo())), | ||
| 294 | + params, | ||
| 295 | + |row| { | ||
| 296 | + Ok(WaitingItem { | ||
| 297 | + owner: col_text(row, 0)?, | ||
| 298 | + repo: col_text(row, 1)?, | ||
| 299 | + number: col_int(row, 2)?, | ||
| 300 | + is_pull: col_text(row, 3)? == "pull", | ||
| 301 | + title: col_text(row, 4)?, | ||
| 302 | + reason: Reason::Mention, | ||
| 303 | + updated_at: col_text(row, 5)?, | ||
| 304 | + }) | ||
| 305 | + }, | ||
| 306 | + ) | ||
| 307 | + .await | ||
| 308 | + } | ||
| 309 | + | ||
| 310 | + /// How many mentions `mentions_waiting` lists in all. | ||
| 311 | + pub async fn mentions_total(&self, user_id: &str) -> Result<u64> { | ||
| 312 | + self.count_rows(&mentions_sql(&readable_repo()), viewer_params(user_id)) | ||
| 313 | + .await | ||
| 314 | + } | ||
| 207 | } | 315 | } |
| 208 | 316 | ||
| 209 | #[cfg(test)] | 317 | #[cfg(test)] |
| @@ -232,13 +340,14 @@ mod tests { | |||
| 232 | .set_issue_assignees(&issue.id, &tahinli.id, &["bob".to_string()]) | 340 | .set_issue_assignees(&issue.id, &tahinli.id, &["bob".to_string()]) |
| 233 | .await | 341 | .await |
| 234 | .unwrap(); | 342 | .unwrap(); |
| 235 | - assert_eq!(store.assigned_issues(&bob.id, 8).await.unwrap().len(), 1); | 343 | + assert_eq!(store.assigned_issues(&bob.id, 8, 0).await.unwrap().len(), 1); |
| 236 | 344 | ||
| 237 | // Once the repo is private and bob is not a collaborator, the assignment stays but is hidden. | 345 | // Once the repo is private and bob is not a collaborator, the assignment stays but is hidden. |
| 238 | store | 346 | store |
| 239 | .set_repo_visibility(&repo.id, Visibility::Private) | 347 | .set_repo_visibility(&repo.id, Visibility::Private) |
| 240 | .await | 348 | .await |
| 241 | .unwrap(); | 349 | .unwrap(); |
| 242 | - assert!(store.assigned_issues(&bob.id, 8).await.unwrap().is_empty()); | 350 | + assert!(store.assigned_issues(&bob.id, 8, 0).await.unwrap().is_empty()); |
| 351 | + assert_eq!(store.assigned_issues_total(&bob.id).await.unwrap(), 0); | ||
| 243 | } | 352 | } |
| 244 | } | 353 | } |
crates/forge-web/assets/nav.jsmodified+52 -13
| @@ -360,6 +360,20 @@ | |||
| 360 | // comes here: live refreshes, back and forward and form posts never animate. | 360 | // comes here: live refreshes, back and forward and form posts never animate. |
| 361 | var MORPH_NAME = 'forge-row'; | 361 | var MORPH_NAME = 'forge-row'; |
| 362 | 362 | ||
| 363 | + // The title a row grows into, by page: commit, issue and pull, CI run and job, a repo's title row, | ||
| 364 | + // and the active tab for the Code tab, which has no title row. Most specific first: the first of | ||
| 365 | + // these that is visible wins, not the first in the page, where the repo's title and tabs come first. | ||
| 366 | + var TITLE_SELECTORS = ['.commit-summary-title', '.issue-heading', '.ci-tl-title', '.ci-job-title', '.repo-title', '.repo-tabs .tab.active']; | ||
| 367 | + | ||
| 368 | + function pageTitle() { | ||
| 369 | + for (var i = 0; i < TITLE_SELECTORS.length; i++) { | ||
| 370 | + var el = document.querySelector(TITLE_SELECTORS[i]); | ||
| 371 | + var box = el ? el.getBoundingClientRect() : null; | ||
| 372 | + if (box && box.width > 0 && box.height > 0) { return el; } | ||
| 373 | + } | ||
| 374 | + return null; | ||
| 375 | + } | ||
| 376 | + | ||
| 363 | function morph(row, run) { | 377 | function morph(row, run) { |
| 364 | if (!row || !document.startViewTransition || motionHeld()) { run(); return undefined; } | 378 | if (!row || !document.startViewTransition || motionHeld()) { run(); return undefined; } |
| 365 | row.style.viewTransitionName = MORPH_NAME; | 379 | row.style.viewTransitionName = MORPH_NAME; |
| @@ -372,7 +386,7 @@ | |||
| 372 | // The old row leaves the page now, so its name goes with it. | 386 | // The old row leaves the page now, so its name goes with it. |
| 373 | row.style.viewTransitionName = ''; | 387 | row.style.viewTransitionName = ''; |
| 374 | try { run(); } catch (err) { reject(err); return; } | 388 | try { run(); } catch (err) { reject(err); return; } |
| 375 | - title = document.querySelector('main h1'); | 389 | + title = pageTitle(); |
| 376 | if (title) { title.style.viewTransitionName = MORPH_NAME; } | 390 | if (title) { title.style.viewTransitionName = MORPH_NAME; } |
| 377 | resolve(); | 391 | resolve(); |
| 378 | } | 392 | } |
| @@ -3155,7 +3169,9 @@ | |||
| 3155 | for (var i = 0; i < els.length; i++) { | 3169 | for (var i = 0; i < els.length; i++) { |
| 3156 | var url = els[i].getAttribute('data-live'); | 3170 | var url = els[i].getAttribute('data-live'); |
| 3157 | if (!url) { continue; } | 3171 | if (!url) { continue; } |
| 3158 | - var tail = els[i].querySelector('[data-live-log]'); | 3172 | + // A stream's own tail is its element or one inside it with no other data-live in between. |
| 3173 | + var tail = els[i].hasAttribute('data-live-log') ? els[i] : els[i].querySelector('[data-live-log]'); | ||
| 3174 | + if (tail && tail.closest('[data-live]') !== els[i]) { tail = null; } | ||
| 3159 | if (tail) { | 3175 | if (tail) { |
| 3160 | url += (url.indexOf('?') < 0 ? '?' : '&') + 'from=' + encodeURIComponent(tail.getAttribute('data-offset') || '0'); | 3176 | url += (url.indexOf('?') < 0 ? '?' : '&') + 'from=' + encodeURIComponent(tail.getAttribute('data-offset') || '0'); |
| 3161 | } | 3177 | } |
| @@ -4174,14 +4190,17 @@ | |||
| 4174 | // Still the text the palette opened with (a repo's path): no query yet, so actions are listed. | 4190 | // Still the text the palette opened with (a repo's path): no query yet, so actions are listed. |
| 4175 | var idle = !!pal.prefill && pal.input.value === pal.prefill; | 4191 | var idle = !!pal.prefill && pal.input.value === pal.prefill; |
| 4176 | var q = raw.toLowerCase(); | 4192 | var q = raw.toLowerCase(); |
| 4193 | + var typed = pal.prefill && !idle && q.indexOf(pal.prefill.toLowerCase()) === 0 ? q.slice(pal.prefill.length) : ''; | ||
| 4177 | // With a "/" the query is a path: an item matches when its label starts with it. | 4194 | // With a "/" the query is a path: an item matches when its label starts with it. |
| 4178 | var pathMode = q.indexOf('/') >= 0; | 4195 | var pathMode = q.indexOf('/') >= 0; |
| 4179 | var scored = []; | 4196 | var scored = []; |
| 4180 | paletteItems().concat(paletteFiles(q)).forEach(function (item, idx) { | 4197 | paletteItems().concat(paletteFiles(q)).forEach(function (item, idx) { |
| 4181 | if (!Object.prototype.hasOwnProperty.call(pal.str.heads, item.kind)) { return; } | 4198 | if (!Object.prototype.hasOwnProperty.call(pal.str.heads, item.kind)) { return; } |
| 4182 | var s = pathMode ? (item.label.toLowerCase().indexOf(q) === 0 ? 3 : 0) : paletteScore(q, item.label); | 4199 | var s = pathMode ? (item.label.toLowerCase().indexOf(q) === 0 ? 3 : 0) : paletteScore(q, item.label); |
| 4183 | - // Above a path match (3), which would otherwise fill the list and cut the actions off. | 4200 | + // Above a path match (3), which would otherwise fill the list and cut the actions off. Text typed |
| 4201 | + // after the opening path searches the page's actions by name. | ||
| 4184 | if (item.kind === 'action' && idle) { s = 4; } | 4202 | if (item.kind === 'action' && idle) { s = 4; } |
| 4203 | + else if (item.kind === 'action' && typed) { var m = paletteScore(typed, item.label); s = m ? m + 3 : 0; } | ||
| 4185 | if (s > 0) { scored.push({ item: item, score: s, idx: idx }); } | 4204 | if (s > 0) { scored.push({ item: item, score: s, idx: idx }); } |
| 4186 | }); | 4205 | }); |
| 4187 | scored.sort(function (a, b) { return b.score - a.score || a.idx - b.idx; }); | 4206 | scored.sort(function (a, b) { return b.score - a.score || a.idx - b.idx; }); |
| @@ -4310,8 +4329,14 @@ | |||
| 4310 | function paletteRun(item) { | 4329 | function paletteRun(item) { |
| 4311 | if (!item) { return; } | 4330 | if (!item) { return; } |
| 4312 | if (item.kind !== 'action') { paletteGo(item.href); return; } | 4331 | if (item.kind !== 'action') { paletteGo(item.href); return; } |
| 4313 | - if (pal.busy || !item.el.isConnected) { return; } | 4332 | + if (pal.busy) { return; } |
| 4314 | var el = item.el; | 4333 | var el = item.el; |
| 4334 | + // A live update may have replaced the control while the palette was open: use the one there now. | ||
| 4335 | + if (!el.isConnected) { | ||
| 4336 | + var now = paletteActions().filter(function (a) { return a.label === item.label && a.mode === item.mode; })[0]; | ||
| 4337 | + if (!now) { paletteNote(pal.str.refused, 'is-bad'); return; } | ||
| 4338 | + el = now.el; | ||
| 4339 | + } | ||
| 4315 | if (item.mode === 'post') { paletteSubmit(el); return; } | 4340 | if (item.mode === 'post') { paletteSubmit(el); return; } |
| 4316 | pal.reload = null; | 4341 | pal.reload = null; |
| 4317 | if (item.mode === 'go' || (item.mode === 'confirm' && el.tagName === 'A')) { | 4342 | if (item.mode === 'go' || (item.mode === 'confirm' && el.tagName === 'A')) { |
| @@ -4398,6 +4423,8 @@ | |||
| 4398 | dlg.showModal(); | 4423 | dlg.showModal(); |
| 4399 | // The path bar's path comes in as a prefix when it has owner and repo, ready to narrow down. | 4424 | // The path bar's path comes in as a prefix when it has owner and repo, ready to narrow down. |
| 4400 | var path = (opener.getAttribute('data-path') || '').replace(/\/+$/, ''); | 4425 | var path = (opener.getAttribute('data-path') || '').replace(/\/+$/, ''); |
| 4426 | + // An issue or a pull adds its title after the path: only owner and repo are a path to narrow. | ||
| 4427 | + if (path.indexOf(' \u00b7 ') >= 0) { path = path.split('/').slice(0, 2).join('/'); } | ||
| 4401 | var prefill = path.split('/').filter(Boolean).length >= 2 ? path + '/' : ''; | 4428 | var prefill = path.split('/').filter(Boolean).length >= 2 ? path + '/' : ''; |
| 4402 | pal.prefill = prefill; | 4429 | pal.prefill = prefill; |
| 4403 | pal.input.value = prefill; | 4430 | pal.input.value = prefill; |
| @@ -4438,13 +4465,19 @@ | |||
| 4438 | if (t.closest('[data-palette-open]')) { e.preventDefault(); openPalette(); } | 4465 | if (t.closest('[data-palette-open]')) { e.preventDefault(); openPalette(); } |
| 4439 | }); | 4466 | }); |
| 4440 | 4467 | ||
| 4441 | - // "/" opens the palette when no field has the keyboard and no other dialog is open. Nothing else on | 4468 | + // "/" focuses the page's own search or filter field when it has one in main, and otherwise opens the |
| 4442 | - // the site uses "/" as a key. | 4469 | + // palette, when no field has the keyboard and no other dialog is open. Nothing else on the site uses |
| 4470 | + // "/" as a key. | ||
| 4443 | document.addEventListener('keydown', function (e) { | 4471 | document.addEventListener('keydown', function (e) { |
| 4444 | if (e.key !== '/' || e.ctrlKey || e.metaKey || e.altKey || e.isComposing) { return; } | 4472 | if (e.key !== '/' || e.ctrlKey || e.metaKey || e.altKey || e.isComposing) { return; } |
| 4445 | var t = e.target; | 4473 | var t = e.target; |
| 4446 | if (t && (t.isContentEditable || t.tagName === 'INPUT' || t.tagName === 'TEXTAREA' || t.tagName === 'SELECT')) { return; } | 4474 | if (t && (t.isContentEditable || t.tagName === 'INPUT' || t.tagName === 'TEXTAREA' || t.tagName === 'SELECT')) { return; } |
| 4447 | - if (document.querySelector('dialog[open]') || !document.querySelector('[data-palette-open]')) { return; } | 4475 | + if (document.querySelector('dialog[open]')) { return; } |
| 4476 | + var field = Array.prototype.filter.call(document.querySelectorAll('main input[type="search"]'), function (f) { | ||
| 4477 | + return f.offsetParent !== null && !f.disabled; | ||
| 4478 | + })[0]; | ||
| 4479 | + if (field) { e.preventDefault(); field.focus(); return; } | ||
| 4480 | + if (!document.querySelector('[data-palette-open]')) { return; } | ||
| 4448 | e.preventDefault(); | 4481 | e.preventDefault(); |
| 4449 | openPalette(); | 4482 | openPalette(); |
| 4450 | }); | 4483 | }); |
| @@ -5540,16 +5573,18 @@ | |||
| 5540 | // ---- keyboard rows ---------------------------------------------------------------------------------- | 5573 | // ---- keyboard rows ---------------------------------------------------------------------------------- |
| 5541 | // Rows marked data-kb-row (lists of commits, issues, pulls, CI runs, repos, notifications) take the | 5574 | // Rows marked data-kb-row (lists of commits, issues, pulls, CI runs, repos, notifications) take the |
| 5542 | // keys: j and k move the selection, Enter opens the row's first link, x ticks its checkbox if it has | 5575 | // keys: j and k move the selection, Enter opens the row's first link, x ticks its checkbox if it has |
| 5543 | -// one, and ? lists the keys. The selection is remembered by that link's address, so a live swap | 5576 | +// one, r reruns the row when it has a form marked data-kb-rerun (a finished CI run, for a writer), |
| 5577 | +// and ? lists the keys. / focuses the search field of the page (the "/" handler above, which opens the | ||
| 5578 | +// palette when there is none). The selection is remembered by that link's address, so a live swap | ||
| 5544 | // that keeps the row keeps it selected; otherwise it clears quietly. Nothing fires while typing, | 5579 | // that keeps the row keeps it selected; otherwise it clears quietly. Nothing fires while typing, |
| 5545 | -// with a modifier held, or while a dialog (the palette included) is open. r and / are not bound | 5580 | +// with a modifier held, or while a dialog (the palette included) is open. r only posts: the page |
| 5546 | -// here: r has no row form to post to, and / already opens the palette (see the report). | 5581 | +// changes when the server answers. |
| 5547 | (function () { | 5582 | (function () { |
| 5548 | 'use strict'; | 5583 | 'use strict'; |
| 5549 | 5584 | ||
| 5550 | var KB_TEXT = { | 5585 | var KB_TEXT = { |
| 5551 | - en: { next: 'Next row', prev: 'Previous row', open: 'Open the row', pick: 'Select the row', keys: 'Show these keys', close: 'Close', title: 'Keyboard' }, | 5586 | + en: { next: 'Next row', prev: 'Previous row', open: 'Open the row', pick: 'Select the row', rerun: 'Re-run the row', find: 'Focus the search', keys: 'Show these keys', close: 'Close', title: 'Keyboard' }, |
| 5552 | - tr: { next: 'Sonraki satır', prev: 'Önceki satır', open: 'Satırı aç', pick: 'Satırı seç', keys: 'Bu tuşları göster', close: 'Kapat', title: 'Klavye' } | 5587 | + tr: { next: 'Sonraki satır', prev: 'Önceki satır', open: 'Satırı aç', pick: 'Satırı seç', rerun: 'Satırı yeniden çalıştır', find: 'Aramaya odaklan', keys: 'Bu tuşları göster', close: 'Kapat', title: 'Klavye' } |
| 5553 | }; | 5588 | }; |
| 5554 | 5589 | ||
| 5555 | var selKey = null; // the address of the selected row's first link | 5590 | var selKey = null; // the address of the selected row's first link |
| @@ -5603,7 +5638,7 @@ | |||
| 5603 | h.textContent = T.title; | 5638 | h.textContent = T.title; |
| 5604 | dlg.appendChild(h); | 5639 | dlg.appendChild(h); |
| 5605 | var dl = document.createElement('dl'); | 5640 | var dl = document.createElement('dl'); |
| 5606 | - [['j', T.next], ['k', T.prev], ['Enter', T.open], ['x', T.pick], ['?', T.keys]].forEach(function (pair) { | 5641 | + [['j', T.next], ['k', T.prev], ['Enter', T.open], ['x', T.pick], ['r', T.rerun], ['/', T.find], ['?', T.keys]].forEach(function (pair) { |
| 5607 | var dt = document.createElement('dt'); | 5642 | var dt = document.createElement('dt'); |
| 5608 | var kbd = document.createElement('kbd'); | 5643 | var kbd = document.createElement('kbd'); |
| 5609 | kbd.textContent = pair[0]; | 5644 | kbd.textContent = pair[0]; |
| @@ -5644,6 +5679,10 @@ | |||
| 5644 | var cur = selectedRow(); | 5679 | var cur = selectedRow(); |
| 5645 | var cb = cur ? cur.querySelector('input[type="checkbox"]') : null; | 5680 | var cb = cur ? cur.querySelector('input[type="checkbox"]') : null; |
| 5646 | if (cb && !cb.disabled) { e.preventDefault(); cb.click(); } | 5681 | if (cb && !cb.disabled) { e.preventDefault(); cb.click(); } |
| 5682 | + } else if (e.key === 'r') { | ||
| 5683 | + var sel = selectedRow(); | ||
| 5684 | + var rerun = sel ? sel.querySelector('form[data-kb-rerun]') : null; | ||
| 5685 | + if (rerun) { e.preventDefault(); rerun.requestSubmit(); } | ||
| 5647 | } | 5686 | } |
| 5648 | }, false); | 5687 | }, false); |
| 5649 | 5688 | ||
crates/forge-web/src/accent_palette.rsmodified+2 -2
| @@ -382,7 +382,7 @@ pub const BASES: &[Base] = &[ | |||
| 382 | surface_2: "#EEF2EC", | 382 | surface_2: "#EEF2EC", |
| 383 | text: "#1E2420", | 383 | text: "#1E2420", |
| 384 | text_2: "#3A433D", | 384 | text_2: "#3A433D", |
| 385 | - muted: "#69736B", | 385 | + muted: "#667068", |
| 386 | border: "#DDE3DB", | 386 | border: "#DDE3DB", |
| 387 | border_strong: "#C5CFC3", | 387 | border_strong: "#C5CFC3", |
| 388 | code_bg: "#EEF2EC", | 388 | code_bg: "#EEF2EC", |
| @@ -415,7 +415,7 @@ pub const BASES: &[Base] = &[ | |||
| 415 | surface_2: "#F0F0F0", | 415 | surface_2: "#F0F0F0", |
| 416 | text: "#18181B", | 416 | text: "#18181B", |
| 417 | text_2: "#3F3F46", | 417 | text_2: "#3F3F46", |
| 418 | - muted: "#71717A", | 418 | + muted: "#6C6C75", |
| 419 | border: "#E4E4E7", | 419 | border: "#E4E4E7", |
| 420 | border_strong: "#D4D4D8", | 420 | border_strong: "#D4D4D8", |
| 421 | code_bg: "#F0F0F0", | 421 | code_bg: "#F0F0F0", |
crates/forge-web/src/i18n/code.rsmodified+12 -0
| @@ -21,6 +21,9 @@ pub enum K { | |||
| 21 | ShowingFirst, | 21 | ShowingFirst, |
| 22 | ShowingFirstEnd, | 22 | ShowingFirstEnd, |
| 23 | CloneTitle, | 23 | CloneTitle, |
| 24 | + CopyCloneUrl, | ||
| 25 | + CloneCopied, | ||
| 26 | + CloneCopyFailed, | ||
| 24 | SshRequiresKey, | 27 | SshRequiresKey, |
| 25 | BranchesTitle, | 28 | BranchesTitle, |
| 26 | FilterRefs, | 29 | FilterRefs, |
| @@ -160,6 +163,12 @@ pub fn t(lang: Lang, key: K) -> &'static str { | |||
| 160 | (ShowingFirstEnd, Tr) => " gösteriliyor)", | 163 | (ShowingFirstEnd, Tr) => " gösteriliyor)", |
| 161 | (CloneTitle, En) => "Clone", | 164 | (CloneTitle, En) => "Clone", |
| 162 | (CloneTitle, Tr) => "Klonla", | 165 | (CloneTitle, Tr) => "Klonla", |
| 166 | + (CopyCloneUrl, En) => "Copy clone URL", | ||
| 167 | + (CopyCloneUrl, Tr) => "Klon adresini kopyala", | ||
| 168 | + (CloneCopied, En) => "Copied", | ||
| 169 | + (CloneCopied, Tr) => "Kopyalandı", | ||
| 170 | + (CloneCopyFailed, En) => "Copy failed", | ||
| 171 | + (CloneCopyFailed, Tr) => "Kopyalanamadı", | ||
| 163 | (SshRequiresKey, En) => "SSH (requires an ed25519 or ECDSA key on your account)", | 172 | (SshRequiresKey, En) => "SSH (requires an ed25519 or ECDSA key on your account)", |
| 164 | (SshRequiresKey, Tr) => "SSH (hesabınızda bir ed25519 veya ECDSA anahtarı olmalı)", | 173 | (SshRequiresKey, Tr) => "SSH (hesabınızda bir ed25519 veya ECDSA anahtarı olmalı)", |
| 165 | (BranchesTitle, En) => "Branches", | 174 | (BranchesTitle, En) => "Branches", |
| @@ -557,6 +566,9 @@ mod tests { | |||
| 557 | K::ShowingFirst, | 566 | K::ShowingFirst, |
| 558 | K::ShowingFirstEnd, | 567 | K::ShowingFirstEnd, |
| 559 | K::CloneTitle, | 568 | K::CloneTitle, |
| 569 | + K::CopyCloneUrl, | ||
| 570 | + K::CloneCopied, | ||
| 571 | + K::CloneCopyFailed, | ||
| 560 | K::SshRequiresKey, | 572 | K::SshRequiresKey, |
| 561 | K::BranchesTitle, | 573 | K::BranchesTitle, |
| 562 | K::FilterRefs, | 574 | K::FilterRefs, |
crates/forge-web/src/i18n/issues.rsmodified+4 -0
| @@ -98,6 +98,7 @@ pub enum K { | |||
| 98 | CommaUsernames, | 98 | CommaUsernames, |
| 99 | SaveAssignees, | 99 | SaveAssignees, |
| 100 | NoOneAssigned, | 100 | NoOneAssigned, |
| 101 | + AssignToMe, | ||
| 101 | MilestoneBox, | 102 | MilestoneBox, |
| 102 | NoneOption, | 103 | NoneOption, |
| 103 | SaveMilestone, | 104 | SaveMilestone, |
| @@ -365,6 +366,8 @@ pub fn t(lang: Lang, key: K) -> &'static str { | |||
| 365 | (K::SaveAssignees, Lang::Tr) => "Atananları kaydet", | 366 | (K::SaveAssignees, Lang::Tr) => "Atananları kaydet", |
| 366 | (K::NoOneAssigned, Lang::En) => "No one assigned.", | 367 | (K::NoOneAssigned, Lang::En) => "No one assigned.", |
| 367 | (K::NoOneAssigned, Lang::Tr) => "Kimse atanmadı.", | 368 | (K::NoOneAssigned, Lang::Tr) => "Kimse atanmadı.", |
| 369 | + (K::AssignToMe, Lang::En) => "Assign to me", | ||
| 370 | + (K::AssignToMe, Lang::Tr) => "Bana ata", | ||
| 368 | (K::MilestoneBox, Lang::En) => "Milestone", | 371 | (K::MilestoneBox, Lang::En) => "Milestone", |
| 369 | (K::MilestoneBox, Lang::Tr) => "Kilometre taşı", | 372 | (K::MilestoneBox, Lang::Tr) => "Kilometre taşı", |
| 370 | (K::NoneOption, Lang::En) => "None", | 373 | (K::NoneOption, Lang::En) => "None", |
| @@ -990,6 +993,7 @@ mod tests { | |||
| 990 | K::CommaUsernames, | 993 | K::CommaUsernames, |
| 991 | K::SaveAssignees, | 994 | K::SaveAssignees, |
| 992 | K::NoOneAssigned, | 995 | K::NoOneAssigned, |
| 996 | + K::AssignToMe, | ||
| 993 | K::MilestoneBox, | 997 | K::MilestoneBox, |
| 994 | K::NoneOption, | 998 | K::NoneOption, |
| 995 | K::SaveMilestone, | 999 | K::SaveMilestone, |
crates/forge-web/src/i18n/needs.rsmodified+48 -0
| @@ -13,9 +13,34 @@ pub enum K { | |||
| 13 | ChangesRequested, | 13 | ChangesRequested, |
| 14 | Approved, | 14 | Approved, |
| 15 | AllReviewRequests, | 15 | AllReviewRequests, |
| 16 | + AllFailedRuns, | ||
| 17 | + AllYourPulls, | ||
| 18 | + AllAssignedIssues, | ||
| 19 | + AllMentions, | ||
| 20 | + BackToNeedsYou, | ||
| 16 | AllClear, | 21 | AllClear, |
| 17 | } | 22 | } |
| 18 | 23 | ||
| 24 | +/// Every key, for the coverage test. | ||
| 25 | +#[cfg(test)] | ||
| 26 | +pub const ALL: &[K] = &[ | ||
| 27 | + K::NeedsYou, | ||
| 28 | + K::FailedRuns, | ||
| 29 | + K::ReviewsRequested, | ||
| 30 | + K::YourPulls, | ||
| 31 | + K::AssignedIssues, | ||
| 32 | + K::Mentions, | ||
| 33 | + K::ChangesRequested, | ||
| 34 | + K::Approved, | ||
| 35 | + K::AllReviewRequests, | ||
| 36 | + K::AllFailedRuns, | ||
| 37 | + K::AllYourPulls, | ||
| 38 | + K::AllAssignedIssues, | ||
| 39 | + K::AllMentions, | ||
| 40 | + K::BackToNeedsYou, | ||
| 41 | + K::AllClear, | ||
| 42 | +]; | ||
| 43 | + | ||
| 19 | pub fn t(lang: Lang, key: K) -> &'static str { | 44 | pub fn t(lang: Lang, key: K) -> &'static str { |
| 20 | use K::*; | 45 | use K::*; |
| 21 | use Lang::*; | 46 | use Lang::*; |
| @@ -38,7 +63,30 @@ pub fn t(lang: Lang, key: K) -> &'static str { | |||
| 38 | (Approved, Tr) => "Onaylandı", | 63 | (Approved, Tr) => "Onaylandı", |
| 39 | (AllReviewRequests, En) => "All review requests", | 64 | (AllReviewRequests, En) => "All review requests", |
| 40 | (AllReviewRequests, Tr) => "Tüm inceleme istekleri", | 65 | (AllReviewRequests, Tr) => "Tüm inceleme istekleri", |
| 66 | + (AllFailedRuns, En) => "All failed runs", | ||
| 67 | + (AllFailedRuns, Tr) => "Tüm başarısız çalıştırmalar", | ||
| 68 | + (AllYourPulls, En) => "All your pull requests", | ||
| 69 | + (AllYourPulls, Tr) => "Tüm pull request'leriniz", | ||
| 70 | + (AllAssignedIssues, En) => "All assigned issues", | ||
| 71 | + (AllAssignedIssues, Tr) => "Size atanan tüm sorunlar", | ||
| 72 | + (AllMentions, En) => "All mentions", | ||
| 73 | + (AllMentions, Tr) => "Tüm bahsetmeler", | ||
| 74 | + (BackToNeedsYou, En) => "Back to Needs you", | ||
| 75 | + (BackToNeedsYou, Tr) => "Sizi bekleyenlere dön", | ||
| 41 | (AllClear, En) => "Nothing is waiting on you.", | 76 | (AllClear, En) => "Nothing is waiting on you.", |
| 42 | (AllClear, Tr) => "Sizi bekleyen bir şey yok.", | 77 | (AllClear, Tr) => "Sizi bekleyen bir şey yok.", |
| 43 | } | 78 | } |
| 44 | } | 79 | } |
| 80 | + | ||
| 81 | +#[cfg(test)] | ||
| 82 | +mod tests { | ||
| 83 | + use super::*; | ||
| 84 | + | ||
| 85 | + #[test] | ||
| 86 | + fn every_key_has_english_and_turkish() { | ||
| 87 | + for key in ALL { | ||
| 88 | + assert!(!t(Lang::En, *key).is_empty(), "{key:?} has no English"); | ||
| 89 | + assert!(!t(Lang::Tr, *key).is_empty(), "{key:?} has no Turkish"); | ||
| 90 | + } | ||
| 91 | + } | ||
| 92 | +} | ||
crates/forge-web/src/pages/ci_job.rsmodified+79 -13
| @@ -6,8 +6,9 @@ | |||
| 6 | //! keeps following it until the job is terminal and the file is read to its end. Artifacts are blobs | 6 | //! keeps following it until the job is terminal and the file is read to its end. Artifacts are blobs |
| 7 | //! under `ci/<artifact id>` and are always served as attachments. | 7 | //! under `ci/<artifact id>` and are always served as attachments. |
| 8 | 8 | ||
| 9 | +use std::collections::HashMap; | ||
| 9 | use std::path::{Path, PathBuf}; | 10 | use std::path::{Path, PathBuf}; |
| 10 | -use std::sync::Arc; | 11 | +use std::sync::{Arc, Mutex, OnceLock}; |
| 11 | use std::time::Duration; | 12 | use std::time::Duration; |
| 12 | 13 | ||
| 13 | use bytes::Bytes; | 14 | use bytes::Bytes; |
| @@ -35,7 +36,7 @@ use crate::i18n::{ | |||
| 35 | }; | 36 | }; |
| 36 | use crate::pages::ci_runs::{ | 37 | use crate::pages::ci_runs::{ |
| 37 | age_text, can_write, changed_event, duration_text, events_response, job_href, run_href, | 38 | age_text, can_write, changed_event, duration_text, events_response, job_href, run_href, |
| 38 | - state_text, | 39 | + state_text, strip_ansi, |
| 39 | }; | 40 | }; |
| 40 | use crate::pages::repo::repo_head; | 41 | use crate::pages::repo::repo_head; |
| 41 | use crate::pages::repo_ctx::{RepoCtx, RepoHead, load_repo, still_readable}; | 42 | use crate::pages::repo_ctx::{RepoCtx, RepoHead, load_repo, still_readable}; |
| @@ -88,16 +89,38 @@ pub(crate) struct Tail { | |||
| 88 | pub(crate) first_line: u64, | 89 | pub(crate) first_line: u64, |
| 89 | } | 90 | } |
| 90 | 91 | ||
| 92 | +/// Most logs the newline cache keeps. A full cache drops an arbitrary entry. | ||
| 93 | +const NEWLINE_CACHE_LIMIT: usize = 256; | ||
| 94 | + | ||
| 95 | +/// For each log, the offset up to which its newlines were last counted, and that count. | ||
| 96 | +fn newline_cache() -> &'static Mutex<HashMap<PathBuf, (u64, u64)>> { | ||
| 97 | + static CACHE: OnceLock<Mutex<HashMap<PathBuf, (u64, u64)>>> = OnceLock::new(); | ||
| 98 | + CACHE.get_or_init(|| Mutex::new(HashMap::new())) | ||
| 99 | +} | ||
| 100 | + | ||
| 91 | /// The number of newlines in the first `end` bytes of the file, so a cut log keeps true line numbers. | 101 | /// The number of newlines in the first `end` bytes of the file, so a cut log keeps true line numbers. |
| 102 | +/// Counting resumes from the cached count of this log when that count covers a prefix of `end`. | ||
| 103 | +/// Logs only grow, so a shorter file, or a cached offset past `end`, counts from zero. | ||
| 92 | async fn newlines_before(path: &Path, end: u64) -> Result<u64> { | 104 | async fn newlines_before(path: &Path, end: u64) -> Result<u64> { |
| 93 | let mut file = tokio::fs::File::open(path) | 105 | let mut file = tokio::fs::File::open(path) |
| 94 | .await | 106 | .await |
| 95 | .map_err(forge_core::Error::Io)?; | 107 | .map_err(forge_core::Error::Io)?; |
| 96 | - let mut left = end; | 108 | + let len = file.metadata().await.map_err(forge_core::Error::Io)?.len(); |
| 97 | - let mut count = 0u64; | 109 | + let cached = newline_cache() |
| 110 | + .lock() | ||
| 111 | + .expect("newline cache") | ||
| 112 | + .get(path) | ||
| 113 | + .copied(); | ||
| 114 | + let (mut at, mut count) = match cached { | ||
| 115 | + Some((offset, count)) if offset <= end && offset <= len => (offset, count), | ||
| 116 | + _ => (0, 0), | ||
| 117 | + }; | ||
| 118 | + file.seek(SeekFrom::Start(at)) | ||
| 119 | + .await | ||
| 120 | + .map_err(forge_core::Error::Io)?; | ||
| 98 | let mut buf = vec![0u8; CHUNK_BYTES]; | 121 | let mut buf = vec![0u8; CHUNK_BYTES]; |
| 99 | - while left > 0 { | 122 | + while at < end { |
| 100 | - let want = usize::try_from(left).map_or(CHUNK_BYTES, |n| n.min(CHUNK_BYTES)); | 123 | + let want = usize::try_from(end - at).map_or(CHUNK_BYTES, |n| n.min(CHUNK_BYTES)); |
| 101 | let n = file | 124 | let n = file |
| 102 | .read(&mut buf[..want]) | 125 | .read(&mut buf[..want]) |
| 103 | .await | 126 | .await |
| @@ -106,8 +129,16 @@ async fn newlines_before(path: &Path, end: u64) -> Result<u64> { | |||
| 106 | break; | 129 | break; |
| 107 | } | 130 | } |
| 108 | count += buf[..n].iter().filter(|byte| **byte == b'\n').count() as u64; | 131 | count += buf[..n].iter().filter(|byte| **byte == b'\n').count() as u64; |
| 109 | - left -= n as u64; | 132 | + at += n as u64; |
| 110 | } | 133 | } |
| 134 | + let mut map = newline_cache().lock().expect("newline cache"); | ||
| 135 | + if !map.contains_key(path) | ||
| 136 | + && map.len() >= NEWLINE_CACHE_LIMIT | ||
| 137 | + && let Some(old) = map.keys().next().cloned() | ||
| 138 | + { | ||
| 139 | + map.remove(&old); | ||
| 140 | + } | ||
| 141 | + map.insert(path.to_path_buf(), (at, count)); | ||
| 111 | Ok(count) | 142 | Ok(count) |
| 112 | } | 143 | } |
| 113 | 144 | ||
| @@ -348,7 +379,7 @@ async fn job_body( | |||
| 348 | <p class="muted small"><a href=(job.run_href.as_str())>(g::t(lang, K::RunNumber)) (job.run_number)</a></p> | 379 | <p class="muted small"><a href=(job.run_href.as_str())>(g::t(lang, K::RunNumber)) (job.run_number)</a></p> |
| 349 | <div class="ci-job-grid fit-pane"> | 380 | <div class="ci-job-grid fit-pane"> |
| 350 | <section class="card"> | 381 | <section class="card"> |
| 351 | - <h2>(job.name.as_str())</h2> | 382 | + <h2 class="ci-job-title">(job.name.as_str())</h2> |
| 352 | <p class="muted small"> | 383 | <p class="muted small"> |
| 353 | <span class=(job.state_class.as_str())>(job.state.as_str())</span> | 384 | <span class=(job.state_class.as_str())>(job.state.as_str())</span> |
| 354 | if !job.runner.is_empty() { | 385 | if !job.runner.is_empty() { |
| @@ -545,6 +576,9 @@ async fn job_events(cx: &Cx) -> Result<Response> { | |||
| 545 | primed: false, | 576 | primed: false, |
| 546 | pending_fingerprint: None, | 577 | pending_fingerprint: None, |
| 547 | pending_log: None, | 578 | pending_log: None, |
| 579 | + plain: uri(cx) | ||
| 580 | + .query() | ||
| 581 | + .is_some_and(|query| query.split('&').any(|pair| pair == "plain=1")), | ||
| 548 | viewer: ctx.viewer.as_ref().map(|(user, _)| user.clone()), | 582 | viewer: ctx.viewer.as_ref().map(|(user, _)| user.clone()), |
| 549 | repo_id: ctx.repo.id.clone(), | 583 | repo_id: ctx.repo.id.clone(), |
| 550 | }; | 584 | }; |
| @@ -578,6 +612,8 @@ struct JobFollow { | |||
| 578 | pending_fingerprint: Option<String>, | 612 | pending_fingerprint: Option<String>, |
| 579 | /// The text and the offset past it. | 613 | /// The text and the offset past it. |
| 580 | pending_log: Option<(String, u64)>, | 614 | pending_log: Option<(String, u64)>, |
| 615 | + /// `?plain=1`: the log lines are sent with their ANSI sequences stripped (the run page's log). | ||
| 616 | + plain: bool, | ||
| 581 | /// The viewer the stream opened for, and the repo, so each send is checked for read access. | 617 | /// The viewer the stream opened for, and the repo, so each send is checked for read access. |
| 582 | viewer: Option<User>, | 618 | viewer: Option<User>, |
| 583 | repo_id: String, | 619 | repo_id: String, |
| @@ -595,6 +631,11 @@ fn job_stream(follow: JobFollow) -> impl Stream<Item = Result<Event>> + Send + ' | |||
| 595 | return Some((changed_event(fingerprint), f)); | 631 | return Some((changed_event(fingerprint), f)); |
| 596 | } | 632 | } |
| 597 | if let Some((text, end)) = f.pending_log.take() { | 633 | if let Some((text, end)) = f.pending_log.take() { |
| 634 | + let text = if f.plain { | ||
| 635 | + text.split('\n').map(strip_ansi).collect::<Vec<_>>().join("\n") | ||
| 636 | + } else { | ||
| 637 | + text | ||
| 638 | + }; | ||
| 598 | let event = Event::new().event("log").data(text).id(end.to_string()); | 639 | let event = Event::new().event("log").data(text).id(end.to_string()); |
| 599 | return Some((Ok(event), f)); | 640 | return Some((Ok(event), f)); |
| 600 | } | 641 | } |
| @@ -617,7 +658,7 @@ fn job_stream(follow: JobFollow) -> impl Stream<Item = Result<Event>> + Send + ' | |||
| 617 | f.fingerprint = Some(fingerprint.clone()); | 658 | f.fingerprint = Some(fingerprint.clone()); |
| 618 | f.pending_fingerprint = Some(fingerprint); | 659 | f.pending_fingerprint = Some(fingerprint); |
| 619 | } | 660 | } |
| 620 | - match read_log(&f.path, f.offset).await { | 661 | + match read_log(&f.path, f.offset, f.plain).await { |
| 621 | Ok(Some((text, end))) => { | 662 | Ok(Some((text, end))) => { |
| 622 | f.offset = end; | 663 | f.offset = end; |
| 623 | f.more = true; | 664 | f.more = true; |
| @@ -634,8 +675,14 @@ fn job_stream(follow: JobFollow) -> impl Stream<Item = Result<Event>> + Send + ' | |||
| 634 | } | 675 | } |
| 635 | 676 | ||
| 636 | /// The whole text of the log from `offset`, at most `LOG_EVENT_BYTES`, and the offset past it. None | 677 | /// The whole text of the log from `offset`, at most `LOG_EVENT_BYTES`, and the offset past it. None |
| 637 | -/// when there is nothing new (no file, no bytes past `offset`, or only part of a character). | 678 | +/// when there is nothing new (no file, no bytes past `offset`, or only part of a character). With |
| 638 | -async fn read_log(path: &Path, offset: u64) -> std::io::Result<Option<(String, u64)>> { | 679 | +/// `whole_lines`, the read ends at the last newline, so an ANSI sequence is never cut in two by a |
| 680 | +/// chunk; the job page's render at the end of the job shows a last line with no newline. | ||
| 681 | +async fn read_log( | ||
| 682 | + path: &Path, | ||
| 683 | + offset: u64, | ||
| 684 | + whole_lines: bool, | ||
| 685 | +) -> std::io::Result<Option<(String, u64)>> { | ||
| 639 | let mut file = match tokio::fs::File::open(path).await { | 686 | let mut file = match tokio::fs::File::open(path).await { |
| 640 | Ok(file) => file, | 687 | Ok(file) => file, |
| 641 | Err(e) if e.kind() == std::io::ErrorKind::NotFound => return Ok(None), | 688 | Err(e) if e.kind() == std::io::ErrorKind::NotFound => return Ok(None), |
| @@ -647,7 +694,12 @@ async fn read_log(path: &Path, offset: u64) -> std::io::Result<Option<(String, u | |||
| 647 | .take(LOG_EVENT_BYTES) | 694 | .take(LOG_EVENT_BYTES) |
| 648 | .read_to_end(&mut buf) | 695 | .read_to_end(&mut buf) |
| 649 | .await?; | 696 | .await?; |
| 650 | - let whole = whole_utf8_len(&buf); | 697 | + let mut whole = whole_utf8_len(&buf); |
| 698 | + if whole_lines && let Some(end) = buf[..whole].iter().rposition(|byte| *byte == b'\n') { | ||
| 699 | + whole = end + 1; | ||
| 700 | + } else if whole_lines && (buf.len() as u64) < LOG_EVENT_BYTES { | ||
| 701 | + return Ok(None); | ||
| 702 | + } | ||
| 651 | if whole == 0 { | 703 | if whole == 0 { |
| 652 | return Ok(None); | 704 | return Ok(None); |
| 653 | } | 705 | } |
| @@ -750,7 +802,21 @@ fn artifact_response( | |||
| 750 | 802 | ||
| 751 | #[cfg(test)] | 803 | #[cfg(test)] |
| 752 | mod tests { | 804 | mod tests { |
| 753 | - use super::job_fingerprint; | 805 | + use super::{job_fingerprint, newlines_before}; |
| 806 | + | ||
| 807 | + #[tokio::test] | ||
| 808 | + async fn a_grown_log_counts_the_same_as_a_fresh_count() { | ||
| 809 | + let dir = tempfile::tempdir().unwrap(); | ||
| 810 | + let path = dir.path().join("job.log"); | ||
| 811 | + let mut text = b"one\ntwo\nthree\n".to_vec(); | ||
| 812 | + std::fs::write(&path, &text).unwrap(); | ||
| 813 | + assert_eq!(newlines_before(&path, 8).await.unwrap(), 2); | ||
| 814 | + text.extend_from_slice(b"four\nfive\n"); | ||
| 815 | + std::fs::write(&path, &text).unwrap(); | ||
| 816 | + let end = text.len() as u64; | ||
| 817 | + let fresh = text.iter().filter(|byte| **byte == b'\n').count() as u64; | ||
| 818 | + assert_eq!(newlines_before(&path, end).await.unwrap(), fresh); | ||
| 819 | + } | ||
| 754 | 820 | ||
| 755 | #[test] | 821 | #[test] |
| 756 | fn an_artifact_or_the_log_changing_changes_the_fingerprint() { | 822 | fn an_artifact_or_the_log_changing_changes_the_fingerprint() { |
crates/forge-web/src/pages/ci_runs.rsmodified+26 -9
| @@ -349,6 +349,9 @@ struct RunRow { | |||
| 349 | scale: String, | 349 | scale: String, |
| 350 | /// The expected total of a running run, from its past runs. None when no estimate can be made. | 350 | /// The expected total of a running run, from its past runs. None when no estimate can be made. |
| 351 | est: Option<Est>, | 351 | est: Option<Est>, |
| 352 | + /// The POST target that reruns this run and the writer's CSRF token. Set for a writer once the run | ||
| 353 | + /// has finished, as the run page's Re-run button is. | ||
| 354 | + rerun: Option<(String, String)>, | ||
| 352 | meta: RowMeta, | 355 | meta: RowMeta, |
| 353 | } | 356 | } |
| 354 | 357 | ||
| @@ -468,6 +471,8 @@ struct JobLog { | |||
| 468 | name: String, | 471 | name: String, |
| 469 | href: String, | 472 | href: String, |
| 470 | log_href: String, | 473 | log_href: String, |
| 474 | + /// The job's event stream (plain lines) while the job is not finished; None once it is. | ||
| 475 | + live: Option<String>, | ||
| 471 | /// The POST target that runs this job again, for a writer once the job has finished. | 476 | /// The POST target that runs this job again, for a writer once the job has finished. |
| 472 | rerun: Option<String>, | 477 | rerun: Option<String>, |
| 473 | text: String, | 478 | text: String, |
| @@ -1409,6 +1414,14 @@ async fn runs_split(cx: &Cx, number: Option<&str>, job: Option<&str>) -> Result< | |||
| 1409 | run_href(&title, number) | 1414 | run_href(&title, number) |
| 1410 | } | 1415 | } |
| 1411 | }; | 1416 | }; |
| 1417 | + let writer = can_write(&ctx); | ||
| 1418 | + let csrf = if writer { | ||
| 1419 | + current_user(cx) | ||
| 1420 | + .await? | ||
| 1421 | + .map(|(_, session)| session.csrf_token.clone()) | ||
| 1422 | + } else { | ||
| 1423 | + None | ||
| 1424 | + }; | ||
| 1412 | let rows: Vec<RunRow> = runs | 1425 | let rows: Vec<RunRow> = runs |
| 1413 | .iter() | 1426 | .iter() |
| 1414 | .zip(&timings) | 1427 | .zip(&timings) |
| @@ -1458,18 +1471,15 @@ async fn runs_split(cx: &Cx, number: Option<&str>, job: Option<&str>) -> Result< | |||
| 1458 | String::new() | 1471 | String::new() |
| 1459 | }, | 1472 | }, |
| 1460 | est, | 1473 | est, |
| 1474 | + // The same condition as the run page's Re-run button: a writer, and a finished run. | ||
| 1475 | + rerun: csrf | ||
| 1476 | + .as_ref() | ||
| 1477 | + .filter(|_| run_finished(&run.state)) | ||
| 1478 | + .map(|token| (format!("{}/rerun", run_href(&title, run.number)), token.clone())), | ||
| 1461 | meta: row_meta(run, jobs, &actor, lang), | 1479 | meta: row_meta(run, jobs, &actor, lang), |
| 1462 | } | 1480 | } |
| 1463 | }) | 1481 | }) |
| 1464 | .collect(); | 1482 | .collect(); |
| 1465 | - let writer = can_write(&ctx); | ||
| 1466 | - let csrf = if writer { | ||
| 1467 | - current_user(cx) | ||
| 1468 | - .await? | ||
| 1469 | - .map(|(_, session)| session.csrf_token.clone()) | ||
| 1470 | - } else { | ||
| 1471 | - None | ||
| 1472 | - }; | ||
| 1473 | let manual = if writer { | 1483 | let manual = if writer { |
| 1474 | let refs = load_refs(ctx.path.clone()).await?; | 1484 | let refs = load_refs(ctx.path.clone()).await?; |
| 1475 | Some(ManualRun { | 1485 | Some(ManualRun { |
| @@ -1653,6 +1663,7 @@ async fn run_detail( | |||
| 1653 | Some(JobLog { | 1663 | Some(JobLog { |
| 1654 | name: job.name.clone(), | 1664 | name: job.name.clone(), |
| 1655 | log_href: format!("{href}/log.txt"), | 1665 | log_href: format!("{href}/log.txt"), |
| 1666 | + live: (!job.state.is_terminal()).then(|| format!("{href}/events?plain=1")), | ||
| 1656 | href, | 1667 | href, |
| 1657 | rerun: lines[index].rerun.clone(), | 1668 | rerun: lines[index].rerun.clone(), |
| 1658 | // Line for line, so line numbers and the byte offset of the stream still match. | 1669 | // Line for line, so line numbers and the byte offset of the stream still match. |
| @@ -1862,6 +1873,12 @@ async fn runs_body( | |||
| 1862 | </span> | 1873 | </span> |
| 1863 | <span class="ci-row-meta">(row.meta.head.as_str())<time datetime=(row.meta.at.as_str()) data-rel="true">(row.meta.age.as_str())</time>(row.meta.hint.as_str())</span> | 1874 | <span class="ci-row-meta">(row.meta.head.as_str())<time datetime=(row.meta.at.as_str()) data-rel="true">(row.meta.age.as_str())</time>(row.meta.hint.as_str())</span> |
| 1864 | </a> | 1875 | </a> |
| 1876 | + if let Some((action, token)) = row.rerun.as_ref() { | ||
| 1877 | + <form method="post" action=(action.as_str()) class="ci-row-rerun-form" data-kb-rerun=""> | ||
| 1878 | + <input type="hidden" name="csrf" value=(token.as_str())> | ||
| 1879 | + <button type="submit" class="ci-row-rerun">(g::t(lang, K::Rerun))</button> | ||
| 1880 | + </form> | ||
| 1881 | + } | ||
| 1865 | </li> | 1882 | </li> |
| 1866 | } | 1883 | } |
| 1867 | </ul> | 1884 | </ul> |
| @@ -2240,7 +2257,7 @@ async fn run_body( | |||
| 2240 | if log.truncated { | 2257 | if log.truncated { |
| 2241 | <p class="muted small">(g::t(lang, K::LogTruncated))</p> | 2258 | <p class="muted small">(g::t(lang, K::LogTruncated))</p> |
| 2242 | } | 2259 | } |
| 2243 | - <pre class="ci-log ci-tl-code" data-live-log="true" data-offset=(log.offset.as_str()) data-first=(log.first_line.as_str())>(log.text.as_str())</pre> | 2260 | + <pre class="ci-log ci-tl-code" data-live=(log.live.as_deref()) data-live-log="true" data-offset=(log.offset.as_str()) data-first=(log.first_line.as_str())>(log.text.as_str())</pre> |
| 2244 | } else { | 2261 | } else { |
| 2245 | <p class="muted">(g::t(lang, K::NoJobs))</p> | 2262 | <p class="muted">(g::t(lang, K::NoJobs))</p> |
| 2246 | } | 2263 | } |
crates/forge-web/src/pages/issue_parts.rsmodified+19 -1
| @@ -1080,12 +1080,20 @@ pub(crate) async fn assignees_box( | |||
| 1080 | action: String, | 1080 | action: String, |
| 1081 | csrf: String, | 1081 | csrf: String, |
| 1082 | names: Vec<String>, | 1082 | names: Vec<String>, |
| 1083 | + assign_next: Option<String>, | ||
| 1083 | ) -> Result<impl View> { | 1084 | ) -> Result<impl View> { |
| 1084 | let text = names.join(", "); | 1085 | let text = names.join(", "); |
| 1085 | Ok(view! { | 1086 | Ok(view! { |
| 1086 | <section class="issue-side-section"> | 1087 | <section class="issue-side-section"> |
| 1087 | <h2>(g::t(lang, K::Assignees))</h2> | 1088 | <h2>(g::t(lang, K::Assignees))</h2> |
| 1088 | if write { | 1089 | if write { |
| 1090 | + if let Some(next) = assign_next { | ||
| 1091 | + <form method="post" action=(action.as_str()) class="assign-me-form"> | ||
| 1092 | + <input type="hidden" name="csrf" value=(csrf.as_str())> | ||
| 1093 | + <input type="hidden" name="assignees" value=(next.as_str())> | ||
| 1094 | + <button type="submit" class="link-button" data-palette-action="post">(g::t(lang, K::AssignToMe))</button> | ||
| 1095 | + </form> | ||
| 1096 | + } | ||
| 1089 | <form method="post" action=(action.as_str()) class="stack"> | 1097 | <form method="post" action=(action.as_str()) class="stack"> |
| 1090 | <input type="hidden" name="csrf" value=(csrf.as_str())> | 1098 | <input type="hidden" name="csrf" value=(csrf.as_str())> |
| 1091 | <input type="text" name="assignees" value=(text.as_str()) autocomplete="off" spellcheck="false" aria-label=(g::t(lang, K::Assignees))> | 1099 | <input type="text" name="assignees" value=(text.as_str()) autocomplete="off" spellcheck="false" aria-label=(g::t(lang, K::Assignees))> |
| @@ -1212,6 +1220,7 @@ pub(crate) async fn item_sidebar( | |||
| 1212 | write: bool, | 1220 | write: bool, |
| 1213 | base: String, | 1221 | base: String, |
| 1214 | csrf: String, | 1222 | csrf: String, |
| 1223 | + viewer: Option<String>, | ||
| 1215 | sidebar: Sidebar, | 1224 | sidebar: Sidebar, |
| 1216 | notify: Option<NotifyBox>, | 1225 | notify: Option<NotifyBox>, |
| 1217 | ) -> Result<impl View> { | 1226 | ) -> Result<impl View> { |
| @@ -1224,13 +1233,22 @@ pub(crate) async fn item_sidebar( | |||
| 1224 | locked, | 1233 | locked, |
| 1225 | lock_reason, | 1234 | lock_reason, |
| 1226 | } = sidebar; | 1235 | } = sidebar; |
| 1236 | + // "Assign to me" posts the whole list with the viewer added, since the route replaces it. | ||
| 1237 | + let assign_next = match viewer { | ||
| 1238 | + Some(me) if write && !assignees.iter().any(|a| *a == me) => { | ||
| 1239 | + let mut next = assignees.clone(); | ||
| 1240 | + next.push(me); | ||
| 1241 | + Some(next.join(", ")) | ||
| 1242 | + } | ||
| 1243 | + _ => None, | ||
| 1244 | + }; | ||
| 1227 | let labels_action = format!("{base}/labels"); | 1245 | let labels_action = format!("{base}/labels"); |
| 1228 | let assignees_action = format!("{base}/assignees"); | 1246 | let assignees_action = format!("{base}/assignees"); |
| 1229 | let milestone_action = format!("{base}/milestone"); | 1247 | let milestone_action = format!("{base}/milestone"); |
| 1230 | let lock_action = format!("{base}/lock"); | 1248 | let lock_action = format!("{base}/lock"); |
| 1231 | Ok(view! { | 1249 | Ok(view! { |
| 1232 | labels_box(lang: lang, write: write, action: labels_action, csrf: csrf.clone(), labels: labels) | 1250 | labels_box(lang: lang, write: write, action: labels_action, csrf: csrf.clone(), labels: labels) |
| 1233 | - assignees_box(lang: lang, write: write, action: assignees_action, csrf: csrf.clone(), names: assignees) | 1251 | + assignees_box(lang: lang, write: write, action: assignees_action, csrf: csrf.clone(), names: assignees, assign_next: assign_next) |
| 1234 | milestone_box(lang: lang, write: write, action: milestone_action, csrf: csrf.clone(), | 1252 | milestone_box(lang: lang, write: write, action: milestone_action, csrf: csrf.clone(), |
| 1235 | options: milestones, current: current_milestone, none_selected: none_selected) | 1253 | options: milestones, current: current_milestone, none_selected: none_selected) |
| 1236 | lock_box(lang: lang, write: write, action: lock_action, csrf: csrf.clone(), locked: locked, reason: lock_reason) | 1254 | lock_box(lang: lang, write: write, action: lock_action, csrf: csrf.clone(), locked: locked, reason: lock_reason) |
crates/forge-web/src/pages/issue_view.rsmodified+2 -1
| @@ -56,6 +56,7 @@ async fn issue_page( | |||
| 56 | 56 | ||
| 57 | let discussion = load_discussion(lang, state, &ctx, &issue, ItemKind::Issue, "").await?; | 57 | let discussion = load_discussion(lang, state, &ctx, &issue, ItemKind::Issue, "").await?; |
| 58 | let sidebar = load_sidebar(state, &ctx.repo.id, &issue).await?; | 58 | let sidebar = load_sidebar(state, &ctx.repo.id, &issue).await?; |
| 59 | + let viewer_login = ctx.viewer.as_ref().map(|(u, _)| u.username.clone()); | ||
| 59 | let pinned = state.store.is_pinned(&ctx.repo.id, &issue.id).await?; | 60 | let pinned = state.store.is_pinned(&ctx.repo.id, &issue.id).await?; |
| 60 | let pin_action = format!("{issue_href}/pin"); | 61 | let pin_action = format!("{issue_href}/pin"); |
| 61 | let notify = notify_box_for(state, &ctx, lang, &issue.id, &issue_href).await?; | 62 | let notify = notify_box_for(state, &ctx, lang, &issue.id, &issue_href).await?; |
| @@ -123,7 +124,7 @@ async fn issue_page( | |||
| 123 | </div> | 124 | </div> |
| 124 | <aside class="issue-sidebar fit-pane"> | 125 | <aside class="issue-sidebar fit-pane"> |
| 125 | pin_box(lang: lang, write: write_meta, pinned: pinned, action: pin_action.clone(), csrf: csrf.clone()) | 126 | pin_box(lang: lang, write: write_meta, pinned: pinned, action: pin_action.clone(), csrf: csrf.clone()) |
| 126 | - item_sidebar(lang: lang, write: write_meta, base: issue_href.clone(), csrf: csrf.clone(), sidebar: sidebar, notify: notify) | 127 | + item_sidebar(lang: lang, write: write_meta, base: issue_href.clone(), csrf: csrf.clone(), viewer: viewer_login, sidebar: sidebar, notify: notify) |
| 127 | </aside> | 128 | </aside> |
| 128 | </div> | 129 | </div> |
| 129 | ) | 130 | ) |
crates/forge-web/src/pages/needs_you.rsmodified+287 -107
| @@ -2,15 +2,16 @@ | |||
| 2 | //! when empty: their failed CI runs, review requests, their own pull requests with a review verdict, | 2 | //! when empty: their failed CI runs, review requests, their own pull requests with a review verdict, |
| 3 | //! assigned issues and unread mentions. Every row comes from a store query that applies the viewer's | 3 | //! assigned issues and unread mentions. Every row comes from a store query that applies the viewer's |
| 4 | //! repo access, except review requests, which are checked per repo here as `/review-requests` does. | 4 | //! repo access, except review requests, which are checked per repo here as `/review-requests` does. |
| 5 | -//! `/needs-you/events` wakes the page on the viewer's review-request and inbox topics. | 5 | +//! `?section=<slug>` shows one section as a full list, 15 rows a page. `/needs-you/events` wakes the |
| 6 | +//! page on the viewer's review-request and inbox topics. | ||
| 6 | 7 | ||
| 7 | use forge_core::authz::{Action, authorize}; | 8 | use forge_core::authz::{Action, authorize}; |
| 8 | use forge_core::store::needs::Verdict; | 9 | use forge_core::store::needs::Verdict; |
| 9 | -use forge_core::{Reason, User}; | 10 | +use forge_core::User; |
| 10 | use topcoat::Result; | 11 | use topcoat::Result; |
| 11 | use topcoat::context::{Cx, app_context}; | 12 | use topcoat::context::{Cx, app_context}; |
| 12 | use topcoat::router::response::Response; | 13 | use topcoat::router::response::Response; |
| 13 | -use topcoat::router::{Body, StatusCode, page, route}; | 14 | +use topcoat::router::{Body, StatusCode, page, query_params, route}; |
| 14 | use topcoat::view::{View, component, view}; | 15 | use topcoat::view::{View, component, view}; |
| 15 | 16 | ||
| 16 | use crate::auth::{current_user, require_user}; | 17 | use crate::auth::{current_user, require_user}; |
| @@ -20,13 +21,168 @@ use crate::i18n::{self, Lang}; | |||
| 20 | use crate::live::{Topic, stream_wakes}; | 21 | use crate::live::{Topic, stream_wakes}; |
| 21 | use crate::pages::ci_runs::run_href; | 22 | use crate::pages::ci_runs::run_href; |
| 22 | use crate::state::AppState; | 23 | use crate::state::AppState; |
| 24 | +use crate::views::repo_list::{PageLink, pager, pager_links}; | ||
| 23 | use crate::views::{empty_state, rel_time, repo_href, shell}; | 25 | use crate::views::{empty_state, rel_time, repo_href, shell}; |
| 24 | 26 | ||
| 25 | -/// Most rows one section lists. | 27 | +/// Most rows one section lists on the overview. |
| 26 | const SECTION_ROWS: usize = 8; | 28 | const SECTION_ROWS: usize = 8; |
| 27 | 29 | ||
| 28 | -/// How many waiting inbox rows are read before the mentions are picked out of them. | 30 | +/// Rows on one page of a section's full list. |
| 29 | -const WAITING_READ: u64 = 200; | 31 | +const PER_PAGE: u64 = 15; |
| 32 | + | ||
| 33 | +#[query_params(error = bad_request)] | ||
| 34 | +struct NeedsQuery { | ||
| 35 | + section: Option<String>, | ||
| 36 | + page: Option<String>, | ||
| 37 | +} | ||
| 38 | + | ||
| 39 | +/// The sections that have a full list at `?section=<slug>`. | ||
| 40 | +#[derive(Clone, Copy)] | ||
| 41 | +enum Section { | ||
| 42 | + Runs, | ||
| 43 | + Pulls, | ||
| 44 | + Issues, | ||
| 45 | + Mentions, | ||
| 46 | +} | ||
| 47 | + | ||
| 48 | +impl Section { | ||
| 49 | + /// The section a `section` query value names. Anything else is not a section. | ||
| 50 | + fn parse(raw: &str) -> Option<Self> { | ||
| 51 | + match raw { | ||
| 52 | + "runs" => Some(Self::Runs), | ||
| 53 | + "pulls" => Some(Self::Pulls), | ||
| 54 | + "issues" => Some(Self::Issues), | ||
| 55 | + "mentions" => Some(Self::Mentions), | ||
| 56 | + _ => None, | ||
| 57 | + } | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + fn slug(self) -> &'static str { | ||
| 61 | + match self { | ||
| 62 | + Self::Runs => "runs", | ||
| 63 | + Self::Pulls => "pulls", | ||
| 64 | + Self::Issues => "issues", | ||
| 65 | + Self::Mentions => "mentions", | ||
| 66 | + } | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + /// The overview's full-list link for this section. | ||
| 70 | + fn href(self) -> &'static str { | ||
| 71 | + match self { | ||
| 72 | + Self::Runs => "/needs-you?section=runs", | ||
| 73 | + Self::Pulls => "/needs-you?section=pulls", | ||
| 74 | + Self::Issues => "/needs-you?section=issues", | ||
| 75 | + Self::Mentions => "/needs-you?section=mentions", | ||
| 76 | + } | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + fn heading(self) -> K { | ||
| 80 | + match self { | ||
| 81 | + Self::Runs => K::FailedRuns, | ||
| 82 | + Self::Pulls => K::YourPulls, | ||
| 83 | + Self::Issues => K::AssignedIssues, | ||
| 84 | + Self::Mentions => K::Mentions, | ||
| 85 | + } | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + fn all_key(self) -> K { | ||
| 89 | + match self { | ||
| 90 | + Self::Runs => K::AllFailedRuns, | ||
| 91 | + Self::Pulls => K::AllYourPulls, | ||
| 92 | + Self::Issues => K::AllAssignedIssues, | ||
| 93 | + Self::Mentions => K::AllMentions, | ||
| 94 | + } | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + /// How many rows the section has in all, for its pager. | ||
| 98 | + async fn total(self, state: &AppState, user_id: &str) -> Result<u64> { | ||
| 99 | + Ok(match self { | ||
| 100 | + Self::Runs => state.store.failing_runs_total(user_id).await?, | ||
| 101 | + Self::Pulls => state.store.own_pulls_total(user_id).await?, | ||
| 102 | + Self::Issues => state.store.assigned_issues_total(user_id).await?, | ||
| 103 | + Self::Mentions => state.store.mentions_total(user_id).await?, | ||
| 104 | + }) | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + /// One page of the section's rows, newest first. | ||
| 108 | + async fn rows( | ||
| 109 | + self, | ||
| 110 | + state: &AppState, | ||
| 111 | + user: &User, | ||
| 112 | + lang: Lang, | ||
| 113 | + limit: i64, | ||
| 114 | + offset: i64, | ||
| 115 | + ) -> Result<Vec<NeedRow>> { | ||
| 116 | + Ok(match self { | ||
| 117 | + Self::Runs => state | ||
| 118 | + .store | ||
| 119 | + .failing_runs(&user.id, limit, offset) | ||
| 120 | + .await? | ||
| 121 | + .iter() | ||
| 122 | + .map(|run| { | ||
| 123 | + let title = format!("{}/{}", run.owner, run.repo); | ||
| 124 | + NeedRow { | ||
| 125 | + href: run_href(&title, run.number), | ||
| 126 | + title: format!("{title} #{}", run.number), | ||
| 127 | + detail: run.git_ref.clone(), | ||
| 128 | + badge: None, | ||
| 129 | + stamp: run.created_at.clone(), | ||
| 130 | + } | ||
| 131 | + }) | ||
| 132 | + .collect(), | ||
| 133 | + Self::Pulls => state | ||
| 134 | + .store | ||
| 135 | + .own_pulls_with_verdict(&user.id, limit, offset) | ||
| 136 | + .await? | ||
| 137 | + .iter() | ||
| 138 | + .map(|pull| NeedRow { | ||
| 139 | + href: repo_href(&pull.owner, &pull.repo, "pulls", &pull.number.to_string()), | ||
| 140 | + title: pull.title.clone(), | ||
| 141 | + detail: format!("{}/{} #{}", pull.owner, pull.repo, pull.number), | ||
| 142 | + badge: Some(match pull.verdict { | ||
| 143 | + Verdict::ChangesRequested => ni::t(lang, K::ChangesRequested), | ||
| 144 | + Verdict::Approved => ni::t(lang, K::Approved), | ||
| 145 | + }), | ||
| 146 | + stamp: pull.updated_at.clone(), | ||
| 147 | + }) | ||
| 148 | + .collect(), | ||
| 149 | + Self::Issues => state | ||
| 150 | + .store | ||
| 151 | + .assigned_issues(&user.id, limit, offset) | ||
| 152 | + .await? | ||
| 153 | + .iter() | ||
| 154 | + .map(|issue| NeedRow { | ||
| 155 | + href: repo_href( | ||
| 156 | + &issue.owner, | ||
| 157 | + &issue.repo, | ||
| 158 | + "issues", | ||
| 159 | + &issue.number.to_string(), | ||
| 160 | + ), | ||
| 161 | + title: issue.title.clone(), | ||
| 162 | + detail: format!("{}/{} #{}", issue.owner, issue.repo, issue.number), | ||
| 163 | + badge: None, | ||
| 164 | + stamp: issue.updated_at.clone(), | ||
| 165 | + }) | ||
| 166 | + .collect(), | ||
| 167 | + Self::Mentions => state | ||
| 168 | + .store | ||
| 169 | + .mentions_waiting(&user.id, limit, offset) | ||
| 170 | + .await? | ||
| 171 | + .iter() | ||
| 172 | + .map(|item| { | ||
| 173 | + let section = if item.is_pull { "pulls" } else { "issues" }; | ||
| 174 | + NeedRow { | ||
| 175 | + href: repo_href(&item.owner, &item.repo, section, &item.number.to_string()), | ||
| 176 | + title: item.title.clone(), | ||
| 177 | + detail: format!("{}/{} #{}", item.owner, item.repo, item.number), | ||
| 178 | + badge: None, | ||
| 179 | + stamp: item.updated_at.clone(), | ||
| 180 | + } | ||
| 181 | + }) | ||
| 182 | + .collect(), | ||
| 183 | + }) | ||
| 184 | + } | ||
| 185 | +} | ||
| 30 | 186 | ||
| 31 | /// One row of a section. | 187 | /// One row of a section. |
| 32 | pub(crate) struct NeedRow { | 188 | pub(crate) struct NeedRow { |
| @@ -37,38 +193,56 @@ pub(crate) struct NeedRow { | |||
| 37 | stamp: String, | 193 | stamp: String, |
| 38 | } | 194 | } |
| 39 | 195 | ||
| 40 | -/// One section: its heading, at most `SECTION_ROWS` rows, and the link to its full list if it has one. | 196 | +/// The pager under a full list: the page shown, the page count and the links from `pager_links`. |
| 197 | +pub(crate) struct NeedPager { | ||
| 198 | + page: u64, | ||
| 199 | + pages: u64, | ||
| 200 | + links: Vec<PageLink>, | ||
| 201 | + prev: Option<String>, | ||
| 202 | + next: Option<String>, | ||
| 203 | +} | ||
| 204 | + | ||
| 205 | +impl NeedPager { | ||
| 206 | + /// The pager of an overview section, which has none: one page, so the pager shows nothing. | ||
| 207 | + fn single() -> Self { | ||
| 208 | + Self { | ||
| 209 | + page: 1, | ||
| 210 | + pages: 1, | ||
| 211 | + links: Vec::new(), | ||
| 212 | + prev: None, | ||
| 213 | + next: None, | ||
| 214 | + } | ||
| 215 | + } | ||
| 216 | +} | ||
| 217 | + | ||
| 218 | +/// One section: its heading, its rows, the link to its full list if it has one, and its pager. | ||
| 41 | pub(crate) struct NeedSection { | 219 | pub(crate) struct NeedSection { |
| 42 | heading: &'static str, | 220 | heading: &'static str, |
| 43 | more: Option<(&'static str, &'static str)>, | 221 | more: Option<(&'static str, &'static str)>, |
| 44 | rows: Vec<NeedRow>, | 222 | rows: Vec<NeedRow>, |
| 223 | + pager: NeedPager, | ||
| 224 | +} | ||
| 225 | + | ||
| 226 | +/// Adds an overview section for `rows`, unless there are none. | ||
| 227 | +fn push_section(sections: &mut Vec<NeedSection>, lang: Lang, section: Section, rows: Vec<NeedRow>) { | ||
| 228 | + if rows.is_empty() { | ||
| 229 | + return; | ||
| 230 | + } | ||
| 231 | + sections.push(NeedSection { | ||
| 232 | + heading: ni::t(lang, section.heading()), | ||
| 233 | + more: Some((section.href(), ni::t(lang, section.all_key()))), | ||
| 234 | + rows, | ||
| 235 | + pager: NeedPager::single(), | ||
| 236 | + }); | ||
| 45 | } | 237 | } |
| 46 | 238 | ||
| 47 | -/// The sections that have rows, in page order. | 239 | +/// The sections that have rows, in page order, each capped at `SECTION_ROWS`. |
| 48 | async fn load_sections(state: &AppState, user: &User, lang: Lang) -> Result<Vec<NeedSection>> { | 240 | async fn load_sections(state: &AppState, user: &User, lang: Lang) -> Result<Vec<NeedSection>> { |
| 49 | let mut sections = Vec::new(); | 241 | let mut sections = Vec::new(); |
| 50 | let limit = SECTION_ROWS as i64; | 242 | let limit = SECTION_ROWS as i64; |
| 51 | 243 | ||
| 52 | - let runs = state.store.failing_runs(&user.id, limit).await?; | 244 | + let runs = Section::Runs.rows(state, user, lang, limit, 0).await?; |
| 53 | - if !runs.is_empty() { | 245 | + push_section(&mut sections, lang, Section::Runs, runs); |
| 54 | - sections.push(NeedSection { | ||
| 55 | - heading: ni::t(lang, K::FailedRuns), | ||
| 56 | - more: None, | ||
| 57 | - rows: runs | ||
| 58 | - .iter() | ||
| 59 | - .map(|run| { | ||
| 60 | - let title = format!("{}/{}", run.owner, run.repo); | ||
| 61 | - NeedRow { | ||
| 62 | - href: run_href(&title, run.number), | ||
| 63 | - title: format!("{title} #{}", run.number), | ||
| 64 | - detail: run.git_ref.clone(), | ||
| 65 | - badge: None, | ||
| 66 | - stamp: run.created_at.clone(), | ||
| 67 | - } | ||
| 68 | - }) | ||
| 69 | - .collect(), | ||
| 70 | - }); | ||
| 71 | - } | ||
| 72 | 246 | ||
| 73 | let mut reviews = Vec::new(); | 247 | let mut reviews = Vec::new(); |
| 74 | for item in state.store.review_requests_for_user(&user.id).await? { | 248 | for item in state.store.review_requests_for_user(&user.id).await? { |
| @@ -115,94 +289,72 @@ async fn load_sections(state: &AppState, user: &User, lang: Lang) -> Result<Vec< | |||
| 115 | heading: ni::t(lang, K::ReviewsRequested), | 289 | heading: ni::t(lang, K::ReviewsRequested), |
| 116 | more: Some(("/review-requests", ni::t(lang, K::AllReviewRequests))), | 290 | more: Some(("/review-requests", ni::t(lang, K::AllReviewRequests))), |
| 117 | rows: reviews, | 291 | rows: reviews, |
| 292 | + pager: NeedPager::single(), | ||
| 118 | }); | 293 | }); |
| 119 | } | 294 | } |
| 120 | 295 | ||
| 121 | - let pulls = state | 296 | + let pulls = Section::Pulls.rows(state, user, lang, limit, 0).await?; |
| 122 | - .store | 297 | + push_section(&mut sections, lang, Section::Pulls, pulls); |
| 123 | - .own_pulls_with_verdict(&user.id, SECTION_ROWS) | ||
| 124 | - .await?; | ||
| 125 | - if !pulls.is_empty() { | ||
| 126 | - sections.push(NeedSection { | ||
| 127 | - heading: ni::t(lang, K::YourPulls), | ||
| 128 | - more: None, | ||
| 129 | - rows: pulls | ||
| 130 | - .iter() | ||
| 131 | - .map(|pull| NeedRow { | ||
| 132 | - href: repo_href(&pull.owner, &pull.repo, "pulls", &pull.number.to_string()), | ||
| 133 | - title: pull.title.clone(), | ||
| 134 | - detail: format!("{}/{} #{}", pull.owner, pull.repo, pull.number), | ||
| 135 | - badge: Some(match pull.verdict { | ||
| 136 | - Verdict::ChangesRequested => ni::t(lang, K::ChangesRequested), | ||
| 137 | - Verdict::Approved => ni::t(lang, K::Approved), | ||
| 138 | - }), | ||
| 139 | - stamp: pull.updated_at.clone(), | ||
| 140 | - }) | ||
| 141 | - .collect(), | ||
| 142 | - }); | ||
| 143 | - } | ||
| 144 | 298 | ||
| 145 | - let issues = state.store.assigned_issues(&user.id, limit).await?; | 299 | + let issues = Section::Issues.rows(state, user, lang, limit, 0).await?; |
| 146 | - if !issues.is_empty() { | 300 | + push_section(&mut sections, lang, Section::Issues, issues); |
| 147 | - sections.push(NeedSection { | ||
| 148 | - heading: ni::t(lang, K::AssignedIssues), | ||
| 149 | - more: None, | ||
| 150 | - rows: issues | ||
| 151 | - .iter() | ||
| 152 | - .map(|issue| NeedRow { | ||
| 153 | - href: repo_href( | ||
| 154 | - &issue.owner, | ||
| 155 | - &issue.repo, | ||
| 156 | - "issues", | ||
| 157 | - &issue.number.to_string(), | ||
| 158 | - ), | ||
| 159 | - title: issue.title.clone(), | ||
| 160 | - detail: format!("{}/{} #{}", issue.owner, issue.repo, issue.number), | ||
| 161 | - badge: None, | ||
| 162 | - stamp: issue.updated_at.clone(), | ||
| 163 | - }) | ||
| 164 | - .collect(), | ||
| 165 | - }); | ||
| 166 | - } | ||
| 167 | 301 | ||
| 168 | - let mentions: Vec<_> = state | 302 | + let mentions = Section::Mentions.rows(state, user, lang, limit, 0).await?; |
| 169 | - .store | 303 | + push_section(&mut sections, lang, Section::Mentions, mentions); |
| 170 | - .waiting_on(&user.id, WAITING_READ) | ||
| 171 | - .await? | ||
| 172 | - .into_iter() | ||
| 173 | - .filter(|item| matches!(item.reason, Reason::Mention)) | ||
| 174 | - .take(SECTION_ROWS) | ||
| 175 | - .collect(); | ||
| 176 | - if !mentions.is_empty() { | ||
| 177 | - sections.push(NeedSection { | ||
| 178 | - heading: ni::t(lang, K::Mentions), | ||
| 179 | - more: None, | ||
| 180 | - rows: mentions | ||
| 181 | - .iter() | ||
| 182 | - .map(|item| { | ||
| 183 | - let section = if item.is_pull { "pulls" } else { "issues" }; | ||
| 184 | - NeedRow { | ||
| 185 | - href: repo_href(&item.owner, &item.repo, section, &item.number.to_string()), | ||
| 186 | - title: item.title.clone(), | ||
| 187 | - detail: format!("{}/{} #{}", item.owner, item.repo, item.number), | ||
| 188 | - badge: None, | ||
| 189 | - stamp: item.updated_at.clone(), | ||
| 190 | - } | ||
| 191 | - }) | ||
| 192 | - .collect(), | ||
| 193 | - }); | ||
| 194 | - } | ||
| 195 | 304 | ||
| 196 | Ok(sections) | 305 | Ok(sections) |
| 197 | } | 306 | } |
| 198 | 307 | ||
| 199 | -/// One section of the page: its head, its rows as a compact list, and its full-list link. | 308 | +/// One section as a full list: the page the query asks for, clamped to the pages there are. |
| 309 | +async fn load_full( | ||
| 310 | + state: &AppState, | ||
| 311 | + user: &User, | ||
| 312 | + lang: Lang, | ||
| 313 | + section: Section, | ||
| 314 | + requested: Option<&str>, | ||
| 315 | +) -> Result<NeedSection> { | ||
| 316 | + let total = section.total(state, &user.id).await?; | ||
| 317 | + let pages = total.div_ceil(PER_PAGE).max(1); | ||
| 318 | + let page = requested | ||
| 319 | + .and_then(|p| p.parse::<u64>().ok()) | ||
| 320 | + .unwrap_or(1) | ||
| 321 | + .clamp(1, pages); | ||
| 322 | + let offset = (page - 1) * PER_PAGE; | ||
| 323 | + let rows = section | ||
| 324 | + .rows(state, user, lang, PER_PAGE as i64, offset as i64) | ||
| 325 | + .await?; | ||
| 326 | + let slug = section.slug(); | ||
| 327 | + let (links, prev, next) = pager_links(page, pages, |n| { | ||
| 328 | + format!("/needs-you?section={slug}&page={n}") | ||
| 329 | + }); | ||
| 330 | + Ok(NeedSection { | ||
| 331 | + heading: ni::t(lang, section.heading()), | ||
| 332 | + more: None, | ||
| 333 | + rows, | ||
| 334 | + pager: NeedPager { | ||
| 335 | + page, | ||
| 336 | + pages, | ||
| 337 | + links, | ||
| 338 | + prev, | ||
| 339 | + next, | ||
| 340 | + }, | ||
| 341 | + }) | ||
| 342 | +} | ||
| 343 | + | ||
| 344 | +/// One section of the page: its head, its rows as a compact list, its full-list link and its pager. | ||
| 200 | #[component] | 345 | #[component] |
| 201 | pub(crate) async fn need_section(lang: Lang, section: NeedSection) -> Result<impl View> { | 346 | pub(crate) async fn need_section(lang: Lang, section: NeedSection) -> Result<impl View> { |
| 202 | let NeedSection { | 347 | let NeedSection { |
| 203 | heading, | 348 | heading, |
| 204 | more, | 349 | more, |
| 205 | rows, | 350 | rows, |
| 351 | + pager: NeedPager { | ||
| 352 | + page, | ||
| 353 | + pages, | ||
| 354 | + links, | ||
| 355 | + prev, | ||
| 356 | + next, | ||
| 357 | + }, | ||
| 206 | } = section; | 358 | } = section; |
| 207 | Ok(view! { | 359 | Ok(view! { |
| 208 | <section class="card needs-section"> | 360 | <section class="card needs-section"> |
| @@ -222,41 +374,69 @@ pub(crate) async fn need_section(lang: Lang, section: NeedSection) -> Result<imp | |||
| 222 | if let Some((href, text)) = more { | 374 | if let Some((href, text)) = more { |
| 223 | <a class="needs-more small" href=(href)>(text)</a> | 375 | <a class="needs-more small" href=(href)>(text)</a> |
| 224 | } | 376 | } |
| 377 | + pager(page: page, pages: pages, links: links, prev: prev, next: next, lang: lang) | ||
| 225 | </section> | 378 | </section> |
| 226 | }) | 379 | }) |
| 227 | } | 380 | } |
| 228 | 381 | ||
| 229 | -/// The page's sections, the only ones with rows, or the one-line empty state. | 382 | +/// The page's sections, the only ones with rows, or the one-line empty state. With a valid |
| 383 | +/// `section` query, that one section as a full list instead. | ||
| 230 | #[page("/needs-you")] | 384 | #[page("/needs-you")] |
| 231 | async fn needs_you(cx: &Cx) -> Result<impl View> { | 385 | async fn needs_you(cx: &Cx) -> Result<impl View> { |
| 232 | let viewer = require_user(cx).await?; | 386 | let viewer = require_user(cx).await?; |
| 233 | let state = app_context::<AppState>(cx); | 387 | let state = app_context::<AppState>(cx); |
| 234 | let user = &viewer.0; | 388 | let user = &viewer.0; |
| 235 | let lang = i18n::lang(cx, Some(user)); | 389 | let lang = i18n::lang(cx, Some(user)); |
| 236 | - let sections = load_sections(state, user, lang).await?; | 390 | + let query = query_params::<NeedsQuery>(cx)?; |
| 237 | - let empty = sections.is_empty(); | 391 | + let section = query.section.as_deref().and_then(Section::parse); |
| 392 | + let (sections, full) = match section { | ||
| 393 | + Some(section) => ( | ||
| 394 | + Vec::new(), | ||
| 395 | + Some(load_full(state, user, lang, section, query.page.as_deref()).await?), | ||
| 396 | + ), | ||
| 397 | + None => (load_sections(state, user, lang).await?, None), | ||
| 398 | + }; | ||
| 399 | + let live = match (section, &full) { | ||
| 400 | + (Some(section), Some(full)) => format!( | ||
| 401 | + "/needs-you/events?section={}&page={}", | ||
| 402 | + section.slug(), | ||
| 403 | + full.pager.page | ||
| 404 | + ), | ||
| 405 | + _ => "/needs-you/events".to_owned(), | ||
| 406 | + }; | ||
| 407 | + let grid = full.is_none() && !sections.is_empty(); | ||
| 408 | + let empty = full.is_none() && sections.is_empty(); | ||
| 409 | + let back = full.as_ref().map(|_| ni::t(lang, K::BackToNeedsYou)); | ||
| 238 | let heading = ni::t(lang, K::NeedsYou); | 410 | let heading = ni::t(lang, K::NeedsYou); |
| 239 | Ok(view! { | 411 | Ok(view! { |
| 240 | shell(title: heading, viewer: Some(&viewer), | 412 | shell(title: heading, viewer: Some(&viewer), |
| 241 | - <section class="page-head" data-live="/needs-you/events"> | 413 | + <section class="page-head" data-live=(live.as_str())> |
| 242 | <h1>(heading)</h1> | 414 | <h1>(heading)</h1> |
| 415 | + if let Some(back) = back { | ||
| 416 | + <a class="needs-back small" href="/needs-you">(back)</a> | ||
| 417 | + } | ||
| 243 | </section> | 418 | </section> |
| 244 | if empty { | 419 | if empty { |
| 245 | empty_state(title: ni::t(lang, K::AllClear)) | 420 | empty_state(title: ni::t(lang, K::AllClear)) |
| 246 | } | 421 | } |
| 247 | - if !empty { | 422 | + if grid { |
| 248 | <div class="needs-grid"> | 423 | <div class="needs-grid"> |
| 249 | for section in sections.into_iter() { | 424 | for section in sections.into_iter() { |
| 250 | need_section(lang: lang, section: section) | 425 | need_section(lang: lang, section: section) |
| 251 | } | 426 | } |
| 252 | </div> | 427 | </div> |
| 253 | } | 428 | } |
| 429 | + if let Some(section) = full { | ||
| 430 | + <div class="needs-full"> | ||
| 431 | + need_section(lang: lang, section: section) | ||
| 432 | + </div> | ||
| 433 | + } | ||
| 254 | ) | 434 | ) |
| 255 | }) | 435 | }) |
| 256 | } | 436 | } |
| 257 | 437 | ||
| 258 | /// The page's stream: a wake on the viewer's review-request or inbox topic. Anonymous visitors get | 438 | /// The page's stream: a wake on the viewer's review-request or inbox topic. Anonymous visitors get |
| 259 | -/// a bare 401. | 439 | +/// a bare 401. The query of a section view is ignored here, so the same stream serves both. |
| 260 | #[route(GET "/needs-you/events")] | 440 | #[route(GET "/needs-you/events")] |
| 261 | async fn needs_you_events(cx: &Cx) -> Result<Response> { | 441 | async fn needs_you_events(cx: &Cx) -> Result<Response> { |
| 262 | let Some((user, _)) = current_user(cx).await? else { | 442 | let Some((user, _)) = current_user(cx).await? else { |
crates/forge-web/src/pages/pull_view.rsmodified+2 -1
| @@ -624,6 +624,7 @@ async fn pull_conversation( | |||
| 624 | ) | 624 | ) |
| 625 | .await?; | 625 | .await?; |
| 626 | let sidebar = load_sidebar(state, &ctx.repo.id, &pr.issue).await?; | 626 | let sidebar = load_sidebar(state, &ctx.repo.id, &pr.issue).await?; |
| 627 | + let viewer_login = ctx.viewer.as_ref().map(|(u, _)| u.username.clone()); | ||
| 627 | let notify = notify_box_for(state, &ctx, lang, &pr.issue.id, &href).await?; | 628 | let notify = notify_box_for(state, &ctx, lang, &pr.issue.id, &href).await?; |
| 628 | let reviewers = load_reviewers(cx, state, &ctx, &pr.issue, &href).await?; | 629 | let reviewers = load_reviewers(cx, state, &ctx, &pr.issue, &href).await?; |
| 629 | let csrf = csrf_of(&ctx); | 630 | let csrf = csrf_of(&ctx); |
| @@ -933,7 +934,7 @@ async fn pull_conversation( | |||
| 933 | } | 934 | } |
| 934 | </div> | 935 | </div> |
| 935 | <aside class="issue-sidebar fit-pane"> | 936 | <aside class="issue-sidebar fit-pane"> |
| 936 | - item_sidebar(lang: lang, write: write_meta, base: href.clone(), csrf: csrf.clone(), sidebar: sidebar, notify: notify) | 937 | + item_sidebar(lang: lang, write: write_meta, base: href.clone(), csrf: csrf.clone(), viewer: viewer_login, sidebar: sidebar, notify: notify) |
| 937 | reviewers_box(lang: lang, reviewers: reviewers) | 938 | reviewers_box(lang: lang, reviewers: reviewers) |
| 938 | </aside> | 939 | </aside> |
| 939 | </div> | 940 | </div> |
crates/forge-web/src/pages/repo.rsmodified+2 -0
| @@ -248,6 +248,8 @@ async fn clone_popover( | |||
| 248 | <div class="pop-panel"> | 248 | <div class="pop-panel"> |
| 249 | <label for="clone-https">"HTTPS"</label> | 249 | <label for="clone-https">"HTTPS"</label> |
| 250 | <input id="clone-https" class="mono" type="text" readonly=(true) value=(https.as_str())> | 250 | <input id="clone-https" class="mono" type="text" readonly=(true) value=(https.as_str())> |
| 251 | + <span id="clone-https-text" hidden=(true)>(https.as_str())</span> | ||
| 252 | + <p><button type="button" class="button small" data-copy="clone-https-text" data-copied=(g::t(lang, K::CloneCopied)) data-failed=(g::t(lang, K::CloneCopyFailed)) data-palette-action="click">(g::t(lang, K::CopyCloneUrl))</button></p> | ||
| 251 | <label for="clone-ssh">"SSH"</label> | 253 | <label for="clone-ssh">"SSH"</label> |
| 252 | <input id="clone-ssh" class="mono" type="text" readonly=(true) value=(ssh.as_str())> | 254 | <input id="clone-ssh" class="mono" type="text" readonly=(true) value=(ssh.as_str())> |
| 253 | <p class="muted small">(g::t(lang, K::SshRequiresKey))</p> | 255 | <p class="muted small">(g::t(lang, K::SshRequiresKey))</p> |
style/_kb_rerun.scssadded+52 -0
| @@ -0,0 +1,52 @@ | |||
| 1 | +// The Re-run control of a CI run row, which r reruns from the keyboard. It is a small quiet button in | ||
| 2 | +// the row's top corner, shown on the hovered, focused or selected row. It sits over the row's corner, | ||
| 3 | +// so the row keeps its height, and the title leaves room for it. | ||
| 4 | + | ||
| 5 | +.ci-run-list > li { | ||
| 6 | + position: relative; | ||
| 7 | +} | ||
| 8 | + | ||
| 9 | +.ci-row-rerun-form { | ||
| 10 | + position: absolute; | ||
| 11 | + top: 8px; | ||
| 12 | + right: 8px; | ||
| 13 | + margin: 0; | ||
| 14 | + opacity: 0; | ||
| 15 | + transition: opacity 120ms ease; | ||
| 16 | + | ||
| 17 | + li:hover &, | ||
| 18 | + li:focus-within &, | ||
| 19 | + li.kb-sel & { | ||
| 20 | + opacity: 1; | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + @media (hover: none) { | ||
| 24 | + opacity: 1; | ||
| 25 | + } | ||
| 26 | +} | ||
| 27 | + | ||
| 28 | +li:has(> .ci-row-rerun-form) .ci-row-title { | ||
| 29 | + padding-right: 64px; | ||
| 30 | +} | ||
| 31 | + | ||
| 32 | +.ci-row-rerun { | ||
| 33 | + padding: 1px 8px; | ||
| 34 | + font-size: 0.75rem; | ||
| 35 | + line-height: 1.5; | ||
| 36 | + color: var(--muted); | ||
| 37 | + background: var(--surface); | ||
| 38 | + border: 1px solid var(--border); | ||
| 39 | + border-radius: var(--radius-md); | ||
| 40 | + cursor: pointer; | ||
| 41 | + | ||
| 42 | + &:hover { | ||
| 43 | + color: var(--text); | ||
| 44 | + border-color: var(--border-strong); | ||
| 45 | + } | ||
| 46 | +} | ||
| 47 | + | ||
| 48 | +@media (prefers-reduced-motion: reduce) { | ||
| 49 | + .ci-row-rerun-form { | ||
| 50 | + transition: none; | ||
| 51 | + } | ||
| 52 | +} | ||
style/_needs.scssmodified+24 -0
| @@ -41,6 +41,30 @@ | |||
| 41 | } | 41 | } |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | +.needs-back { | ||
| 45 | + display: inline-block; | ||
| 46 | + color: var(--muted); | ||
| 47 | + text-decoration: none; | ||
| 48 | + | ||
| 49 | + &:hover { | ||
| 50 | + color: var(--text); | ||
| 51 | + text-decoration: underline; | ||
| 52 | + } | ||
| 53 | +} | ||
| 54 | + | ||
| 55 | +// A section's full list: its rows scroll inside the card when they run past the window, and the | ||
| 56 | +// pager stays under them. | ||
| 57 | +.needs-full { | ||
| 58 | + .needs-section { | ||
| 59 | + margin-bottom: 0; | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + .notif-list { | ||
| 63 | + max-height: calc(100vh - 220px); | ||
| 64 | + overflow-y: auto; | ||
| 65 | + } | ||
| 66 | +} | ||
| 67 | + | ||
| 44 | @media (min-width: 900px) { | 68 | @media (min-width: 900px) { |
| 45 | .needs-grid { | 69 | .needs-grid { |
| 46 | grid-template-columns: repeat(2, minmax(0, 1fr)); | 70 | grid-template-columns: repeat(2, minmax(0, 1fr)); |
style/main.scssmodified+1 -0
| @@ -8059,6 +8059,7 @@ button.ci-job-last { | |||
| 8059 | @import "timeline"; | 8059 | @import "timeline"; |
| 8060 | @import "density"; | 8060 | @import "density"; |
| 8061 | @import "keyboard"; | 8061 | @import "keyboard"; |
| 8062 | +@import "kb_rerun"; | ||
| 8062 | @import "review_flow"; | 8063 | @import "review_flow"; |
| 8063 | @import "commit_page"; | 8064 | @import "commit_page"; |
| 8064 | @import "commit_line"; | 8065 | @import "commit_line"; |