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
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/14065-each-app-in-explore-has-a-make-it-yours → main 6 commits fork 1 thread · 1 unresolved
4 files
changed +53
−23
src/web/studio/explore.ts +10 −13
| @@ -42,7 +42,7 @@ const href = (query: ExploreQuery, page = 1): string => { | ||
| 42 | 42 | return text === "" ? "/explore" : `/explore?${text}`; |
| 43 | 43 | }; |
| 44 | 44 | |
| 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 { | |
| 46 | 46 | const why = whyOf(row, query.sort, now, weights); |
| 47 | 47 | // One row: what it does in plain words, then the one signal that explains its place. |
| 48 | 48 | // 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 | ||
| 62 | 62 | : { |
| 63 | 63 | after: html`<details class="row-forks" data-forks> |
| 64 | 64 | <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> | |
| 66 | 66 | </details>`, |
| 67 | 67 | }), |
| 68 | 68 | title: html`<a href="${row.url}">${row.name}</a>${nameMark(row.mark)}`, |
| 69 | 69 | ...(parts.length === 0 ? {} : { meta: metaHtml }), |
| 70 | 70 | ...(row.copyable === true && row.repo !== undefined |
| 71 | 71 | ? { |
| 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 | }), | |
| 82 | 79 | } |
| 83 | 80 | : {}), |
| 84 | 81 | }); |
| @@ -309,7 +306,7 @@ export async function explorePage(ctx: Ctx): Promise<Response> { | ||
| 309 | 306 | <p class="mb small">${countLine(query, shown.total, ctx.auth.user?.isAdmin === true)}</p> |
| 310 | 307 | ${rows.length === 0 |
| 311 | 308 | ? 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>`, { | |
| 313 | 310 | pad: false, |
| 314 | 311 | extra: "bare", |
| 315 | 312 | })}${pager(query, shown.page, shown.pages)}</div>`; |
test/explore-fork.test.ts +1 −1
| @@ -101,7 +101,7 @@ describe("explore: make it yours", () => { | ||
| 101 | 101 | }); |
| 102 | 102 | |
| 103 | 103 | 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); | |
| 105 | 105 | const res = await fetch(`${servers.url}/alice/open/make-it-yours`, { |
| 106 | 106 | method: "POST", |
| 107 | 107 | 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", () => { | ||
| 246 | 246 | headers: { authorization: `Bearer ${bobToken}` }, |
| 247 | 247 | }) |
| 248 | 248 | ).text(); |
| 249 | expect(signedIn).toContain('action="/alice/loved/make-it-yours"'); | |
| 249 | expect(signedIn).toContain('href="/alice/loved/make-it-yours?receipt=1"'); | |
| 250 | 250 | const res = await fetch(`${base}/mcp`, { |
| 251 | 251 | method: "POST", |
| 252 | 252 | headers: { |
| @@ -308,9 +308,9 @@ describe("explore", () => { | ||
| 308 | 308 | const asBob = await ( |
| 309 | 309 | await fetch(`${base}/explore`, { headers: { authorization: `Bearer ${bobToken}` } }) |
| 310 | 310 | ).text(); |
| 311 | expect(asBob).toContain('action="/alice/loved/make-it-yours"'); | |
| 311 | expect(asBob).toContain('href="/alice/loved/make-it-yours?receipt=1"'); | |
| 312 | 312 | // 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"'); | |
| 314 | 314 | const rows = (await api("kind:app", bobToken)).items; |
| 315 | 315 | expect(rows.find((r) => r.name === "alice/gated").copyable).toBe(false); |
| 316 | 316 | expect(rows.find((r) => r.name === "alice/loved").copyable).toBe(true); |
| @@ -318,7 +318,7 @@ describe("explore", () => { | ||
| 318 | 318 | const asAlice = await ( |
| 319 | 319 | await fetch(`${base}/explore`, { headers: { authorization: `Bearer ${aliceToken}` } }) |
| 320 | 320 | ).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"'); | |
| 322 | 322 | }); |
| 323 | 323 | |
| 324 | 324 | 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", () => { | ||
| 93 | 93 | expect(rows).toBe(2); |
| 94 | 94 | expect(page.match(/Make it yours/g)?.length).toBe(rows); |
| 95 | 95 | } |
| 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 } }); | |
| 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"); | |
| 98 | 131 | }); |
| 99 | 132 | |
| 100 | 133 | test("one tap forks, the receipt says so, undo takes it back", async () => { |
| @@ -228,9 +261,9 @@ describe("explorer: page and MCP words match", () => { | ||
| 228 | 261 | // The page's own button for this row, as bob sees it, says the same words. |
| 229 | 262 | const bobCookie = `forge_session=${createSession(app.db, bob.id).token}`; |
| 230 | 263 | 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); | |
| 234 | 267 | // The named action is a tool that answers, and previews first. |
| 235 | 268 | const prev = await fetch(`${servers.url}/mcp`, { |
| 236 | 269 | method: "POST", |
new above
offline
Add the signed-out and already-forked preview cases here (see the review body); only the signed-in preview is asserted.