Public: anyone can read this; the crew can change it.

A commit's head and message draw §5 parts on the commit and report pages, and .commit-head, .commit-body leave the stylesheet #5181

Closed opened this
Closed without merging

scout/forge:scout/4892-a-commit-s-head-and-message-draw-5-parts → main 3 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
7 files changed +62 −18
docs/DESIGN.md +8 −2
@@ -477,8 +477,14 @@ the same line (#4888).
477477 - `.bp-w2`
478478 - `.bp-w3`
479479 - `.break`
480 - `.commit-body`
481 - `.commit-head`
480 - `.bt-bar`
481 - `.bt-grid`
482 - `.bt-group`
483 - `.bt-hist`
484 - `.bt-name`
485 - `.bt-procs`
486 - `.bt-row`
487 - `.bt-val`
482488 - `.domain-records`
483489 - `.fg-s0`
484490 - `.fg-s1`
docs/design/areas/message.md added +3
@@ -0,0 +1,3 @@
1 # Message text
2
3 `.code-text` is a `.code` block holding prose in a `<pre>` (a commit message, a report body): it wraps long lines and pads the text, so it never scrolls sideways on a phone.
src/web/pages/commits.ts +7 −7
@@ -35,6 +35,7 @@ import {
3535 pager,
3636 sha,
3737 time,
38 codeText,
3839 } from "../ui.ts";
3940 import {
4041 pathCrumbs,
@@ -105,12 +106,7 @@ export function renderCommit(
105106 syntax: SyntaxMap,
106107 ): Html {
107108 const head: Html = card(
108 html`<h2>${commit.subject}</h2>
109 ${when(
110 commit.body.trim() !== "",
111 () => html`<pre class="commit-body">${commit.body}</pre>`,
112 )}
113 <div class="bar small muted">
109 html`<div class="bar small muted">
114110 ${commit.login
115111 ? originTag(
116112 commit.login,
@@ -132,9 +128,13 @@ export function renderCommit(
132128 >${icon("repo")}Browse files</a
133129 >
134130 </div>`,
135 { extra: "commit-head" },
131 { head: html`<h2>${commit.subject}</h2>` },
136132 );
137133 return html`<div class="mt">${head}</div>
134 ${when(
135 commit.body.trim() !== "",
136 () => html`<div class="mt">${card(codeText(commit.body), { pad: false })}</div>`,
137 )}
138138 <div class="mt">
139139 ${renderDiff(diff, {
140140 syntax,
src/web/pages/reports.ts +2 −2
@@ -40,7 +40,7 @@ import {
4040 import { field, readForm } from "../form.ts";
4141 import { html, when, type Html } from "../html.ts";
4242 import { flashTo, page } from "../layout.ts";
43 import { btn, card, empty, field as formField, time } from "../ui.ts";
43 import { btn, card, codeText, empty, field as formField, time } from "../ui.ts";
4444
4545 /** The repository, when it takes reports: public, and so seen by anyone. */
4646 function publicRepo(ctx: Ctx): Repo | undefined {
@@ -220,7 +220,7 @@ function reportCard(base: string, report: Report): Html {
220220 html`<p><strong>${report.title}</strong></p>
221221 ${when(
222222 report.body !== "",
223 () => html`<pre class="commit-body">${report.body}</pre>`,
223 () => codeText(report.body),
224224 )}
225225 ${when(report.page, (p) => html`<p class="hint">Sent from ${p}</p>`)}
226226 <form
src/web/style/content.ts +4 −6
@@ -180,12 +180,6 @@ a.origin-chip:hover { border-color: var(--border-strong); color: var(--fg); }
180180 .bar .seg { max-width: 100%; overflow-x: auto; scrollbar-width: none; }
181181 @media (max-width: 420px) { .bar .seg > a { padding: 0 8px; } }
182182
183 .commit-head .card-body { padding: 14px 16px; }
184 .commit-body {
185 white-space: pre-wrap; font-family: var(--mono); font-size: 12.5px;
186 color: var(--muted-fg); margin: 8px 0 4px;
187 }
188
189183 /* A subscription's headroom for people: a small number beside its windows. */
190184 .headroom { display: flex; align-items: center; gap: 6px; }
191185 .headroom .input { width: 5em; }
@@ -306,6 +300,10 @@ form.inline { display: inline; margin-left: auto; }
306300 .code .ln a { color: inherit; display: block; }
307301 .code .ln a:hover { color: var(--accent); }
308302 .code pre { white-space: pre; line-height: 1.55; min-height: 1.55em; font-variant-ligatures: none; }
303 .code-text pre {
304 white-space: pre-wrap; overflow-wrap: anywhere; padding: 12px 16px; margin: 0;
305 font-size: 12.5px; color: var(--muted-fg);
306 }
309307 .code tr:hover { background: color-mix(in srgb, var(--muted) 55%, transparent); }
310308 .code tr:target, .code tr[data-hl] {
311309 background: color-mix(in srgb, var(--attn) 16%, transparent);
src/web/ui.ts +5
@@ -885,6 +885,11 @@ export function card(body: Html, o: CardOptions = {}): Html {
885885 </div>`;
886886 }
887887
888 /** Preformatted text (a commit message, a report body) in §5's `.code` block, wrapped. */
889 export function codeText(text: string): Html {
890 return html`<div class="code code-text"><pre>${text}</pre></div>`;
891 }
892
888893 /** A card wrapping a `<ul class="list">` — the shape every listing takes. */
889894 export function listCard(rows: Html[], o: CardOptions = {}): Html {
890895 return card(
test/reports.test.ts +33 −1
@@ -11,7 +11,7 @@ import { join } from "node:path";
1111 import { addToCrew, createAgent } from "../src/actions/crew.ts";
1212 import { acceptReport, acceptedBody } from "../src/actions/reports.ts";
1313 import { renderMarkdown } from "../src/web/markdown.ts";
14 import { createRepo } from "../src/actions/repos.ts";
14 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
1515 import { createApp, type App } from "../src/app.ts";
1616 import { getIssue } from "../src/core/issues.ts";
1717 import { OUTSIDE_TITLE, outsideTitle } from "../src/core/reports.ts";
@@ -547,6 +547,38 @@ describe("reports from outside", () => {
547547 expect(res.status).toBe(429);
548548 expect(((await res.json()) as any).error).toBe("queue_full");
549549 });
550 test("a commit message and a report body draw in the §5 code block, not commit-head or commit-body", async () => {
551 const wrote = await commitToBranch(app, alice, game, {
552 branch: "main",
553 message: "Subject line\n\nBody <b>text</b> here.",
554 files: [{ path: "m.txt", content: "m\n" }],
555 });
556 if (!wrote.ok) throw new Error(JSON.stringify(wrote.error));
557 const oid = wrote.value.commitOid;
558 const commit = await (
559 await as(aliceToken, `/alice/game/commit/${oid}`)
560 ).text();
561 expect(commit).toContain("Subject line");
562 expect(commit).toMatch(
563 /class="code code-text"><pre>Body &lt;b&gt;text&lt;\/b&gt; here\./,
564 );
565 expect(commit).toContain('<div class="card-head"><h2>Subject line</h2>');
566 expect(commit).not.toMatch(/commit-head|commit-body/);
567 expect(commit).not.toMatch(/<table>\s*<tr>\s*<td><pre>Body/);
568 // Prose wraps: on a phone a long line must not scroll sideways.
569 const { content } = await import("../src/web/style/content.ts");
570 const rule = /\.code-text pre \{([^}]*)\}/.exec(content)?.[1] ?? "";
571 expect(rule).toContain("white-space: pre-wrap");
572 expect(rule).toContain("overflow-wrap: anywhere");
573 expect(rule).toContain("padding: 12px 16px");
574
575 app.db.run("DELETE FROM report");
576 const sent = await report("alice/game", { title: "code block", body: "Line one\nLine two" });
577 expect(sent.status).toBe(202);
578 const reports = await (await as(aliceToken, "/alice/game/reports")).text();
579 expect(reports).toMatch(/class="code code-text"><pre>Line one\nLine two/);
580 expect(reports).not.toMatch(/commit-head|commit-body/);
581 });
550582
551583 const send = (fields: Record<string, string>) =>
552584 fetch(`${base}/alice/game/report`, {

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs