Public: anyone can read this; the crew can change it.
small: the '+ New forge' page has one primary next action, with phone and desktop looks on the pull #17818
Merged 5h 2m ago, live in production
scout/forge:scout/13374-small-the-new-forge-page-has-one-primary → main 0 commits fork 2 threads · 2 unresolved
3 files
changed +20
−10
docs/design/quiet-debt.json −1
src/web/pages/new-forge.ts +8 −9
| @@ -263,7 +263,7 @@ function formView( | ||
| 263 | 263 | ? html`<p class="error mb" role="alert">${errors["form"]}${values.where !== "" ? html` <a href="${CEILING_PAGE}">Cloud accounts</a>` : null}</p>` |
| 264 | 264 | : null} |
| 265 | 265 | ${plan} |
| 266 | ${recipesView(recipes, errors)} | |
| 266 | ${recipesView(recipes, errors, plan === null)} | |
| 267 | 267 | <section class="settings-block"> |
| 268 | 268 | <h2>Its name and apps</h2> |
| 269 | 269 | <form method="post" action="/forges/new" class="stack" id="new-forge"> |
| @@ -440,10 +440,8 @@ function formView( | ||
| 440 | 440 | })} |
| 441 | 441 | </details>`} |
| 442 | 442 | <div class="form-actions" data-stick> |
| 443 | <button class="btn" type="submit" name="do" value="plan"> | |
| 444 | See the plan | |
| 445 | </button> | |
| 446 | ${btn("Spawn", { variant: "primary" })} | |
| 443 | ${btn("See the plan", { name: "do", value: "plan", variant: "outline" })} | |
| 444 | ${btn("Spawn", { variant: plan === null && recipes.length === 0 ? "primary" : "secondary" })} | |
| 447 | 445 | </div> |
| 448 | 446 | </form> |
| 449 | 447 | </section> |
| @@ -498,9 +496,10 @@ const sayConfig = (c: ForgeConfig): string => | ||
| 498 | 496 | |
| 499 | 497 | /** |
| 500 | 498 | * Saved recipes: a name for the new forge, Spawn. A budget needs its key again, as a key is never |
| 501 | * kept. | |
| 499 | * kept. The page has one primary action: the first recipe's Spawn when there is no plan on the page | |
| 500 | * and a recipe is saved; the rest are secondary. | |
| 502 | 501 | */ |
| 503 | function recipesView(recipes: readonly Recipe[], errors: Errors): Html | null { | |
| 502 | function recipesView(recipes: readonly Recipe[], errors: Errors, primary: boolean): Html | null { | |
| 504 | 503 | if (recipes.length === 0) return null; |
| 505 | 504 | return html`<section class="settings-block" id="recipes"> |
| 506 | 505 | <h2>Your recipes</h2> |
| @@ -513,8 +512,8 @@ function recipesView(recipes: readonly Recipe[], errors: Errors): Html | null { | ||
| 513 | 512 | ? null |
| 514 | 513 | : formField({ label: "AI account key", name: "modelKey", id: `recipe-${i}-key`, type: "password", autocomplete: "off", required: true, hint: `For its $${r.config.budgetUsd} budget; sealed in the new forge, never shown again.` })} |
| 515 | 514 | <div class="form-actions"> |
| 516 | <button class="btn" type="submit" name="do" value="plan">See the plan</button> | |
| 517 | ${btn("Spawn", { variant: "primary" })} | |
| 515 | ${btn("See the plan", { name: "do", value: "plan", variant: "outline" })} | |
| 516 | ${btn("Spawn", { variant: primary && i === 0 ? "primary" : "secondary" })} | |
| 518 | 517 | </div> |
| 519 | 518 | </form>`, |
| 520 | 519 | )} |
test/new-forge-refresh.test.ts +12
| @@ -14,6 +14,7 @@ import { PAGE_WAIT_MS, isStale, refreshForPage } from "../src/actions/places_ref | ||
| 14 | 14 | import { readTimes, triedTimes } from "../src/cloud/places_read.ts"; |
| 15 | 15 | import { createUser, getUserByName } from "../src/core/users.ts"; |
| 16 | 16 | import type { Ctx } from "../src/http/context.ts"; |
| 17 | import { saveRecipe } from "../src/spawn/recipes.ts"; | |
| 17 | 18 | import { newForgePage } from "../src/web/pages/new-forge.ts"; |
| 18 | 19 | import { hetzner } from "./helpers/places-fixture.ts"; |
| 19 | 20 | import { quietLogs } from "./helpers/globals.ts"; |
| @@ -122,3 +123,14 @@ test("a cloud account added just after a fresh look is read by the next visit", | ||
| 122 | 123 | await visit(); |
| 123 | 124 | expect(triedTimes(app.db)["digitalocean"]).toBeDefined(); |
| 124 | 125 | }); |
| 126 | ||
| 127 | test("with saved recipes the page has one primary Spawn (the first recipe's); the rest are secondary", async () => { | |
| 128 | const alice = getUserByName(app.db, "alice")!; | |
| 129 | const none = await visit(); | |
| 130 | expect(none.match(/data-variant="primary"/g)?.length ?? 0).toBe(1); // the form's own Spawn | |
| 131 | for (const name of ["one", "two"]) expect(saveRecipe(app.config.dataDir, alice.id, name, { apps: [] }).ok).toBe(true); | |
| 132 | const html = await visit(); | |
| 133 | expect(html.match(/data-variant="primary"/g)?.length).toBe(1); | |
| 134 | expect(html.indexOf('data-variant="primary"')).toBeLessThan(html.indexOf('id="new-forge"')); | |
| 135 | expect(html.match(/data-variant="outline"[^>]*>\s*See the plan/g)?.length).toBe(3); | |
| 136 | }); |
new above
offline
Principle 5, one way to draw a button: use btn("See the plan", { name: "do", value: "plan", variant: "outline" }) instead of a hand-written button element.