Public: anyone can read this; the crew can change it.
Home: two or three owner-pinned panels with release annotations #16884
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/16850-home-two-or-three-owner-pinned-panels-wi → main 0 commits fork 2 threads · 2 unresolved
4 files
changed +54
−4
docs/features/home-pins.md added +21
| @@ -0,0 +1,21 @@ | ||
| 1 | --- | |
| 2 | topic: Your apps | |
| 3 | row: Home pins: two or three board panels with release marks | |
| 4 | --- | |
| 5 | # Home pins: two or three board panels with release marks | |
| 6 | ||
| 7 | The owner (a forge admin who is a person) keeps at most **three** board panels on home, under the | |
| 8 | KPI row. Each draws its chart over its board's range with the release marks every board chart | |
| 9 | carries (`releaseMarks`, `src/boards/marks.ts`), and **Open board** goes to `/boards/<slug>`, which | |
| 10 | draws the same panels over the same range. | |
| 11 | ||
| 12 | - **Web:** on `/boards`, Pin a panel; on home, Up, Down, Unpin and Open board beside it. A fourth | |
| 13 | pin is refused ("too many"). The choice is per user, in the `board_pin` table under | |
| 14 | `FORGE_APP_DATA`; the board and panel are checked against the boards registry, and every change is | |
| 15 | a same-origin form post. | |
| 16 | - **Terminal:** the Pinned panels screen (`src/tui/screens/home_pins.ts`): `<`/`>` move, `u` | |
| 17 | unpins, `enter` opens the board. `p` on a panel in the Boards screen pins it. | |
| 18 | - **API and MCP:** `/api/v1/boards/pins` and the `board_pins` tool, through `actions/board-pins.ts`. | |
| 19 | ||
| 20 | Pins above three that were made before the limit stay stored. Home shows the first three; the rest | |
| 21 | are listed, and can be unpinned, on `/boards` and in the terminal's Pinned panels screen. |
src/boards/pins.ts +2 −1
| @@ -8,7 +8,8 @@ import type { Database } from "bun:sqlite"; | ||
| 8 | 8 | import { isSlug, MAX_TITLE } from "./store.ts"; |
| 9 | 9 | |
| 10 | 10 | export type Pin = { slug: string; title: string }; |
| 11 | export const MAX_PINS = 24; | |
| 11 | /** Home keeps a few panels, not a wall: two or three the owner chose (#16850). */ | |
| 12 | export const MAX_PINS = 3; | |
| 12 | 13 | |
| 13 | 14 | /** A pin as a form says it, judged: the plain value or undefined. */ |
| 14 | 15 | export function pinOf(slug: unknown, title: unknown): Pin | undefined { |
src/web/studio/pinned.ts +5 −3
| @@ -1,12 +1,12 @@ | ||
| 1 | 1 | /** |
| 2 | 2 | * The panels a person pinned from /boards, drawn under home's KPI row in |
| 3 | * their order (#2741), each with Up, Down and Unpin beside it. Only the | |
| 3 | * their order (#2741), at most MAX_PINS of them, each with Up, Down and Unpin beside it. Only the | |
| 4 | 4 | * viewer's own pins are read. A pin whose board or panel is gone is skipped. |
| 5 | 5 | */ |
| 6 | 6 | import type { App } from "../../app.ts"; |
| 7 | 7 | import { listPinned, PINS_EVENT } from "../../actions/board-pins.ts"; |
| 8 | 8 | import type { Board, Panel } from "../../boards/store.ts"; |
| 9 | import type { Pin } from "../../boards/pins.ts"; | |
| 9 | import { MAX_PINS, type Pin } from "../../boards/pins.ts"; | |
| 10 | 10 | import type { User } from "../../core/users.ts"; |
| 11 | 11 | import { html, type Html } from "../html.ts"; |
| 12 | 12 | import { btn } from "../ui.ts"; |
| @@ -17,6 +17,7 @@ import { drawPanel } from "../pages/boards-view.ts"; | ||
| 17 | 17 | function controls(p: Pin): Html { |
| 18 | 18 | const hidden = html`<input type="hidden" name="slug" value="${p.slug}" /><input type="hidden" name="title" value="${p.title}" /><input type="hidden" name="back" value="/" />`; |
| 19 | 19 | return html`<div class="row-actions"> |
| 20 | ${btn("Open board", { href: `/boards/${p.slug}`, size: "sm", label: `Open the ${p.title} board` })} | |
| 20 | 21 | <form method="post" action="/boards/move-pin" class="row-actions">${hidden} |
| 21 | 22 | ${btn("Up", { size: "sm", name: "by", value: "-1", label: `Move ${p.title} up` })} |
| 22 | 23 | ${btn("Down", { size: "sm", name: "by", value: "1", label: `Move ${p.title} down` })} |
| @@ -32,7 +33,8 @@ const cached = (p: Pin & { board: Board; panel: Panel }): typeof runFor => (db, | ||
| 32 | 33 | export async function pinnedPanels(app: App, user: User): Promise<Html | null> { |
| 33 | 34 | const listed = await listPinned(app, user); |
| 34 | 35 | if (!listed.ok) return null; |
| 35 | const shown = listed.value.length === 0 ? null : html`<section class="bgrid" aria-label="Pinned panels">${listed.value.map((p) => drawPanel(app, p.board, p.panel, { slug: p.slug, index: p.board.panels.indexOf(p.panel) }, controls(p), cached(p)))}</section>`; | |
| 36 | const first = listed.value.slice(0, MAX_PINS); // pins stored before the cap stay listed elsewhere; home draws three | |
| 37 | const shown = first.length === 0 ? null : html`<section class="bgrid" aria-label="Pinned panels">${first.map((p) => drawPanel(app, p.board, p.panel, { slug: p.slug, index: p.board.panels.indexOf(p.panel) }, controls(p), cached(p)))}</section>`; | |
| 36 | 38 | return pinsRegion(shown); |
| 37 | 39 | } |
| 38 | 40 |
test/board-pins.test.ts +26
| @@ -99,6 +99,13 @@ describe("pinned panels", () => { | ||
| 99 | 99 | expect(pinOf("mine", "a\u0000b")).toBeUndefined(); |
| 100 | 100 | }); |
| 101 | 101 | |
| 102 | test("home keeps at most three pins and each links to its board", async () => { | |
| 103 | expect(MAX_PINS).toBe(3); | |
| 104 | const html = await home("alice"); | |
| 105 | expect(html).toContain('href="/boards/mine"'); | |
| 106 | expect(html).toContain("Open the Pin A board"); | |
| 107 | }); | |
| 108 | ||
| 102 | 109 | test("a pin whose panel has gone is skipped, not an error", async () => { |
| 103 | 110 | app.db.run("INSERT INTO board_pin (user_id, slug, title, pos) VALUES (?, 'gone', 'x', 9)", [alice.id]); |
| 104 | 111 | expect(titles(await home("alice"))).toEqual(["Pin A", "Pin B"]); |
| @@ -140,3 +147,22 @@ describe("pinned panels", () => { | ||
| 140 | 147 | expect(await titlesOf("carol")).toEqual([]); // her "Pin C" was renamed away: not shown |
| 141 | 148 | }); |
| 142 | 149 | }); |
| 150 | ||
| 151 | describe("the cap of three", () => { | |
| 152 | test("home draws only the first three of four stored pins; a fourth through pinPanel is refused", async () => { | |
| 153 | const dave = { ...carol, isAdmin: true }; // the stale object predates the promotion | |
| 154 | app.db.run("DELETE FROM board_pin WHERE user_id = ?", [dave.id]); | |
| 155 | const names = ["Cap 1", "Cap 2", "Cap 3", "Cap 4"]; | |
| 156 | const w = await writeBoard(app, alice, "cap", { title: "Cap", range: "all", refresh: "off", panels: names.map(panel) }); | |
| 157 | expect(w.ok).toBe(true); | |
| 158 | names.forEach((t, i) => app.db.run("INSERT INTO board_pin (user_id, slug, title, pos) VALUES (?, 'cap', ?, ?)", [dave.id, t, i])); | |
| 159 | expect(listPins(app.db, dave.id)).toHaveLength(4); | |
| 160 | const h = await home("carol"); | |
| 161 | expect([...h.matchAll(/<h2>(Cap \d)<\/h2>/g)].map((m) => m[1])).toEqual(["Cap 1", "Cap 2", "Cap 3"]); | |
| 162 | const w2 = await writeBoard(app, alice, "cap", { title: "Cap", range: "all", refresh: "off", panels: [...names, "Cap 5"].map(panel) }); | |
| 163 | expect(w2.ok).toBe(true); | |
| 164 | const refused = await pinPanel(app, dave, "cap", "Cap 5"); | |
| 165 | expect(refused.ok).toBe(false); | |
| 166 | if (!refused.ok) expect(refused.error).toBe("too_many"); | |
| 167 | }); | |
| 168 | }); |
new above
offline
This sentence contradicts the title and the first paragraph ('at most three'). Once home shows the first three, say where the others are listed and unpinned.