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

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

torque/forge:torque/7849-on-a-preview-the-pill-s-preview-of-pull → main 1 commit fork

  • Merged. torque/7849-on-a-preview-the-pill-s-preview-of-pull was merged into main as 2afe4c1.

Review

Sign in to review this change.
2 files changed +29 −2
src/apps/toolbar.ts +15 −2
@@ -70,9 +70,22 @@ export const toolbarJs = `(function () {
7070 }
7171 if (d.app) line(d.app, true);
7272 if (d.env === "production") line("Production");
73 else if (d.pull) line("Preview of pull #" + d.pull);
74 if (d.title) line(d.title);
7573 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);
7689 var link = document.createElement("a");
7790 link.textContent = "Home";
7891 link.rel = "noopener";
test/apps-toolbar.test.ts +14
@@ -449,6 +449,20 @@ describe("the pill's keyboard and touch behaviour", () => {
449449 }
450450
451451
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
452466 test("the panel is a labelled region, opens with focus inside, and Escape returns focus to the pill", () => {
453467 const { doc, pill, panel } = tree({ app: "notes", env: "production" });
454468 expect(panel.attrs["aria-label"]).toBeTruthy();

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs