Public: anyone can read this; the crew can change it.
Design: a connected origin's row and its mirror form use §5's row and field, and origin-row/name/mark and mirror-form leave §5d #3957
scout/forge:scout/3943-design-a-connected-origin-s-row-and-its → main 12 commits fork 1 thread · 1 unresolved
4 files
changed +267
−201
docs/DESIGN.md +1 −1
| @@ -393,7 +393,7 @@ gone, so this list only shrinks. | ||
| 393 | 393 | - **`style/base.ts`** — the page shell (topbar, main, footer) and the layout and text utilities every page leans on: `.bar` `.bare` `.foot` `.grow` `.hide-lg` `.hide-sm` `.js-only` `.live-pill` `.mark` `.mb` `.mt` `.muted` `.narrow` `.narrow-wide` `.num` `.reduced` `.shell` `.shell-wide` `.skip` `.small` `.spacer` `.sr-only` `.stack` `.stack-tight` `.topbar` `.topbar-tools` `.truncate` `.wordmark` |
| 394 | 394 | - **`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` `.live-status` `.menu-item` `.menu-panel` `.menu-sep` `.menu-title` `.palette-empty` `.palette-foot` `.palette-group` `.palette-heading` `.palette-input` `.palette-item` `.palette-list` `.passkey` `.passkey-lead` `.passkey-note` `.passkey-off` `.passkey-on` `.preview` `.sep` `.split` `.sprite` `.swatch` `.table-scroll` `.tell-here` `.theme-apply` `.theme-option` `.tick` `.timeline` `.tl-dot` `.toast-body` `.topbar-search` |
| 395 | 395 | - **`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` |
| 396 | - **`style/content.ts`, page furniture** — what frames a page's content: page and repo heads, the merge box, the front page and its tiles, explore, backups, boards, the fleet chart's series colours, following, lineage: `.about` `.act` `.app-shelf` `.app-tile` `.app-tile-body` `.app-tile-desc` `.app-tile-look` `.app-tile-name` `.backups-drill` `.backups-error` `.backups-now` `.backups-restore` `.bform` `.bgrid` `.big` `.bmanage` `.boards-result` `.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` `.chart` `.chart-box` `.commit-body` `.commit-head` `.connect-more` `.connect-path` `.domain-records` `.explore-filters` `.explore-line` `.explore-main` `.explore-name` `.explore-row` `.fg-s0` `.fg-s1` `.fg-s2` `.fg-s3` `.fg-s4` `.fg-s5` `.fg-s6` `.fg-s7` `.filters` `.flag-form` `.following` `.following-actions` `.following-eyebrow` `.following-foot` `.following-head` `.following-sentence` `.fork-bar` `.front-admin` `.front-controls` `.front-crew` `.front-featured` `.front-featured-body` `.front-featured-look` `.front-issues` `.front-live` `.front-more` `.front-pick` `.front-pin-any` `.front-weights` `.frozen` `.frozen-form` `.frozen-sentence` `.handoff` `.handoff-links` `.headroom` `.hero` `.hero-terminal` `.issue-head` `.issue-meta` `.lineage` `.lineage-children` `.lineage-here` `.merge-box` `.merge-form` `.merge-headline` `.merge-sub` `.mirror-form` `.number` `.origin-link` `.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` `.stage-detail` `.stage-dot` `.steps` `.sub` `.sys-pair` `.table-wrap` `.terminal-line` `.tok` `.tree-row` `.tree-total` `.wall-cells` `.where-sep` | |
| 396 | - **`style/content.ts`, page furniture** — what frames a page's content: page and repo heads, the merge box, the front page and its tiles, explore, backups, boards, the fleet chart's series colours, following, lineage: `.about` `.act` `.app-shelf` `.app-tile` `.app-tile-body` `.app-tile-desc` `.app-tile-look` `.app-tile-name` `.backups-drill` `.backups-error` `.backups-now` `.backups-restore` `.bform` `.bgrid` `.big` `.bmanage` `.boards-result` `.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` `.chart` `.chart-box` `.commit-body` `.commit-head` `.connect-more` `.connect-path` `.domain-records` `.explore-filters` `.explore-line` `.explore-main` `.explore-name` `.explore-row` `.fg-s0` `.fg-s1` `.fg-s2` `.fg-s3` `.fg-s4` `.fg-s5` `.fg-s6` `.fg-s7` `.filters` `.flag-form` `.following` `.following-actions` `.following-eyebrow` `.following-foot` `.following-head` `.following-sentence` `.fork-bar` `.front-admin` `.front-controls` `.front-crew` `.front-featured` `.front-featured-body` `.front-featured-look` `.front-issues` `.front-live` `.front-more` `.front-pick` `.front-pin-any` `.front-weights` `.frozen` `.frozen-form` `.frozen-sentence` `.handoff` `.handoff-links` `.headroom` `.hero` `.hero-terminal` `.issue-head` `.issue-meta` `.lineage` `.lineage-children` `.lineage-here` `.merge-box` `.merge-form` `.merge-headline` `.merge-sub` `.number` `.origin-link` `.owner` `.page-head` `.path-head` `.policy-line` `.qf` `.repo-actions` `.repo-audience` `.repo-desc` `.repo-layout` `.repo-lineage` `.repo-title` `.search` `.slash` `.stage-detail` `.stage-dot` `.steps` `.sub` `.sys-pair` `.table-wrap` `.terminal-line` `.tok` `.tree-row` `.tree-total` `.wall-cells` `.where-sep` | |
| 397 | 397 | - **`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` |
| 398 | 398 | - **`style/content.ts`, prose (markdown)** — table cell alignment, built by `markdown.ts` as `ta-${align}`: `.ta-c` `.ta-r` |
| 399 | 399 | - **`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/pages/origins.ts +222 −195
| @@ -48,7 +48,11 @@ import { | ||
| 48 | 48 | } from "../../core/origins.ts"; |
| 49 | 49 | import { pinnedRepoIds } from "../../core/pins.ts"; |
| 50 | 50 | import { getRepo, getReposByIds } from "../../core/repos.ts"; |
| 51 | import { notePhase, takeSessionTime, timePhase } from "../../core/route_timing.ts"; | |
| 51 | import { | |
| 52 | notePhase, | |
| 53 | takeSessionTime, | |
| 54 | timePhase, | |
| 55 | } from "../../core/route_timing.ts"; | |
| 52 | 56 | import type { Ctx } from "../../http/context.ts"; |
| 53 | 57 | import { forgeBaseUrl, oauthCallbackUri } from "../../http/api.ts"; |
| 54 | 58 | import { qrEncode, qrSvg } from "../../design/qr.ts"; |
| @@ -106,7 +110,12 @@ export type AccountSection = | ||
| 106 | 110 | * admin's section — an agent is an account that acts — so it is on the nav |
| 107 | 111 | * only for one, the way the repo header hides Settings from a non-admin. |
| 108 | 112 | */ |
| 109 | const USAGE: ReadonlySet<AccountSection> = new Set(["usage", "spend", "capacity", "telemetry"]); | |
| 113 | const USAGE: ReadonlySet<AccountSection> = new Set([ | |
| 114 | "usage", | |
| 115 | "spend", | |
| 116 | "capacity", | |
| 117 | "telemetry", | |
| 118 | ]); | |
| 110 | 119 | |
| 111 | 120 | export function accountSections( |
| 112 | 121 | current: AccountSection, |
| @@ -313,31 +322,27 @@ function reauthNote(origin: Origin, mirrors: number): Html { | ||
| 313 | 322 | function originCard(origin: Origin, mirrors: number): Html { |
| 314 | 323 | const base = `/settings/origins/${origin.id}`; |
| 315 | 324 | return card( |
| 316 | html`<div class="origin-row"> | |
| 317 | <span class="origin-mark">${icon(originIcon(origin.kind))}</span> | |
| 318 | <span class="grow"> | |
| 319 | <span class="origin-name" | |
| 320 | >${origin.login}<span class="muted"> @ </span>${hostLabel( | |
| 325 | html`<ul class="list setting-list"> | |
| 326 | ${row({ | |
| 327 | lead: icon(originIcon(origin.kind)), | |
| 328 | title: html`${origin.login}<span class="muted"> @ </span>${hostLabel( | |
| 321 | 329 | origin.webUrl, |
| 322 | )}</span | |
| 323 | > | |
| 324 | <span class="row-meta muted small" | |
| 325 | >${origin.authKind === "oauth" ? "OAuth" : "personal access token"} | |
| 326 | · | |
| 327 | ${origin.lastSyncAt === null | |
| 330 | )}`, | |
| 331 | meta: html`${ | |
| 332 | origin.authKind === "oauth" ? "OAuth" : "personal access token" | |
| 333 | } | |
| 334 | · | |
| 335 | ${ | |
| 336 | origin.lastSyncAt === null | |
| 328 | 337 | ? html`never synced` |
| 329 | : html`synced ${time(origin.lastSyncAt)}`}</span | |
| 330 | > | |
| 331 | ${when( | |
| 338 | : html`synced ${time(origin.lastSyncAt)}` | |
| 339 | }${when( | |
| 332 | 340 | isTrustedHost(URL.parse(origin.webUrl)?.hostname ?? ""), |
| 333 | () => | |
| 334 | html`<span class="row-meta muted small" | |
| 335 | >trusted internal host</span | |
| 336 | >`, | |
| 337 | )} | |
| 338 | </span> | |
| 339 | ${healthBadge(origin)} | |
| 340 | </div> | |
| 341 | () => html` · trusted internal host`, | |
| 342 | )}`, | |
| 343 | trail: healthBadge(origin), | |
| 344 | })} | |
| 345 | </ul> | |
| 341 | 346 | ${when( |
| 342 | 347 | origin.lastError !== "", |
| 343 | 348 | () => html`<p class="error-note mt">${origin.lastError}</p>`, |
| @@ -509,9 +514,9 @@ function forgejoSection( | ||
| 509 | 514 | <li> |
| 510 | 515 | Open |
| 511 | 516 | <span class="mono" |
| 512 | >${values.host === "" | |
| 513 | ? "https://your.forge" | |
| 514 | : values.host}/user/settings/applications</span | |
| 517 | >${ | |
| 518 | values.host === "" ? "https://your.forge" : values.host | |
| 519 | }/user/settings/applications</span | |
| 515 | 520 | >. |
| 516 | 521 | </li> |
| 517 | 522 | <li> |
| @@ -642,10 +647,10 @@ function trustedHostsCard(text: string, error?: string): Html { | ||
| 642 | 647 | return card( |
| 643 | 648 | html`<h3>${icon("lock")}Trusted internal hosts</h3> |
| 644 | 649 | <p class="muted small"> |
| 645 | Origins on these exact host names may resolve to a private address | |
| 646 | (your own Forgejo, reached inside the cluster). Webhooks never do. | |
| 647 | Separate names with a space, comma or new line; addresses, wildcards and | |
| 648 | URLs are not accepted. | |
| 650 | Origins on these exact host names may resolve to a private address (your | |
| 651 | own Forgejo, reached inside the cluster). Webhooks never do. Separate | |
| 652 | names with a space, comma or new line; addresses, wildcards and URLs are | |
| 653 | not accepted. | |
| 649 | 654 | </p> |
| 650 | 655 | ${when( |
| 651 | 656 | fixed.length > 0, |
| @@ -698,22 +703,26 @@ function originsView( | ||
| 698 | 703 | issues, pulls and comments come with them — and anything you do here is |
| 699 | 704 | written through to the origin first. |
| 700 | 705 | </p> |
| 701 | ${origins.length === 0 | |
| 702 | ? empty({ | |
| 703 | icon: "globe", | |
| 704 | title: "No origins connected", | |
| 705 | note: "Connect GitHub, a Forgejo instance or a Gitea instance and its repositories become mirrorable here.", | |
| 706 | }) | |
| 707 | : html`<div class="stack"> | |
| 708 | ${origins.map((o) => originCard(o, mirrors.get(o.id)?.count ?? 0))} | |
| 709 | </div>`} | |
| 706 | ${ | |
| 707 | origins.length === 0 | |
| 708 | ? empty({ | |
| 709 | icon: "globe", | |
| 710 | title: "No origins connected", | |
| 711 | note: "Connect GitHub, a Forgejo instance or a Gitea instance and its repositories become mirrorable here.", | |
| 712 | }) | |
| 713 | : html`<div class="stack"> | |
| 714 | ${origins.map((o) => originCard(o, mirrors.get(o.id)?.count ?? 0))} | |
| 715 | </div>` | |
| 716 | } | |
| 710 | 717 | ${frozenCard(frozen)} |
| 711 | ${mayEditTrustedHosts(user) | |
| 712 | ? trustedHostsCard( | |
| 713 | values.trustedText ?? editableHosts().join("\n"), | |
| 714 | values.trustedError, | |
| 715 | ) | |
| 716 | : null} | |
| 718 | ${ | |
| 719 | mayEditTrustedHosts(user) | |
| 720 | ? trustedHostsCard( | |
| 721 | values.trustedText ?? editableHosts().join("\n"), | |
| 722 | values.trustedError, | |
| 723 | ) | |
| 724 | : null | |
| 725 | } | |
| 717 | 726 | ${card( |
| 718 | 727 | html`${tokenSection(values)} |
| 719 | 728 | <details |
| @@ -767,7 +776,10 @@ function readFrozen(ctx: Ctx) { | ||
| 767 | 776 | return { frozen, repos }; |
| 768 | 777 | } |
| 769 | 778 | |
| 770 | function frozenCard({ frozen, repos }: ReturnType<typeof readFrozen>): Html | null { | |
| 779 | function frozenCard({ | |
| 780 | frozen, | |
| 781 | repos, | |
| 782 | }: ReturnType<typeof readFrozen>): Html | null { | |
| 771 | 783 | if (frozen.length === 0) return null; |
| 772 | 784 | return listCard( |
| 773 | 785 | frozen.flatMap((m) => { |
| @@ -779,10 +791,9 @@ function frozenCard({ frozen, repos }: ReturnType<typeof readFrozen>): Html | nu | ||
| 779 | 791 | href: `/${repo.ownerName}/${repo.name}`, |
| 780 | 792 | lead: icon("repo"), |
| 781 | 793 | title: `${repo.ownerName}/${repo.name}`, |
| 782 | meta: html`mirrors <span class="mono">${m.fullName}</span>${host === | |
| 783 | "" | |
| 784 | ? null | |
| 785 | : html` at ${host}`}`, | |
| 794 | meta: html`mirrors <span class="mono">${m.fullName}</span>${ | |
| 795 | host === "" ? null : html` at ${host}` | |
| 796 | }`, | |
| 786 | 797 | }), |
| 787 | 798 | ]; |
| 788 | 799 | }), |
| @@ -843,9 +854,11 @@ export function originsPage(ctx: Ctx): Response { | ||
| 843 | 854 | ? html`<div class="toast" data-tone="danger" role="status"> |
| 844 | 855 | ${icon("alert")} |
| 845 | 856 | <div class="toast-body"> |
| 846 | ${error === "state" | |
| 847 | ? "That authorization could not be matched to a connect you started here. Start again." | |
| 848 | : error.slice(0, 200)} | |
| 857 | ${ | |
| 858 | error === "state" | |
| 859 | ? "That authorization could not be matched to a connect you started here. Start again." | |
| 860 | : error.slice(0, 200) | |
| 861 | } | |
| 849 | 862 | </div> |
| 850 | 863 | </div>` |
| 851 | 864 | : null; |
| @@ -1144,15 +1157,15 @@ export function originFlowPage(ctx: Ctx): Response { | ||
| 1144 | 1157 | class="bar mt" |
| 1145 | 1158 | method="post" |
| 1146 | 1159 | action="${pollAction}" |
| 1147 | data-poll="${flow.flow === "device" | |
| 1148 | ? String(Math.max(1, flow.intervalSecs)) | |
| 1149 | : "0"}" | |
| 1160 | data-poll="${ | |
| 1161 | flow.flow === "device" ? String(Math.max(1, flow.intervalSecs)) : "0" | |
| 1162 | }" | |
| 1150 | 1163 | > |
| 1151 | 1164 | <span class="muted small" |
| 1152 | 1165 | >Waiting for you to authorize |
| 1153 | ${flow.flow === "device" | |
| 1154 | ? "on the other device" | |
| 1155 | : "on the instance"}…</span | |
| 1166 | ${ | |
| 1167 | flow.flow === "device" ? "on the other device" : "on the instance" | |
| 1168 | }…</span | |
| 1156 | 1169 | > |
| 1157 | 1170 | <span class="spacer"></span> |
| 1158 | 1171 | ${btn("Check again", { size: "sm", variant: "outline", icon: "sync" })} |
| @@ -1205,17 +1218,21 @@ function handoff(url: string, shortLink: string, openLabel?: string): Html { | ||
| 1205 | 1218 | const payload = shortLink === "" ? url : shortLink; |
| 1206 | 1219 | const code = qrEncode(payload); |
| 1207 | 1220 | return html`<div class="handoff"> |
| 1208 | ${code.ok | |
| 1209 | ? raw(qrSvg(code.value, { title: "Scan to open the link" })) | |
| 1210 | : null} | |
| 1221 | ${ | |
| 1222 | code.ok | |
| 1223 | ? raw(qrSvg(code.value, { title: "Scan to open the link" })) | |
| 1224 | : null | |
| 1225 | } | |
| 1211 | 1226 | <div class="handoff-links"> |
| 1212 | ${shortLink === "" | |
| 1213 | ? null | |
| 1214 | : html`<p class="muted small">Or open this on a phone:</p> | |
| 1215 | <div class="bar"> | |
| 1216 | <span class="mono" id="flow-short">${shortLink}</span> | |
| 1217 | ${copyBtn("flow-short", "Copy the short link")} | |
| 1218 | </div>`} | |
| 1227 | ${ | |
| 1228 | shortLink === "" | |
| 1229 | ? null | |
| 1230 | : html`<p class="muted small">Or open this on a phone:</p> | |
| 1231 | <div class="bar"> | |
| 1232 | <span class="mono" id="flow-short">${shortLink}</span> | |
| 1233 | ${copyBtn("flow-short", "Copy the short link")} | |
| 1234 | </div>` | |
| 1235 | } | |
| 1219 | 1236 | <p class="muted small mt">The full link:</p> |
| 1220 | 1237 | <div class="bar"> |
| 1221 | 1238 | <span class="mono small break" id="flow-url">${url}</span> |
| @@ -1421,133 +1438,143 @@ export async function originReposPage(ctx: Ctx): Promise<Response> { | ||
| 1421 | 1438 | ? "This account has nothing this token can see." |
| 1422 | 1439 | : "Nothing on this origin matches that filter.", |
| 1423 | 1440 | }) |
| 1424 | : listCard( | |
| 1425 | rows.map((remote) => { | |
| 1426 | const mirror = | |
| 1427 | remote.mirroredAs === null | |
| 1428 | ? undefined | |
| 1429 | : mirrors.get(remote.mirroredAs); | |
| 1430 | const pinned = mirror !== undefined && pins.has(mirror.id); | |
| 1431 | // Only offer a name box when the obvious one is taken: the | |
| 1432 | // mirror action picks a free name by itself otherwise. | |
| 1433 | const collides = | |
| 1434 | mirror === undefined && | |
| 1435 | getRepo( | |
| 1436 | ctx.app.db, | |
| 1437 | ctx.auth.user!.username, | |
| 1438 | remote.fullName.split("/")[1] ?? "", | |
| 1439 | ) !== undefined; | |
| 1440 | // Mirroring is no longer what enter does — the row opens the | |
| 1441 | // repository live, and this is the secondary verb beside it. | |
| 1442 | const counted = repoCounts({ | |
| 1443 | openIssues: remote.openIssues, | |
| 1444 | openPulls: remote.openPulls, | |
| 1445 | issuesIncludePulls: remote.openIssuesIncludingPulls, | |
| 1446 | }); | |
| 1447 | // Fork is the row's other verb: grabbing a repository you cannot | |
| 1448 | // push to is a different intention from keeping a copy of one, | |
| 1449 | // and making people open the repository first to find it out is | |
| 1450 | // a step in the way of the workflow this picker exists for. | |
| 1451 | const forkable = | |
| 1452 | !remote.canPush && !isOwnRepo(origin.login, remote.fullName); | |
| 1453 | const forkForm = when( | |
| 1454 | forkable, | |
| 1455 | () => | |
| 1456 | html`<form | |
| 1457 | class="mirror-form" | |
| 1458 | method="post" | |
| 1459 | action="${browseBase(origin.id, remote.fullName)}/fork" | |
| 1460 | > | |
| 1461 | ${btn("Fork", { | |
| 1462 | size: "sm", | |
| 1463 | variant: "ghost", | |
| 1464 | icon: "fork", | |
| 1465 | title: `Fork ${remote.fullName} into your account at ${hostLabel(origin.webUrl)}`, | |
| 1466 | })} | |
| 1467 | </form>`, | |
| 1468 | ); | |
| 1469 | const trail = | |
| 1470 | mirror !== undefined | |
| 1471 | ? html`${counted}${forkForm}${btn("Open mirror", { | |
| 1472 | href: `/${mirror.ownerName}/${mirror.name}`, | |
| 1473 | size: "sm", | |
| 1474 | variant: "outline", | |
| 1475 | icon: "repo", | |
| 1476 | })}` | |
| 1477 | : html`${counted}${forkForm} | |
| 1478 | <form | |
| 1479 | class="mirror-form" | |
| 1480 | method="post" | |
| 1481 | action="/settings/origins/${origin.id}/mirror" | |
| 1482 | > | |
| 1483 | <input | |
| 1484 | type="hidden" | |
| 1485 | name="fullName" | |
| 1486 | value="${remote.fullName}" | |
| 1487 | /> | |
| 1488 | ${when( | |
| 1489 | collides, | |
| 1441 | : card( | |
| 1442 | html`<ul class="list setting-list"> | |
| 1443 | ${rows.map((remote) => { | |
| 1444 | const mirror = | |
| 1445 | remote.mirroredAs === null | |
| 1446 | ? undefined | |
| 1447 | : mirrors.get(remote.mirroredAs); | |
| 1448 | const pinned = mirror !== undefined && pins.has(mirror.id); | |
| 1449 | // Only offer a name box when the obvious one is taken: the | |
| 1450 | // mirror action picks a free name by itself otherwise. | |
| 1451 | const collides = | |
| 1452 | mirror === undefined && | |
| 1453 | getRepo( | |
| 1454 | ctx.app.db, | |
| 1455 | ctx.auth.user!.username, | |
| 1456 | remote.fullName.split("/")[1] ?? "", | |
| 1457 | ) !== undefined; | |
| 1458 | // Mirroring is no longer what enter does — the row opens the | |
| 1459 | // repository live, and this is the secondary verb beside it. | |
| 1460 | const counted = repoCounts({ | |
| 1461 | openIssues: remote.openIssues, | |
| 1462 | openPulls: remote.openPulls, | |
| 1463 | issuesIncludePulls: remote.openIssuesIncludingPulls, | |
| 1464 | }); | |
| 1465 | // Fork is the row's other verb: grabbing a repository you cannot | |
| 1466 | // push to is a different intention from keeping a copy of one, | |
| 1467 | // and making people open the repository first to find it out is | |
| 1468 | // a step in the way of the workflow this picker exists for. | |
| 1469 | const forkable = | |
| 1470 | !remote.canPush && !isOwnRepo(origin.login, remote.fullName); | |
| 1471 | const forkForm = when( | |
| 1472 | forkable, | |
| 1473 | () => | |
| 1474 | html`<form | |
| 1475 | class="row-fields" | |
| 1476 | method="post" | |
| 1477 | action="${browseBase(origin.id, remote.fullName)}/fork" | |
| 1478 | > | |
| 1479 | ${btn("Fork", { | |
| 1480 | size: "sm", | |
| 1481 | variant: "ghost", | |
| 1482 | icon: "fork", | |
| 1483 | title: `Fork ${remote.fullName} into your account at ${hostLabel(origin.webUrl)}`, | |
| 1484 | })} | |
| 1485 | </form>`, | |
| 1486 | ); | |
| 1487 | const trail = | |
| 1488 | mirror !== undefined | |
| 1489 | ? html`${counted}${forkForm}${btn("Open mirror", { | |
| 1490 | href: `/${mirror.ownerName}/${mirror.name}`, | |
| 1491 | size: "sm", | |
| 1492 | variant: "outline", | |
| 1493 | icon: "repo", | |
| 1494 | })}` | |
| 1495 | : html`${counted}${forkForm} | |
| 1496 | <form | |
| 1497 | class="row-fields" | |
| 1498 | method="post" | |
| 1499 | action="/settings/origins/${origin.id}/mirror" | |
| 1500 | > | |
| 1501 | <input | |
| 1502 | type="hidden" | |
| 1503 | name="fullName" | |
| 1504 | value="${remote.fullName}" | |
| 1505 | /> | |
| 1506 | ${when( | |
| 1507 | collides, | |
| 1508 | () => | |
| 1509 | html`<input | |
| 1510 | class="input" | |
| 1511 | data-size="sm" | |
| 1512 | name="name" | |
| 1513 | placeholder="local name" | |
| 1514 | aria-label="Local name for ${remote.fullName}" | |
| 1515 | autocomplete="off" | |
| 1516 | />`, | |
| 1517 | )} | |
| 1518 | ${btn("Mirror", { | |
| 1519 | size: "sm", | |
| 1520 | variant: "outline", | |
| 1521 | icon: "download", | |
| 1522 | })} | |
| 1523 | </form>`; | |
| 1524 | return row({ | |
| 1525 | nav: true, | |
| 1526 | lead: icon(originIcon(origin.kind)), | |
| 1527 | // The row is not itself an anchor: it carries a form, and a | |
| 1528 | // form inside an <a> is markup the parser pulls apart. The | |
| 1529 | // title is the link, and `data-nav` opens it. | |
| 1530 | title: html`<a href="${browseBase(origin.id, remote.fullName)}" | |
| 1531 | >${remote.fullName}</a | |
| 1532 | > | |
| 1533 | ${ | |
| 1534 | remote.private | |
| 1535 | ? badge("Private", { icon: "lock", variant: "secondary" }) | |
| 1536 | : badge("Public", { variant: "outline" }) | |
| 1537 | } | |
| 1538 | ${when(remote.fork, () => | |
| 1539 | badge("Fork", { icon: "fork", variant: "outline" }), | |
| 1540 | )}`, | |
| 1541 | titleAttr: remote.fullName, | |
| 1542 | meta: html`${when( | |
| 1543 | mirror, | |
| 1544 | (m) => | |
| 1545 | html`<span class="where-place" data-state="present" | |
| 1546 | ><span aria-hidden="true">●</span>mirrored as | |
| 1547 | <a href="/${m.ownerName}/${m.name}" | |
| 1548 | >${m.ownerName}/${m.name}</a | |
| 1549 | ></span | |
| 1550 | >${when( | |
| 1551 | pinned, | |
| 1490 | 1552 | () => |
| 1491 | html`<input | |
| 1492 | class="input" | |
| 1493 | name="name" | |
| 1494 | placeholder="local name" | |
| 1495 | aria-label="Local name for ${remote.fullName}" | |
| 1496 | autocomplete="off" | |
| 1497 | />`, | |
| 1553 | html`<span class="where-sep" aria-hidden="true" | |
| 1554 | >·</span | |
| 1555 | ><span | |
| 1556 | class="where-place" | |
| 1557 | data-state="present" | |
| 1558 | title="Kept on your machine" | |
| 1559 | ><span aria-hidden="true">◆</span>this | |
| 1560 | machine</span | |
| 1561 | >`, | |
| 1498 | 1562 | )} |
| 1499 | ${btn("Mirror", { | |
| 1500 | size: "sm", | |
| 1501 | variant: "outline", | |
| 1502 | icon: "download", | |
| 1503 | })} | |
| 1504 | </form>`; | |
| 1505 | return row({ | |
| 1506 | nav: true, | |
| 1507 | lead: icon(originIcon(origin.kind)), | |
| 1508 | // The row is not itself an anchor: it carries a form, and a | |
| 1509 | // form inside an <a> is markup the parser pulls apart. The | |
| 1510 | // title is the link, and `data-nav` opens it. | |
| 1511 | title: html`<a href="${browseBase(origin.id, remote.fullName)}" | |
| 1512 | >${remote.fullName}</a | |
| 1513 | > | |
| 1514 | ${remote.private | |
| 1515 | ? badge("Private", { icon: "lock", variant: "secondary" }) | |
| 1516 | : badge("Public", { variant: "outline" })} | |
| 1517 | ${when(remote.fork, () => | |
| 1518 | badge("Fork", { icon: "fork", variant: "outline" }), | |
| 1519 | )}`, | |
| 1520 | titleAttr: remote.fullName, | |
| 1521 | meta: html`${when( | |
| 1522 | mirror, | |
| 1523 | (m) => | |
| 1524 | html`<span class="where-place" data-state="present" | |
| 1525 | ><span aria-hidden="true">●</span | |
| 1526 | >mirrored as | |
| 1527 | <a href="/${m.ownerName}/${m.name}" | |
| 1528 | >${m.ownerName}/${m.name}</a | |
| 1529 | ></span | |
| 1530 | >${when( | |
| 1531 | pinned, | |
| 1532 | () => | |
| 1533 | html`<span class="where-sep" aria-hidden="true">·</span | |
| 1534 | ><span | |
| 1535 | class="where-place" | |
| 1536 | data-state="present" | |
| 1537 | title="Kept on your machine" | |
| 1538 | ><span aria-hidden="true">◆</span | |
| 1539 | >this machine</span | |
| 1540 | >`, | |
| 1541 | )} | |
| 1542 | · `, | |
| 1543 | )}${remote.description !== "" | |
| 1544 | ? html`${remote.description} · ` | |
| 1545 | : null}${remote.pushedAt === null | |
| 1546 | ? html`never pushed` | |
| 1547 | : html`pushed ${time(remote.pushedAt)}`}`, | |
| 1548 | trail, | |
| 1549 | }); | |
| 1550 | }), | |
| 1563 | · `, | |
| 1564 | )}${ | |
| 1565 | remote.description !== "" | |
| 1566 | ? html`${remote.description} · ` | |
| 1567 | : null | |
| 1568 | }${ | |
| 1569 | remote.pushedAt === null | |
| 1570 | ? html`never pushed` | |
| 1571 | : html`pushed ${time(remote.pushedAt)}` | |
| 1572 | }`, | |
| 1573 | trail, | |
| 1574 | }); | |
| 1575 | })} | |
| 1576 | </ul>`, | |
| 1577 | { pad: false }, | |
| 1551 | 1578 | ); |
| 1552 | 1579 | |
| 1553 | 1580 | return page({ |
src/web/style/content.ts +3 −5
| @@ -148,9 +148,6 @@ a.origin-chip:hover { border-color: var(--border-strong); color: var(--fg); } | ||
| 148 | 148 | .origin-link:hover { color: var(--accent); } |
| 149 | 149 | |
| 150 | 150 | /* The origins settings page. */ |
| 151 | .origin-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; } | |
| 152 | .origin-row .origin-mark .ico { color: var(--muted-fg); } | |
| 153 | .origin-name { display: block; font-weight: 560; } | |
| 154 | 151 | .connect-path + .connect-path { margin-top: 20px; padding-top: 20px; border-top: 1px solid var(--border); } |
| 155 | 152 | /* The two OAuth paths, folded away. Both need somebody to register an |
| 156 | 153 | application once, and a page whose first control cannot be used until an |
| @@ -191,9 +188,10 @@ a.origin-chip:hover { border-color: var(--border-strong); color: var(--fg); } | ||
| 191 | 188 | .connect-path h3 { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; } |
| 192 | 189 | .connect-path h3 .ico { color: var(--muted-fg); } |
| 193 | 190 | .steps { margin: 8px 0 12px 18px; padding: 0; color: var(--muted-fg); } |
| 191 | /* The optional local name in a repository row's Mirror form: bounded, and it | |
| 192 | shrinks (row-fields gives it min-width:0) before it can push the button off a phone. */ | |
| 193 | .row-fields .input[name="name"] { width: 10rem; } | |
| 194 | 194 | .steps li + li { margin-top: 6px; } |
| 195 | .mirror-form { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; } | |
| 196 | .mirror-form .input { width: 10rem; padding: 4px 8px; font-size: 13px; } | |
| 197 | 195 | |
| 198 | 196 | /* A device code is read aloud across a room and typed on a phone: it is the |
| 199 | 197 | one place in the product where type is deliberately large. */ |
test/web-origins.test.ts +41
| @@ -14,6 +14,7 @@ import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | ||
| 14 | 14 | import { mkdtemp, rm } from "node:fs/promises"; |
| 15 | 15 | import { tmpdir } from "node:os"; |
| 16 | 16 | import { join } from "node:path"; |
| 17 | import { createRepo } from "../src/actions/repos.ts"; | |
| 17 | 18 | import { createApp, type App } from "../src/app.ts"; |
| 18 | 19 | import { serve, type Servers } from "../src/http/server.ts"; |
| 19 | 20 | import { enableApp } from "../src/actions/apps.ts"; |
| @@ -225,6 +226,12 @@ describe("origins on the web", () => { | ||
| 225 | 226 | expect(html).toContain("personal access token"); |
| 226 | 227 | // The one thing that must never be on this page. |
| 227 | 228 | expect(html).not.toContain(ORIGIN_TOKEN); |
| 229 | // Drawn with the shared row, not the page's own classes. | |
| 230 | expect(html).toContain("row-title"); | |
| 231 | // Title and meta wrap on a phone instead of ellipsizing. | |
| 232 | expect(html).toContain('<ul class="list setting-list">'); | |
| 233 | for (const gone of ["origin-row", "origin-name", "origin-mark", "mirror-form"]) | |
| 234 | expect(html).not.toContain(gone); | |
| 228 | 235 | |
| 229 | 236 | const stored = listOrigins(app.db, getUserByName(app.db, "alice")!.id); |
| 230 | 237 | expect(stored).toHaveLength(1); |
| @@ -293,6 +300,40 @@ describe("origins on the web", () => { | ||
| 293 | 300 | expect(html).not.toContain("Mirror all"); |
| 294 | 301 | }); |
| 295 | 302 | |
| 303 | test("a taken name puts a bounded local-name input in a row-fields Mirror form", async () => { | |
| 304 | const id = listOrigins(app.db, getUserByName(app.db, "alice")!.id)[0]!.id; | |
| 305 | const clash = await createRepo(app, getUserByName(app.db, "alice")!, { | |
| 306 | name: "gadgets", | |
| 307 | visibility: "private", | |
| 308 | }); | |
| 309 | expect(clash.ok).toBe(true); | |
| 310 | forgejo.state.repos.push({ | |
| 311 | id: 42, | |
| 312 | fullName: "octo/gadgets", | |
| 313 | cloneUrl: `${originServers.url}/octo/gadgets.git`, | |
| 314 | htmlUrl: `${originServers.url}/octo/gadgets`, | |
| 315 | defaultBranch: "main", | |
| 316 | }); | |
| 317 | try { | |
| 318 | const html = await ( | |
| 319 | await asUser(alice, `/settings/origins/${id}/repos?refresh=1`) | |
| 320 | ).text(); | |
| 321 | const form = html.match( | |
| 322 | /<form\s[^>]*?action="\/settings\/origins\/[^"/]+\/mirror"[\s\S]*?<\/form>/g, | |
| 323 | )!; | |
| 324 | const gadgets = form.find((f) => /gadgets/.test(f))!; | |
| 325 | expect(gadgets).toContain('class="row-fields"'); | |
| 326 | expect(gadgets).toMatch(/<input[^>]*class="input"/); | |
| 327 | expect(gadgets).toContain('aria-label="Local name for octo/gadgets"'); | |
| 328 | // No clash, no box: the widgets row has only the hidden field. | |
| 329 | const widgets = form.find((f) => /widgets/.test(f))!; | |
| 330 | expect(widgets).toContain('class="row-fields"'); | |
| 331 | expect(widgets).not.toContain("Local name"); | |
| 332 | } finally { | |
| 333 | forgejo.state.repos = forgejo.state.repos.filter((r) => r.id !== 42); | |
| 334 | } | |
| 335 | }); | |
| 336 | ||
| 296 | 337 | test("Mirror starts a job, shows its stages, and lands on the mirror", async () => { |
| 297 | 338 | const id = listOrigins(app.db, getUserByName(app.db, "alice")!.id)[0]!.id; |
| 298 | 339 | const mirrored = await asUser(alice, `/settings/origins/${id}/mirror`, { |
new above
offline