Public: anyone can read this; the crew can change it.
Settings › Model speaks the home page's language #9857
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/9800-settings-model-speaks-the-home-page-s-la → main 3 commits fork 1 thread · 1 unresolved
3 files
changed +81
−7
docs/design/areas/settings.md +2
| @@ -130,6 +130,8 @@ Settings › Prompts (`promptsView()` in `src/web/pages/prompts.ts`, #9825) adds | ||
| 130 | 130 | |
| 131 | 131 | Settings › Hooks (`hooksPage()` in `src/web/pages/hooks.ts`, #9762) adds no component class and has no card or table: Webhooks and Add a webhook are each a `<section class="settings-block">` with an `<h2>`. Each hook is a `row()` in `<ul class="list setting-list">` (URL as title; events, state, added date and "unsigned" as meta; Send ping and a confirmed Delete in the trail), with its recent deliveries as nested child rows, Redeliver in the trail of a failed one. With no hook, one plain sentence. The secret is never drawn. Pinned by `test/hooks-rows.test.ts`. |
| 132 | 132 | |
| 133 | Settings › Model (`modelPage()` in `src/web/pages/model.ts`, #9800) adds no class and has no card: Your model budget is one `<section class="settings-block">` with an `<h2>`. A grant an admin gave is one `row()` in `<ul class="list setting-list" id="model-budget">`; with nothing (or an own subscription, or an admin) one plain sentence says what the account may spend and how to add a subscription. The token form sits straight in the block, typed once and never shown again. `ceilingCard` and `grantCard` stay cards on the account's page. Pinned by `test/model-page-shape.test.ts`. | |
| 134 | ||
| 133 | 135 | ## Organizations |
| 134 | 136 | |
| 135 | 137 | `/organizations/new` is one muted sentence (what an organization is) over the single name field, whose hint says it becomes the URL; "first owner" is said once, in the landing flash. A team's page (`/:owner/-/teams/:team`) is three `<section class="settings-block">`s, each an `<h2>` — Members, Add a member, Delete this team (not on Owners) — over a `list setting-list` of `row()`s or a plain form. No card, no empty-state box (an empty team is one muted line), no new class. Every change stays a plain POST form or a confirm page, so it works with JavaScript off. `test/org-team-rows.test.ts` holds the shape. |
src/web/pages/model.ts +12 −7
| @@ -23,7 +23,7 @@ import { notFoundPage, settingsLayout, signInFirst } from "../chrome.ts"; | ||
| 23 | 23 | import { field, readForm } from "../form.ts"; |
| 24 | 24 | import { html, type Html } from "../html.ts"; |
| 25 | 25 | import { flashTo, page } from "../layout.ts"; |
| 26 | import { btn, card } from "../ui.ts"; | |
| 26 | import { btn, card, row } from "../ui.ts"; | |
| 27 | 27 | import { accountOnly, accountSections } from "./origins.ts"; |
| 28 | 28 | |
| 29 | 29 | // GET /settings/model |
| @@ -34,6 +34,7 @@ export function modelPage(ctx: Ctx): Response { | ||
| 34 | 34 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 35 | 35 | const own = timePhase(ctx.request, "subscription", () => ownSubscription(ctx.app.db, user.id)); |
| 36 | 36 | const budget = timePhase(ctx.request, "budget", () => budgetLine(ctx.app.db, user, new Date())); |
| 37 | const grant = getModelGrant(ctx.app.db, user.id); | |
| 37 | 38 | const rendering = performance.now(); |
| 38 | 39 | const form = own |
| 39 | 40 | ? html`<p class="muted"> |
| @@ -64,12 +65,16 @@ export function modelPage(ctx: Ctx): Response { | ||
| 64 | 65 | body: html`<div class="page-head"><h1>Model</h1></div> |
| 65 | 66 | ${settingsLayout( |
| 66 | 67 | accountSections("model", { admin: user.isAdmin }), |
| 67 | card(html`${form}`, { | |
| 68 | head: html`<h2>Your model budget</h2> | |
| 69 | <p class="muted" id="model-budget"> | |
| 70 | ${budget} | |
| 71 | </p>`, | |
| 72 | }), | |
| 68 | html`<section class="settings-block"> | |
| 69 | <h2>Your model budget</h2> | |
| 70 | ${grant === undefined || own || user.isAdmin | |
| 71 | ? html`<p class="muted" id="model-budget">${budget}</p>` | |
| 72 | : html`<ul class="list setting-list" id="model-budget">${row({ | |
| 73 | title: "A grant from an admin", | |
| 74 | meta: html`${budget}`, | |
| 75 | })}</ul>`} | |
| 76 | ${form} | |
| 77 | </section>`, | |
| 73 | 78 | "Account settings", |
| 74 | 79 | )}`, |
| 75 | 80 | }); |
test/model-page-shape.test.ts added +67
| @@ -0,0 +1,67 @@ | ||
| 1 | /** /settings/model is a heading over rows: a settings block, no `.card`. */ | |
| 2 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 3 | import { mkdtempSync, rmSync } from "node:fs"; | |
| 4 | import { tmpdir } from "node:os"; | |
| 5 | import { join } from "node:path"; | |
| 6 | import { createApp, type App } from "../src/app.ts"; | |
| 7 | import { setAccountGrant } from "../src/actions/model_grant.ts"; | |
| 8 | import { createUser, getUserByName } from "../src/core/users.ts"; | |
| 9 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 10 | import { quietLogs } from "./helpers/globals.ts"; | |
| 11 | ||
| 12 | quietLogs(); | |
| 13 | ||
| 14 | const PASS = "a-good-passphrase"; | |
| 15 | let root = ""; | |
| 16 | let app: App; | |
| 17 | let servers: Servers; | |
| 18 | ||
| 19 | const signIn = async (username: string) => { | |
| 20 | const r = await fetch(`${servers.url}/signin`, { | |
| 21 | method: "POST", | |
| 22 | headers: { origin: servers.url }, | |
| 23 | body: new URLSearchParams({ username, password: PASS }), | |
| 24 | redirect: "manual", | |
| 25 | }); | |
| 26 | return (r.headers.get("set-cookie") ?? "").split(";")[0]!; | |
| 27 | }; | |
| 28 | const get = async (cookie: string) => | |
| 29 | (await fetch(`${servers.url}/settings/model`, { headers: { cookie } })).text(); | |
| 30 | const noCard = (body: string) => expect(body).not.toMatch(/class="(?:[^"]*\s)?card(?:\s[^"]*)?"/); | |
| 31 | const heading = /<section class="settings-block"[^>]*>\s*<h2>Your model budget<\/h2>/; | |
| 32 | ||
| 33 | beforeAll(async () => { | |
| 34 | root = mkdtempSync(join(tmpdir(), "forge-model-shape-")); | |
| 35 | app = createApp({ dataDir: root, port: 0 }); | |
| 36 | for (const [username, isAdmin] of [["alice", true], ["bob", false], ["carol", false]] as const) { | |
| 37 | const u = await createUser(app.db, { | |
| 38 | origin: "seed", trusted: true, username, email: `${username}@x.test`, password: PASS, isAdmin, | |
| 39 | }); | |
| 40 | if (!u.ok) throw new Error(u.error); | |
| 41 | } | |
| 42 | servers = await serve(app); | |
| 43 | }); | |
| 44 | afterAll(() => { | |
| 45 | servers.stop(); | |
| 46 | app.close(); | |
| 47 | rmSync(root, { recursive: true, force: true }); | |
| 48 | }); | |
| 49 | ||
| 50 | test("a new account sees a heading, one sentence and the token form, no card", async () => { | |
| 51 | const body = await get(await signIn("bob")); | |
| 52 | expect(body).toMatch(heading); | |
| 53 | noCard(body); | |
| 54 | expect(body).toContain("Model budget: $0. Add your own subscription, or ask an admin for a grant."); | |
| 55 | expect(body).not.toContain('class="row'); | |
| 56 | expect(body).toContain('name="token"'); | |
| 57 | }); | |
| 58 | ||
| 59 | test("an account with a grant sees it as one row, no card", async () => { | |
| 60 | const admin = getUserByName(app.db, "alice")!; | |
| 61 | expect(setAccountGrant(app, admin, "carol", 20).ok).toBe(true); | |
| 62 | const body = await get(await signIn("carol")); | |
| 63 | expect(body).toMatch(heading); | |
| 64 | noCard(body); | |
| 65 | expect(body.match(/class="row"/g)?.length).toBe(1); | |
| 66 | expect(body).toContain("a grant of $20.00 a month, $20.00 left"); | |
| 67 | }); |
Next: this lookup runs outside timePhase and duplicates what budgetLine reads; fold it into the timed phase.