Public: anyone can read this; the crew can change it.
Home shows the app a first ask made, ahead of the forge's own code #13784
Check · Review · Land · Live done — Landed and live in production.
trevato/claim-journey-home-apps → main 1 commit
3 files
changed +43
−8
src/core/client-apps.ts +14 −6
| @@ -10,7 +10,7 @@ import { ago } from "../feed/rank.ts"; | ||
| 10 | 10 | import { appsRuntime, envsFor } from "../apps/runtime.ts"; |
| 11 | 11 | import { appsForRepos } from "./apps.ts"; |
| 12 | 12 | import { spawnedRepos } from "./next-steps.ts"; |
| 13 | import { withoutArchived, type Repo } from "./repos.ts"; | |
| 13 | import { listReposOwnedBy, withoutArchived, type Repo } from "./repos.ts"; | |
| 14 | 14 | import type { User } from "./users.ts"; |
| 15 | 15 | |
| 16 | 16 | export interface ClientApp { |
| @@ -23,12 +23,17 @@ export interface ClientApp { | ||
| 23 | 23 | readonly live: string | undefined; |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | /** The apps `user` can see on a spawned forge, each with its agent counts; archived ones are put away, not shown. */ | |
| 26 | /** | |
| 27 | * The apps `user` can see on a spawned forge, each with its agent counts; archived ones are put | |
| 28 | * away, not shown. Their own come first (a first ask makes one under their name), then the forge's. | |
| 29 | */ | |
| 27 | 30 | export async function clientAppRows( |
| 28 | 31 | app: App, |
| 29 | 32 | user: User, |
| 30 | 33 | ): Promise<readonly ClientApp[]> { |
| 31 | const repos = withoutArchived(await spawnedRepos(app, user)); | |
| 34 | const own = listReposOwnedBy(app.db, user.id); | |
| 35 | const mine = new Set(own.map((r) => r.id)); | |
| 36 | const repos = withoutArchived([...own, ...(await spawnedRepos(app, user)).filter((r) => !mine.has(r.id))]); | |
| 32 | 37 | if (repos.length === 0) return []; |
| 33 | 38 | const rows = app.db |
| 34 | 39 | .query<{ repo_id: string; state: string; n: number }, string[]>( |
| @@ -47,9 +52,9 @@ export async function clientAppRows( | ||
| 47 | 52 | return up ? runtime.urlFor(record, "production") : undefined; |
| 48 | 53 | }; |
| 49 | 54 | return repos.map((repo) => { |
| 50 | const own = rows.filter((r) => r.repo_id === repo.id); | |
| 55 | const runs = rows.filter((r) => r.repo_id === repo.id); | |
| 51 | 56 | const n = (state: string): number => |
| 52 | own.find((r) => r.state === state)?.n ?? 0; | |
| 57 | runs.find((r) => r.state === state)?.n ?? 0; | |
| 53 | 58 | return { repo, working: n("running"), queued: n("queued"), live: liveOf(repo) }; |
| 54 | 59 | }); |
| 55 | 60 | } |
| @@ -135,7 +140,10 @@ export function doingLine(doing: ClientDoing | undefined): string { | ||
| 135 | 140 | return title === "" ? "" : `Working on: ${title}`; |
| 136 | 141 | } |
| 137 | 142 | |
| 138 | /** `Finished 3 days ago: Fix the menu`, or "" for an app with nothing finished; both doors word it so. */ | |
| 143 | /** | |
| 144 | * `Finished 3 days ago: Fix the menu`, or "" for an app with nothing finished; both doors word it | |
| 145 | * so. | |
| 146 | */ | |
| 139 | 147 | export function finishedLine(finished: ClientFinished | undefined, now: number): string { |
| 140 | 148 | const title = finished === undefined ? "" : cutTitle(finished.title); |
| 141 | 149 | if (finished === undefined || title === "") return ""; |
src/web/studio/client_home.ts +4 −2
| @@ -48,9 +48,11 @@ export async function clientApps(ctx: Ctx, user: User): Promise<Html> { | ||
| 48 | 48 | variant: "outline", |
| 49 | 49 | }) |
| 50 | 50 | : null; |
| 51 | // The running app, by the way the apps page opens it; an app that is not up offers nothing. | |
| 51 | // The running app, by the way the apps page opens it; an app that is not up offers nothing, | |
| 52 | // and neither does the forge's own code, whose address is the page the person is on. | |
| 53 | const here = (ctx.app.config.url ?? new URL(ctx.request.url).origin).replace(/\/$/, ""); | |
| 52 | 54 | const open = |
| 53 | live === undefined | |
| 55 | live === undefined || live.replace(/\/$/, "") === here | |
| 54 | 56 | ? null |
| 55 | 57 | : btn("Open", { href: `${repoBase(repo)}/app/production/open`, variant: "outline" }); |
| 56 | 58 | return html`<li class="client-app"> |
test/client-home.test.ts +25
| @@ -264,6 +264,13 @@ describe("a client's first screen", () => { | ||
| 264 | 264 | expect(up).toContain(">Open<"); |
| 265 | 265 | expect(up).toContain('href="/marias/bakery"'); |
| 266 | 266 | expect(runtime.urlFor(record, "production")).toStartWith("https://"); |
| 267 | ||
| 268 | // The forge's own code answers at the address of this very page: an Open there would only | |
| 269 | // load the page again, so it is not offered. | |
| 270 | const here = { ...ctx, request: new Request(runtime.urlFor(record, "production")) } as unknown as Ctx; | |
| 271 | const same = String(await clientApps(here, maria)); | |
| 272 | expect(same).not.toContain("/app/production/open"); | |
| 273 | expect(same).toContain('href="/marias/bakery"'); | |
| 267 | 274 | for (const shown of [up, down]) |
| 268 | 275 | for (const word of ["deploy", "process", "port"]) |
| 269 | 276 | expect(text(shown)).not.toMatch(new RegExp(`\\b${word}`, "i")); |
| @@ -458,6 +465,24 @@ describe("a client's first screen", () => { | ||
| 458 | 465 | app.stop(); |
| 459 | 466 | }); |
| 460 | 467 | |
| 468 | test("an app made under the person's own name is on the first screen, ahead of the forge's", async () => { | |
| 469 | const maria = getUserByName(child.db, "maria")!; | |
| 470 | // What a first ask from the home makes: an app of maria's, not of the organisation's. | |
| 471 | const made = await createRepo(child, maria, { name: "countdown" }); | |
| 472 | if (!made.ok) throw new Error(JSON.stringify(made.error)); | |
| 473 | try { | |
| 474 | const names = (await clientAppRows(child, maria)).map((r) => `${r.repo.ownerName}/${r.repo.name}`); | |
| 475 | expect(names[0]).toBe("maria/countdown"); | |
| 476 | expect(names).toContain("marias/bakery"); | |
| 477 | const home = main(await page(owner)); | |
| 478 | const apps = home.slice(home.indexOf('id="client-apps"')); | |
| 479 | expect(apps).toContain('href="/maria/countdown"'); | |
| 480 | expect(apps.indexOf('href="/maria/countdown"')).toBeLessThan(apps.indexOf('href="/marias/bakery"')); | |
| 481 | } finally { | |
| 482 | expect(moveArchived(child.db, made.value.id, true)).toBe(true); | |
| 483 | } | |
| 484 | }); | |
| 485 | ||
| 461 | 486 | test("an archived app leaves the first screen and comes back when woken", async () => { |
| 462 | 487 | const maria = getUserByName(child.db, "maria")!; |
| 463 | 488 | const second = await createRepo(child, maria, { name: "cafe", owner: "marias" }); |
new above
offline