Public: anyone can read this; the crew can change it.
Every destructive confirm names what is lost and the way back in one sentence #16059
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/16044-every-destructive-confirm-names-what-is → main 0 commits fork
5 files
changed +69
−11
docs/features/danger-confirms.md added +12
| @@ -0,0 +1,12 @@ | ||
| 1 | --- | |
| 2 | topic: Your apps | |
| 3 | row: Stop-as-app and delete confirms say what is lost and the way back | |
| 4 | --- | |
| 5 | # Destructive confirms say what is lost and the way back | |
| 6 | ||
| 7 | Pressing "Stop running as an app" or "Delete this repository" (Settings → Danger zone) opens `/-/confirm`, whose paragraph is two sentences: what is lost, then the way back, or that there is none. Nothing changes until the second button (and, for delete, the typed full name). | |
| 8 | ||
| 9 | - **Stop running as an app:** production and every preview stop and their data is removed; the code is untouched and running it again starts from empty data. | |
| 10 | - **Delete this repository:** issues, pulls, comments, webhooks and git objects go; there is no way back, forks are detached first and keep working. | |
| 11 | ||
| 12 | The words live once in `src/web/danger_words.ts` (`DANGERS`, `dangerDetail`). Terminal: the repository's `:` palette → "Delete this repository" shows the same two sentences before asking for the name (`src/tui/screens/deleterepo.ts`). Test: `test/danger-words.test.ts` fails if an entry lacks either line. |
src/tui/screens/deleterepo.ts +2 −5
| @@ -6,15 +6,12 @@ | ||
| 6 | 6 | |
| 7 | 7 | import { deleteRepo } from "../../actions/repos.ts"; |
| 8 | 8 | import { canAdmin, type Repo } from "../../core/repos.ts"; |
| 9 | import { DELETE_REPO } from "../../web/danger_words.ts"; | |
| 9 | import { DELETE_REPO, dangerDetail } from "../../web/danger_words.ts"; | |
| 10 | 10 | import type { Ctx, Screen } from "../app/app.ts"; |
| 11 | 11 | import type { Command } from "../app/palette.ts"; |
| 12 | 12 | import type { Session } from "../session.ts"; |
| 13 | 13 | import { promptScreen } from "./common.ts"; |
| 14 | 14 | |
| 15 | const GOES = | |
| 16 | "every issue, pull request, comment and webhook, and the git objects; forks are detached first and keep working"; | |
| 17 | ||
| 18 | 15 | /** The prompt floats over whatever is already drawn; this is the empty backdrop it asks for. */ |
| 19 | 16 | const backdrop: Screen = { |
| 20 | 17 | title: DELETE_REPO, |
| @@ -36,7 +33,7 @@ export function deleteRepoCommands(f: Session, ctx: Ctx, repo: Repo | undefined) | ||
| 36 | 33 | ctx.push( |
| 37 | 34 | promptScreen(ctx, backdrop, { |
| 38 | 35 | title: `${DELETE_REPO} (cannot be undone)`, |
| 39 | label: `Removes ${GOES}. Type ${full}:`, | |
| 36 | label: `${dangerDetail(DELETE_REPO)} Type ${full}:`, | |
| 40 | 37 | placeholder: full, |
| 41 | 38 | onSubmit: (typed) => { |
| 42 | 39 | if (typed !== full) return `Type ${full} to confirm.`; |
src/web/danger_words.ts +33
| @@ -9,3 +9,36 @@ export const STOP_APP = "Stop running as an app"; | ||
| 9 | 9 | |
| 10 | 10 | /** Deletes the repository, its issues, pulls and git objects. */ |
| 11 | 11 | export const DELETE_REPO = "Delete this repository"; |
| 12 | ||
| 13 | /** What a destructive confirm says: one sentence for what is lost, one for the way back. */ | |
| 14 | export interface DangerSaid { | |
| 15 | /** The button's words. */ | |
| 16 | verb: string; | |
| 17 | /** What is lost, in one sentence. */ | |
| 18 | lost: string; | |
| 19 | /** The way back in one sentence, or the plain statement that there is none. */ | |
| 20 | wayBack: string; | |
| 21 | } | |
| 22 | ||
| 23 | /** Every confirm built from this file, so a test can enumerate them. */ | |
| 24 | export const DANGERS: readonly DangerSaid[] = [ | |
| 25 | { | |
| 26 | verb: STOP_APP, | |
| 27 | lost: "Production and every preview stop, and their data directories and checkouts are removed from disk.", | |
| 28 | wayBack: | |
| 29 | "The repository and its code are untouched; run it as an app again later and it starts from empty data.", | |
| 30 | }, | |
| 31 | { | |
| 32 | verb: DELETE_REPO, | |
| 33 | lost: "Every issue, pull request, comment and webhook goes with it, and the git objects are removed from disk.", | |
| 34 | wayBack: | |
| 35 | "There is no way back: forks are detached first and keep working, but this repository cannot be restored.", | |
| 36 | }, | |
| 37 | ]; | |
| 38 | ||
| 39 | /** The paragraph a confirm shows for one of the acts above. */ | |
| 40 | export function dangerDetail(verb: string): string { | |
| 41 | const said = DANGERS.find((d) => d.verb === verb); | |
| 42 | if (said === undefined) throw new Error(`no danger words for ${verb}`); | |
| 43 | return `${said.lost} ${said.wayBack}`; | |
| 44 | } |
src/web/pages/search.ts +3 −5
| @@ -42,7 +42,7 @@ import type { Ctx } from "../../http/context.ts"; | ||
| 42 | 42 | import { notePhase, takeSessionTime, timePhase } from "../../core/route_timing.ts"; |
| 43 | 43 | import { notFoundPage, pageHead } from "../chrome.ts"; |
| 44 | 44 | import { html, when, type Html } from "../html.ts"; |
| 45 | import { DELETE_REPO, STOP_APP } from "../danger_words.ts"; | |
| 45 | import { DELETE_REPO, STOP_APP, dangerDetail } from "../danger_words.ts"; | |
| 46 | 46 | import { icon } from "../icons.ts"; |
| 47 | 47 | import { page } from "../layout.ts"; |
| 48 | 48 | import { browseBase } from "../scope.ts"; |
| @@ -641,8 +641,7 @@ const DESTRUCTIVE: { | ||
| 641 | 641 | describe: (m) => ({ |
| 642 | 642 | verb: DELETE_REPO, |
| 643 | 643 | title: `Delete ${m[1]}/${m[2]}?`, |
| 644 | detail: | |
| 645 | "Every issue, pull request, comment and webhook goes with it, and the git objects are removed from disk. Forks are detached first and keep working. This cannot be undone.", | |
| 644 | detail: dangerDetail(DELETE_REPO), | |
| 646 | 645 | phrase: `${m[1]}/${m[2]}`, |
| 647 | 646 | }), |
| 648 | 647 | }, |
| @@ -911,8 +910,7 @@ const DESTRUCTIVE: { | ||
| 911 | 910 | describe: (m) => ({ |
| 912 | 911 | verb: STOP_APP, |
| 913 | 912 | title: `Stop running ${m[1]}/${m[2]} as an app?`, |
| 914 | detail: | |
| 915 | "Production and every preview stop, and their data directories and checkouts are removed from disk. The repository and its code are untouched. Run it as an app again later and it starts from empty data.", | |
| 913 | detail: dangerDetail(STOP_APP), | |
| 916 | 914 | phrase: "", |
| 917 | 915 | }), |
| 918 | 916 | }, |
test/danger-words.test.ts +19 −1
| @@ -7,7 +7,7 @@ | ||
| 7 | 7 | import { expect, test } from "bun:test"; |
| 8 | 8 | import { readFileSync } from "node:fs"; |
| 9 | 9 | import { join } from "node:path"; |
| 10 | import { DELETE_REPO, STOP_APP } from "../src/web/danger_words.ts"; | |
| 10 | import { DANGERS, DELETE_REPO, STOP_APP, dangerDetail } from "../src/web/danger_words.ts"; | |
| 11 | 11 | |
| 12 | 12 | const root = join(import.meta.dir, ".."); |
| 13 | 13 | const readers = ["src/web/pages/settings.ts", "src/web/pages/search.ts"]; |
| @@ -26,3 +26,21 @@ test("no file that shows them types a sentence out again", () => { | ||
| 26 | 26 | } |
| 27 | 27 | } |
| 28 | 28 | }); |
| 29 | ||
| 30 | test("every confirm names what is lost and the way back, each in one sentence", () => { | |
| 31 | expect(DANGERS.length).toBeGreaterThanOrEqual(2); | |
| 32 | for (const d of DANGERS) { | |
| 33 | for (const line of [d.lost, d.wayBack]) { | |
| 34 | expect({ verb: d.verb, ok: line.trim().length > 20 }).toEqual({ verb: d.verb, ok: true }); | |
| 35 | expect({ verb: d.verb, one: (line.match(/[.!?](\s|$)/g) ?? []).length }).toEqual({ verb: d.verb, one: 1 }); | |
| 36 | } | |
| 37 | expect(dangerDetail(d.verb)).toBe(`${d.lost} ${d.wayBack}`); | |
| 38 | } | |
| 39 | expect(DANGERS.map((d) => d.verb)).toEqual([STOP_APP, DELETE_REPO]); | |
| 40 | }); | |
| 41 | ||
| 42 | test("the confirm page shows both lines for each", async () => { | |
| 43 | const text = readFileSync(join(root, "src/web/pages/search.ts"), "utf8"); | |
| 44 | expect(text).toContain("dangerDetail(DELETE_REPO)"); | |
| 45 | expect(text).toContain("dangerDetail(STOP_APP)"); | |
| 46 | }); |
new above
offline