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

Each app in /explore has a Make it yours button that forks it in one confirmed step #14118

Merged opened this

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

Merged

mason/forge:mason/14065-each-app-in-explore-has-a-make-it-yours → main 6 commits fork 1 thread · 1 unresolved

  • Merged. mason/14065-each-app-in-explore-has-a-make-it-yours was merged into main as 2dae7a5.

Review

Sign in to review this change.
4 files changed +53 −23
src/web/studio/explore.ts +10 −13
@@ -42,7 +42,7 @@ const href = (query: ExploreQuery, page = 1): string => {
4242 return text === "" ? "/explore" : `/explore?${text}`;
4343 };
4444
45 function rowHtml(row: ExploreRow, signedIn: boolean, query: ExploreQuery, now: number, weights: FrontWeights): Html {
45 function rowHtml(row: ExploreRow, query: ExploreQuery, now: number, weights: FrontWeights): Html {
4646 const why = whyOf(row, query.sort, now, weights);
4747 // One row: what it does in plain words, then the one signal that explains its place.
4848 // Apps say their counts and keep the dated `<time>`: the absolute date stays in its title.
@@ -62,23 +62,20 @@ function rowHtml(row: ExploreRow, signedIn: boolean, query: ExploreQuery, now: n
6262 : {
6363 after: html`<details class="row-forks" data-forks>
6464 <summary class="muted small">${forked.length} fork${forked.length === 1 ? "" : "s"}</summary>
65 <ul class="list">${forked.map((f) => rowHtml(f, signedIn, query, now, weights))}</ul>
65 <ul class="list">${forked.map((f) => rowHtml(f, query, now, weights))}</ul>
6666 </details>`,
6767 }),
6868 title: html`<a href="${row.url}">${row.name}</a>${nameMark(row.mark)}`,
6969 ...(parts.length === 0 ? {} : { meta: metaHtml }),
7070 ...(row.copyable === true && row.repo !== undefined
7171 ? {
72 trail: signedIn
73 ? html`<form method="post" action="/${row.repo.owner}/${row.repo.name}/make-it-yours" data-make-it-yours>
74 <input type="hidden" name="receipt" value="1" />
75 ${btn(MAKE_IT_YOURS.label, { size: "sm", icon: "fork" })}
76 </form>`
77 : btn(MAKE_IT_YOURS.label, {
78 href: `/${row.repo.owner}/${row.repo.name}/make-it-yours?receipt=1`,
79 size: "sm",
80 icon: "fork",
81 }),
72 // Signed in or out, the button opens the preview of what will be made;
73 // the confirm is on that page (signed out, it asks to sign in first).
74 trail: btn(MAKE_IT_YOURS.label, {
75 href: `/${row.repo.owner}/${row.repo.name}/make-it-yours?receipt=1`,
76 size: "sm",
77 icon: "fork",
78 }),
8279 }
8380 : {}),
8481 });
@@ -309,7 +306,7 @@ export async function explorePage(ctx: Ctx): Promise<Response> {
309306 <p class="mb small">${countLine(query, shown.total, ctx.auth.user?.isAdmin === true)}</p>
310307 ${rows.length === 0
311308 ? emptyState(ctx, query)
312 : card(html`<ul class="list">${rows.map((r) => rowHtml(r, ctx.auth.user !== undefined, query, now, weights))}</ul>`, {
309 : card(html`<ul class="list">${rows.map((r) => rowHtml(r, query, now, weights))}</ul>`, {
313310 pad: false,
314311 extra: "bare",
315312 })}${pager(query, shown.page, shown.pages)}</div>`;
test/explore-fork.test.ts +1 −1
@@ -101,7 +101,7 @@ describe("explore: make it yours", () => {
101101 });
102102
103103 test("signed in: one POST forks and lands on the fork", async () => {
104 expect((await explore(bobCookie)).match(/data-make-it-yours/g)?.length).toBe(1);
104 expect((await explore(bobCookie)).match(/href="\/alice\/open\/make-it-yours\?receipt=1"/g)?.length).toBe(1);
105105 const res = await fetch(`${servers.url}/alice/open/make-it-yours`, {
106106 method: "POST",
107107 headers: { cookie: bobCookie, origin: servers.url, "content-type": "application/x-www-form-urlencoded" },
test/explore.test.ts +4 −4
@@ -246,7 +246,7 @@ describe("explore", () => {
246246 headers: { authorization: `Bearer ${bobToken}` },
247247 })
248248 ).text();
249 expect(signedIn).toContain('action="/alice/loved/make-it-yours"');
249 expect(signedIn).toContain('href="/alice/loved/make-it-yours?receipt=1"');
250250 const res = await fetch(`${base}/mcp`, {
251251 method: "POST",
252252 headers: {
@@ -308,9 +308,9 @@ describe("explore", () => {
308308 const asBob = await (
309309 await fetch(`${base}/explore`, { headers: { authorization: `Bearer ${bobToken}` } })
310310 ).text();
311 expect(asBob).toContain('action="/alice/loved/make-it-yours"');
311 expect(asBob).toContain('href="/alice/loved/make-it-yours?receipt=1"');
312312 // alice/gated is a public repository whose app only its writers enter.
313 expect(asBob).not.toContain('action="/alice/gated/make-it-yours"');
313 expect(asBob).not.toContain('href="/alice/gated/make-it-yours?receipt=1"');
314314 const rows = (await api("kind:app", bobToken)).items;
315315 expect(rows.find((r) => r.name === "alice/gated").copyable).toBe(false);
316316 expect(rows.find((r) => r.name === "alice/loved").copyable).toBe(true);
@@ -318,7 +318,7 @@ describe("explore", () => {
318318 const asAlice = await (
319319 await fetch(`${base}/explore`, { headers: { authorization: `Bearer ${aliceToken}` } })
320320 ).text();
321 expect(asAlice).not.toContain('action="/alice/loved/make-it-yours"');
321 expect(asAlice).not.toContain('href="/alice/loved/make-it-yours?receipt=1"');
322322 });
323323
324324 test("Make it yours is offered to a signed-out visitor on public apps only, linking to the make-it-yours path", async () => {
test/explorer-make-it-yours.test.ts +38 −5
@@ -93,8 +93,41 @@ describe("explorer: make it yours", () => {
9393 expect(rows).toBe(2);
9494 expect(page.match(/Make it yours/g)?.length).toBe(rows);
9595 }
96 // Signed in, the action is a form that posts: one tap.
97 expect((await explore(bobCookie)).match(/data-make-it-yours/g)?.length).toBe(2);
96 // Signed in or out, the button opens the preview, never a bare POST.
97 const signedIn = await explore(bobCookie);
98 expect(signedIn).not.toContain("data-make-it-yours");
99 expect(signedIn).toContain('href="/alice/garden/make-it-yours?receipt=1"');
100 });
101
102 test("the preview says what will be made and its confirm posts with the receipt", async () => {
103 const res = await fetch(`${servers.url}/alice/garden/make-it-yours?receipt=1`, { headers: { cookie: bobCookie } });

Add the signed-out and already-forked preview cases here (see the review body); only the signed-in preview is asserted.

104 const page = await res.text();
105 expect(page).toContain("bob/garden");
106 expect(page).toContain("Not copied");
107 expect(page).toContain('action="/alice/garden/make-it-yours"');
108 expect(page).toContain('name="receipt"');
109 expect(getRepo(app.db, "bob", "garden")).toBeUndefined();
110 });
111
112 test("signed out, the preview asks to sign in and offers no confirm", async () => {
113 const res = await fetch(`${servers.url}/alice/garden/make-it-yours?receipt=1`, { redirect: "manual" });
114 const body = await res.text();
115 expect(res.status).toBe(303);
116 expect(res.headers.get("location")).toBe("/signin?next=%2Falice%2Fgarden%2Fmake-it-yours%3Freceipt%3D1");
117 expect(body).not.toContain('action="/alice/garden/make-it-yours"');
118 expect(getRepo(app.db, "bob", "garden")).toBeUndefined();
119 });
120
121 test("a viewer who already forked it sees Open mine and no second confirm to make", async () => {
122 expect((await post("/alice/garden/make-it-yours", "receipt=1")).status).toBe(303);
123 const page = await (
124 await fetch(`${servers.url}/alice/garden/make-it-yours?receipt=1`, { headers: { cookie: bobCookie } })
125 ).text();
126 expect(page).toContain("Open mine");
127 expect(page).toContain("You already have");
128 expect(page).not.toContain(">Make it yours</button>");
129 expect(page).not.toContain('name="visibility"');
130 await post("/alice/garden/make-it-yours/undo");
98131 });
99132
100133 test("one tap forks, the receipt says so, undo takes it back", async () => {
@@ -228,9 +261,9 @@ describe("explorer: page and MCP words match", () => {
228261 // The page's own button for this row, as bob sees it, says the same words.
229262 const bobCookie = `forge_session=${createSession(app.db, bob.id).token}`;
230263 const page = await (await fetch(`${servers.url}/explore?q=kind%3Aapp`, { headers: { cookie: bobCookie } })).text();
231 const form = page.match(/<form method="post" action="\/alice\/garden\/make-it-yours" data-make-it-yours>[\s\S]*?<\/form>/)?.[0];
232 expect(form).toBeDefined();
233 expect(form!.match(/<button[\s\S]*?<\/button>/)?.[0]).toContain(row.action.label);
264 const link = page.match(/<a [^>]*href="\/alice\/garden\/make-it-yours\?receipt=1"[\s\S]*?<\/a>/)?.[0];
265 expect(link).toBeDefined();
266 expect(link).toContain(row.action.label);
234267 // The named action is a tool that answers, and previews first.
235268 const prev = await fetch(`${servers.url}/mcp`, {
236269 method: "POST",

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs