Public: anyone can read this; the crew can change it.
On a preview, the pill's "Preview of pull #N" line is a link to that pull on the forge #7851
Check · Review · Land · Live done — Landed and live in production.
torque/forge:torque/7849-on-a-preview-the-pill-s-preview-of-pull → main 1 commit fork
2 files
changed +29
−2
src/apps/toolbar.ts +15 −2
| @@ -70,9 +70,22 @@ export const toolbarJs = `(function () { | ||
| 70 | 70 | } |
| 71 | 71 | if (d.app) line(d.app, true); |
| 72 | 72 | if (d.env === "production") line("Production"); |
| 73 | else if (d.pull) line("Preview of pull #" + d.pull); | |
| 74 | if (d.title) line(d.title); | |
| 75 | 73 | var LS = "color:#8ab4ff;text-decoration:none;display:flex;align-items:center;min-height:44px"; |
| 74 | var pullHref = ""; | |
| 75 | // The pull this preview shows, one tap away: built from the script's own origin, never from page text. | |
| 76 | if (d.env !== "production" && /^\\d{1,9}$/.test(d.pull || "") && /^[\\w.-]+\\/[\\w.-]+$/.test(d.repo || "")) { | |
| 77 | try { pullHref = new URL("/" + d.repo + "/pulls/" + d.pull, me.src).href; } catch (e) {} | |
| 78 | } | |
| 79 | if (d.env === "production") {} | |
| 80 | else if (pullHref) { | |
| 81 | var pl = document.createElement("a"); | |
| 82 | pl.textContent = "Preview of pull #" + d.pull; | |
| 83 | pl.href = pullHref; | |
| 84 | pl.rel = "noopener"; | |
| 85 | pl.style.cssText = LS; | |
| 86 | panel.appendChild(pl); | |
| 87 | } else if (d.pull) line("Preview of pull #" + d.pull); | |
| 88 | if (d.title) line(d.title); | |
| 76 | 89 | var link = document.createElement("a"); |
| 77 | 90 | link.textContent = "Home"; |
| 78 | 91 | link.rel = "noopener"; |
test/apps-toolbar.test.ts +14
| @@ -449,6 +449,20 @@ describe("the pill's keyboard and touch behaviour", () => { | ||
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | |
| 452 | test("on a preview with a repo the pull line links to the pull; otherwise it is plain text", () => { | |
| 453 | const a = tree({ app: "notes", repo: "alice/notes", pull: "12" }).lines.find((l) => l.textContent === "Preview of pull #12")!; | |
| 454 | expect(a.tag).toBe("a"); | |
| 455 | expect(a.href).toBe("https://forge.test/alice/notes/pulls/12"); | |
| 456 | expect(a.style.cssText).toContain("min-height:44px"); | |
| 457 | const prod = tree({ app: "notes", repo: "alice/notes", env: "production", pull: "12" }); | |
| 458 | expect(prod.lines.some((l) => l.textContent.includes("Preview"))).toBe(false); | |
| 459 | for (const bad of [{ pull: "12x" }, { pull: "../1" }, { pull: "1234567890" }, { repo: "" }]) { | |
| 460 | const t = tree({ app: "notes", repo: "alice/notes", pull: "12", ...bad }); | |
| 461 | const l = t.lines.find((x) => x.textContent.startsWith("Preview of pull"))!; | |
| 462 | expect(l.tag === "a").toBe(false); | |
| 463 | } | |
| 464 | }); | |
| 465 | ||
| 452 | 466 | test("the panel is a labelled region, opens with focus inside, and Escape returns focus to the pill", () => { |
| 453 | 467 | const { doc, pill, panel } = tree({ app: "notes", env: "production" }); |
| 454 | 468 | expect(panel.attrs["aria-label"]).toBeTruthy(); |
new above
offline