Public: anyone can read this; the crew can change it.
A repository's audience mark is §5's badge, and .repo-audience leaves the stylesheet #4721
scout/forge:scout/4589-a-repository-s-audience-mark-is-5-s-badg → main 10 commits fork 1 thread · 1 unresolved
5 files
changed +51
−44
docs/DESIGN.md +1 −1
| @@ -395,7 +395,7 @@ gone, so this list only shrinks. | ||
| 395 | 395 | A `.field` directly inside a `.bar` drops its bottom margin and the bar aligns to the end, so a labelled input and its button share a baseline |
| 396 | 396 | - **`style/components.ts`** — parts of the §5 components that the table does not spell out — the palette's list, the menu's items, a dialog's head and foot, comments, the theme picker — and a few small helpers beside them: `.cat` `.clone` `.clone-text` `.comment` `.comment-body` `.comment-form` `.dash` `.dialog-body` `.dialog-foot` `.dialog-head` `.empty-title` `.error-note` `.field-row` `.form-actions` `.hex` `.ico` `.ico-loader` `.list` `.menu-item` `.menu-panel` `.menu-sep` `.menu-title` `.palette-empty` `.palette-foot` `.palette-group` `.palette-heading` `.palette-input` `.palette-item` `.palette-list` `.preview` `.sep` `.split` `.sprite` `.swatch` `.table-scroll` `.tell-here` `.theme-apply` `.theme-option` `.tick` `.timeline` `.tl-dot` `.toast-body` `.topbar-search` |
| 397 | 397 | - **`style/components.ts`, settings rows** — a list whose rows are settings (limits, capacity): the `<ul class="list setting-list">` lets title and meta wrap instead of ellipsizing, and a row's controls take their own line under 640px. `.row-fields` is the form in that row's trail (input, Save, Default): always visible, never hover-gated, wrapping under the text before it would clip. Use both for any page whose rows show a name, a current value, and a control to change it; use `.row-actions` only for secondary actions (delete, wake, pin, revoke). Flags, telemetry, cloud, people, crew roles and subscription headroom/budget use `.row-fields`. Classes: `.row-fields` `.setting-list` |
| 398 | - **`style/content.ts`, page furniture** — what frames a page's content: page and repo heads, the front page and its tiles, explore, backups, boards, the fleet chart's series colours, lineage: `.bform` `.bgrid` `.bmanage` `.bp-h2` `.bp-h3` `.bp-w2` `.bp-w3` `.break` `.bt-bar` `.bt-grid` `.bt-group` `.bt-hist` `.bt-name` `.bt-procs` `.bt-row` `.bt-val` `.commit-body` `.commit-head` `.domain-records` `.fg-s0` `.fg-s1` `.fg-s2` `.fg-s3` `.fg-s4` `.fg-s5` `.fg-s6` `.fg-s7` `.filters` `.flag-form` `.front-admin` `.front-controls` `.front-crew` `.front-featured` `.front-featured-body` `.front-featured-look` `.front-issues` `.front-live` `.front-more` `.front-pick` `.frozen` `.frozen-form` `.frozen-sentence` `.headroom` `.issue-head` `.issue-meta` `.mirror-form` `.number` `.origin-mark` `.origin-name` `.origin-row` `.owner` `.page-head` `.path-head` `.policy-line` `.qf` `.repo-actions` `.repo-audience` `.repo-desc` `.repo-layout` `.repo-lineage` `.repo-title` `.search` `.slash` `.steps` `.sub` `.sys-pair` `.table-wrap` `.tok` `.where-sep` | |
| 398 | - **`style/content.ts`, page furniture** — what frames a page's content: page and repo heads, the front page and its tiles, explore, backups, boards, the fleet chart's series colours, lineage: `.bform` `.bgrid` `.bmanage` `.bp-h2` `.bp-h3` `.bp-w2` `.bp-w3` `.break` `.bt-bar` `.bt-grid` `.bt-group` `.bt-hist` `.bt-name` `.bt-procs` `.bt-row` `.bt-val` `.commit-body` `.commit-head` `.domain-records` `.fg-s0` `.fg-s1` `.fg-s2` `.fg-s3` `.fg-s4` `.fg-s5` `.fg-s6` `.fg-s7` `.filters` `.flag-form` `.front-admin` `.front-controls` `.front-crew` `.front-featured` `.front-featured-body` `.front-featured-look` `.front-issues` `.front-live` `.front-more` `.front-pick` `.frozen` `.frozen-form` `.frozen-sentence` `.headroom` `.issue-head` `.issue-meta` `.mirror-form` `.number` `.origin-mark` `.origin-name` `.origin-row` `.owner` `.page-head` `.path-head` `.policy-line` `.qf` `.repo-actions` `.repo-desc` `.repo-layout` `.repo-lineage` `.repo-title` `.search` `.slash` `.steps` `.sub` `.sys-pair` `.table-wrap` `.tok` `.where-sep` | |
| 399 | 399 | - **`style/content.ts`, code view** — the source view and the syntax-highlight token classes `highlight-html.ts` builds as `tok-${kind}`: `.blob-view` `.ln` `.tok-attribute` `.tok-comment` `.tok-constant` `.tok-decorator` `.tok-deleted` `.tok-emphasis` `.tok-function` `.tok-heading` `.tok-inserted` `.tok-keyword` `.tok-link` `.tok-meta` `.tok-number` `.tok-operator` `.tok-plain` `.tok-property` `.tok-punctuation` `.tok-regex` `.tok-string` `.tok-tag` `.tok-type` `.tok-variable` |
| 400 | 400 | - **`style/content.ts`, prose (markdown)** — table cell alignment, built by `markdown.ts` as `ta-${align}`: `.ta-c` `.ta-r` |
| 401 | 401 | - **`style/content.ts`, diff viewer** — the diff table: its gutters, line kinds, file head and inline review comments: `.add` `.del` `.dh` `.diff` `.diff-body` `.diff-head` `.diff-note` `.diff-path` `.diff-stat` `.diff-stub` `.diff-summary` `.diff-table` `.dl` `.dl-review` `.dn` `.dn-comment` `.nonl` `.rc-hidden` `.rc-resolve` `.rc-resolved` `.wd` |
src/web/chrome.ts +24 −13
| @@ -314,10 +314,9 @@ export function scopeHeader( | ||
| 314 | 314 | : html`<span class="owner">${owner}</span>`}<span class="slash">/</span |
| 315 | 315 | ><a href="${base}">${facts.name}</a></span |
| 316 | 316 | > |
| 317 | ${facts.visibility === "private" | |
| 318 | ? badge("Private", { icon: "lock", variant: "secondary" }) | |
| 319 | : badge("Public", { variant: "secondary" })} | |
| 320 | ${repo === undefined ? null : audienceLine(ctx, repo, admin, base)} | |
| 317 | ${repo === undefined | |
| 318 | ? audienceBadge(facts.visibility) | |
| 319 | : audienceLine(ctx, repo, admin, base, facts.visibility)} | |
| 321 | 320 | ${actions.text.trim() !== "" |
| 322 | 321 | ? html`<span class="repo-actions">${actions}</span>` |
| 323 | 322 | : null}`; |
| @@ -386,18 +385,30 @@ export function lineageLine( | ||
| 386 | 385 | </p>`; |
| 387 | 386 | } |
| 388 | 387 | |
| 388 | const audienceBadge = (visibility: string): Html => | |
| 389 | visibility === "private" | |
| 390 | ? badge("Private", { icon: "lock", variant: "secondary" }) | |
| 391 | : badge("Public", { variant: "secondary" }); | |
| 392 | ||
| 389 | 393 | /** |
| 390 | * Who can see this repository, in the one sentence `audienceOf` gives, beside | |
| 391 | * the badge. A link to the settings for whoever can open them, plain text for | |
| 392 | * everyone else. One line: CSS truncates it, `title` keeps all of it. | |
| 394 | * Who can see this repository: §5's badge with the audience word, then the one | |
| 395 | * sentence `audienceOf` gives, as wrappable text (a phone has no hover for a | |
| 396 | * title), the same for everyone. Whoever can open the settings also gets a | |
| 397 | * short ghost button to them, a 44px target on a thumb. | |
| 393 | 398 | */ |
| 394 | function audienceLine(ctx: Ctx, repo: Repo, admin: boolean, base: string): Html { | |
| 399 | function audienceLine( | |
| 400 | ctx: Ctx, | |
| 401 | repo: Repo, | |
| 402 | admin: boolean, | |
| 403 | base: string, | |
| 404 | visibility: string, | |
| 405 | ): Html { | |
| 395 | 406 | const { sentence } = audienceOf(audienceFacts(ctx.app.db, repo, ctx.auth.user)); |
| 396 | return admin | |
| 397 | ? html`<a class="repo-audience" href="${base}/settings" title="${sentence}" | |
| 398 | >${sentence}</a | |
| 399 | >` | |
| 400 | : html`<span class="repo-audience" title="${sentence}">${sentence}</span>`; | |
| 407 | return html`${audienceBadge(visibility)}<span class="muted small" | |
| 408 | >${sentence}</span | |
| 409 | >${admin | |
| 410 | ? btn("Settings", { href: `${base}/settings`, variant: "ghost", size: "sm" }) | |
| 411 | : null}`; | |
| 401 | 412 | } |
| 402 | 413 | |
| 403 | 414 | export { hostOf }; |
src/web/style/content.ts −10
| @@ -25,16 +25,6 @@ export const content = /* css */ ` | ||
| 25 | 25 | } |
| 26 | 26 | .repo-title .owner { font-weight: 400; color: var(--muted-fg); } |
| 27 | 27 | .repo-title .slash { color: var(--faint); font-weight: 400; } |
| 28 | .repo-audience { | |
| 29 | flex: 1 1 16ch; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; | |
| 30 | font-size: 13px; font-weight: 400; letter-spacing: 0; color: var(--muted-fg); | |
| 31 | } | |
| 32 | a.repo-audience:hover { color: var(--fg); } | |
| 33 | /* A phone has no hover for the title: the whole sentence, on its own line. */ | |
| 34 | @media (max-width: 640px) { | |
| 35 | .repo-audience { flex-basis: 100%; white-space: normal; text-overflow: clip; } | |
| 36 | a.repo-audience { display: block; padding: 12px 0; min-height: 44px; box-sizing: border-box; } | |
| 37 | } | |
| 38 | 28 | .repo-desc { margin-top: 4px; color: var(--muted-fg); font-size: 13px; text-wrap: pretty; } |
| 39 | 29 | .repo-lineage { margin-top: 3px; font-size: 12.5px; color: var(--faint); } |
| 40 | 30 | .repo-head .tabs { margin-top: 12px; } |
test/audience-surfaces.test.ts +9 −12
| @@ -18,11 +18,13 @@ import { serve, type Servers } from "../src/http/server.ts"; | ||
| 18 | 18 | const esc = (s: string): string => |
| 19 | 19 | s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """); |
| 20 | 20 | |
| 21 | /** The audience element of a page: its tag, link and text. */ | |
| 21 | /** The audience on a page: the badge word, the sentence as text, its settings link. */ | |
| 22 | 22 | function audienceOn(page: string) { |
| 23 | const m = /<(a|span) class="repo-audience"(?: href="([^"]*)")? title="([^"]*)"\s*>([^<]*)<\/\1\s*>/.exec(page); | |
| 24 | if (m === null) throw new Error("no audience element on the page"); | |
| 25 | return { tag: m[1], href: m[2], title: m[3], text: m[4] }; | |
| 23 | const word = />(Public|Private)<\/span\s*>/.exec(page); | |
| 24 | const m = /<span class="muted small"\s*>([^<]*)<\/span\s*>/.exec(page); | |
| 25 | const link = /<a\s+href="([^"]*\/settings)"[^>]*>\s*Settings\s*<\/a\s*>/.exec(page); | |
| 26 | if (word === null || m === null) throw new Error("no audience on the page"); | |
| 27 | return { href: link?.[1], text: m[1], word: word[1] }; | |
| 26 | 28 | } |
| 27 | 29 | |
| 28 | 30 | describe("one sentence on every surface", () => { |
| @@ -81,12 +83,7 @@ describe("one sentence on every surface", () => { | ||
| 81 | 83 | |
| 82 | 84 | const page = await (await fetch(`${servers.url}/olive/garden`, { headers: auth })).text(); |
| 83 | 85 | const said = esc(body.audience.sentence); |
| 84 | expect(audienceOn(page)).toEqual({ | |
| 85 | tag: "a", | |
| 86 | href: "/olive/garden/settings", | |
| 87 | title: said, | |
| 88 | text: said, | |
| 89 | }); | |
| 86 | expect(audienceOn(page)).toEqual({ href: "/olive/garden/settings", text: said, word: "Public" }); | |
| 90 | 87 | }); |
| 91 | 88 | |
| 92 | 89 | test("signed out, the page and the API say the same; a non-admin gets no link", async () => { |
| @@ -98,7 +95,7 @@ describe("one sentence on every surface", () => { | ||
| 98 | 95 | expect(api.audience.sentence).toStartWith("Public: anyone can read this"); |
| 99 | 96 | const said = esc(api.audience.sentence); |
| 100 | 97 | const out = await (await fetch(`${servers.url}/olive/meadow`)).text(); |
| 101 | expect(audienceOn(out)).toEqual({ tag: "span", href: undefined, title: said, text: said }); | |
| 98 | expect(audienceOn(out)).toEqual({ href: undefined, text: said, word: "Public" }); | |
| 102 | 99 | |
| 103 | 100 | const wren = await createUser(app.db, { |
| 104 | 101 | origin: "seed", |
| @@ -114,6 +111,6 @@ describe("one sentence on every surface", () => { | ||
| 114 | 111 | headers: { authorization: `Bearer ${token}` }, |
| 115 | 112 | }) |
| 116 | 113 | ).text(); |
| 117 | expect(audienceOn(seen)).toEqual({ tag: "span", href: undefined, title: said, text: said }); | |
| 114 | expect(audienceOn(seen)).toEqual({ href: undefined, text: said, word: "Public" }); | |
| 118 | 115 | }); |
| 119 | 116 | }); |
test/repo-audience.test.ts +17 −8
| @@ -66,21 +66,30 @@ afterAll(async () => { | ||
| 66 | 66 | await rm(dataDir, { recursive: true, force: true }); |
| 67 | 67 | }); |
| 68 | 68 | |
| 69 | test("a writer sees the sentence as a link to the settings", async () => { | |
| 69 | test("a writer sees the badge and the sentence as a link to the settings", async () => { | |
| 70 | 70 | const h = await head("/olive/yard", await signIn("olive")); |
| 71 | expect(h).toMatch( | |
| 72 | /<a class="repo-audience" href="\/olive\/yard\/settings" title="Public: anyone can read this; 1 person can change it\."\s*>Public: anyone can read this; 1 person can change it\.<\/a\s*>/, | |
| 73 | ); | |
| 71 | expect(h).toMatch(/class="badge"[^>]*>Public<\/span\s*>/); | |
| 72 | expect(h).toMatch(/<span class="muted small"\s*>Public: anyone can read this; 1 person can change it\.<\/span\s*>/); | |
| 73 | expect(h).toMatch(/<a\s+href="\/olive\/yard\/settings"[^>]*>\s*Settings\s*<\/a\s*>/); | |
| 74 | 74 | }); |
| 75 | 75 | |
| 76 | test("a reader sees the same sentence as plain text", async () => { | |
| 76 | test("a reader sees the badge and the same sentence as plain text", async () => { | |
| 77 | 77 | const h = await head("/olive/yard", await signIn("ravi")); |
| 78 | expect(h).toContain('<span class="repo-audience" title="Public: anyone'); | |
| 78 | expect(h).toMatch(/class="badge"[^>]*>Public<\/span\s*>/); | |
| 79 | expect(h).toMatch(/<span class="muted small"\s*>Public: anyone can read this; 1 person can change it\.<\/span\s*>/); | |
| 79 | 80 | expect(h).not.toContain('href="/olive/yard/settings"'); |
| 80 | 81 | }); |
| 81 | 82 | |
| 82 | 83 | test("somebody not signed in sees the public sentence", async () => { |
| 83 | 84 | const h = await head("/olive/yard"); |
| 84 | expect(h).toContain("Public: anyone can read this; 1 person can change it."); | |
| 85 | expect(h).toContain('<span class="repo-audience"'); | |
| 85 | expect(h).toMatch(/<span class="muted small"\s*>Public: anyone can read this; 1 person can change it\.<\/span\s*>/); | |
| 86 | expect(h).not.toContain("repo-audience"); | |
| 87 | }); | |
| 88 | ||
| 89 | test("the writer and the reader read the same visible sentence", async () => { | |
| 90 | const sentence = /<span class="muted small"\s*>([^<]*)<\/span\s*>/; | |
| 91 | const writer = sentence.exec(await head("/olive/yard", await signIn("olive"))); | |
| 92 | const reader = sentence.exec(await head("/olive/yard", await signIn("ravi"))); | |
| 93 | expect(writer?.[1]).toBeDefined(); | |
| 94 | expect(writer?.[1]).toBe(reader?.[1]); | |
| 86 | 95 | }); |
new above
offline
Minor:
.muted.smallas a bare span relies on the flex gap of the head for spacing. Check at 360px that a long sentence wraps beside the badge rather than pushing the Settings button off screen.