diff --git a/.changeset/github-draft-body-whole.md b/.changeset/github-draft-body-whole.md new file mode 100644 index 0000000000..b55d0d209a --- /dev/null +++ b/.changeset/github-draft-body-whole.md @@ -0,0 +1,5 @@ +--- +"@schlessera/brain-ui-kit": patch +--- + +A not-posted GitHub draft now shows its whole body (#4197). `GitHubPullRequest` in `preview` cut a draft longer than 20,000 characters and said "Truncated · the rest is on GitHub", though a draft is not on GitHub yet and the host posts up to 65,536 characters. A draft keeps its 8-line clamp, whose expand control names the whole length. Read bodies keep their 20,000-character bound and their "Truncated" note. The W1 issue approval (`GitHubIssue` with `posting: { status: "preview" }`) already showed the whole body, and a unit test and a long-draft story now hold it to that. diff --git a/packages/ui-kit/src/github/object-parts.tsx b/packages/ui-kit/src/github/object-parts.tsx index bf1c5eea40..fff51a935a 100644 --- a/packages/ui-kit/src/github/object-parts.tsx +++ b/packages/ui-kit/src/github/object-parts.tsx @@ -8,8 +8,8 @@ import { Field, GitHubLink, githubHref, type GitHubState } from "./shared.js"; /** Internal pieces shared by `GitHubPullRequest` and `GitHubIssue`. */ -/** The body's hard bound, from the design's truncation table. */ -const BODY_MAX_CHARS = 20_000; +/** A read or posted body's hard bound, from the design's truncation table. */ +export const BODY_MAX_CHARS = 20_000; /** "1,840": a count in the reader-facing format, the same in every locale the kit renders in. */ export function count(n: number): string { @@ -68,6 +68,13 @@ export function Labels({ labels }: { labels: string[] }) { /** Where a not-posted draft's links say they come from: it is not on GitHub yet. */ export const DRAFT_SOURCE = { source: "this draft", sourcePhrase: "in this draft" } as const; +/** + * An issue or pull request body. A read or posted body keeps the design's + * 20,000-character bound and its "Truncated" note. A draft (`draft`, a + * not-posted preview) shows its whole text behind the same clamp: what is + * approved is what is posted, up to 65,536 characters (#4197, as #4154 did + * for the W4 comment preview). + */ export function Body(p: { body?: string | null; author: string; bodyLength?: number; bodyTruncated?: boolean; htmlUrl?: string | null; draft?: boolean }) { if (!p.body) { return
— No description provided.
; @@ -81,7 +88,7 @@ export function Body(p: { body?: string | null; author: string; bodyLength?: num lines={8} linesNarrow={10} expandLabel={`Show full description · ${count(length)} characters`} - maxChars={BODY_MAX_CHARS} + {...(p.draft ? {} : { maxChars: BODY_MAX_CHARS })} truncated={p.bodyTruncated} truncatedNote={ !p.draft && githubHref(p.htmlUrl) ? ( diff --git a/packages/ui-kit/stories/github/GitHubPullRequest.stories.tsx b/packages/ui-kit/stories/github/GitHubPullRequest.stories.tsx index 0c204a4717..3529b7883c 100644 --- a/packages/ui-kit/stories/github/GitHubPullRequest.stories.tsx +++ b/packages/ui-kit/stories/github/GitHubPullRequest.stories.tsx @@ -1,6 +1,6 @@ import preview from "#.storybook/preview"; import { useState } from "react"; -import { expect, within } from "storybook/test"; +import { expect, userEvent, within } from "storybook/test"; import { argos, commits, eurycleia, penelope, pr, prThread, telemachus } from "../../fixtures/github.js"; import { GitHubCommitRow } from "../../src/github/GitHubCommitRow.js"; @@ -168,3 +168,22 @@ export const Preview = meta.story({ }, }); export const PreviewNarrow = Preview.extend({ ...narrow }); + +/** + * A preview shows its whole draft (#4197): the read bodies' 20,000-character + * bound does not cut what is approved. The 8-line clamp stays, and its + * expand control names the whole length. + */ +const LONG_PR_DRAFT = `${"The key log gains a second signature per opening. ".repeat(500)}The last line of the draft.`; +export const PreviewLongDraft = meta.story({ + args: { preview: true, body: LONG_PR_DRAFT, bodyLength: undefined, bodyTruncated: false }, + ...desktop, + play: async ({ canvas }) => { + await expect(canvas.queryByText(/Truncated/), "a draft is never shown cut").toBeNull(); + const length = Array.from(LONG_PR_DRAFT).length; + await expect(length).toBeGreaterThan(20_000); + await userEvent.click(canvas.getByRole("button", { name: `Show full description · ${length.toLocaleString("en-US")} characters` })); + await expect(canvas.getByText(/The last line of the draft\./)).toBeVisible(); + }, +}); +export const PreviewLongDraftNarrow = PreviewLongDraft.extend({ ...narrow }); diff --git a/packages/ui-kit/stories/github/GitHubWrite.stories.tsx b/packages/ui-kit/stories/github/GitHubWrite.stories.tsx index 23046b61b8..1e33188ce1 100644 --- a/packages/ui-kit/stories/github/GitHubWrite.stories.tsx +++ b/packages/ui-kit/stories/github/GitHubWrite.stories.tsx @@ -1,5 +1,5 @@ import preview from "#.storybook/preview"; -import { expect, fn } from "storybook/test"; +import { expect, fn, userEvent } from "storybook/test"; import { brainBot } from "../../fixtures/github.js"; import { ApprovalCard } from "../../src/decisions/ApprovalCard.js"; @@ -49,6 +49,29 @@ export const W1IssueApproval = meta.story({ }); export const W1IssueApprovalNarrow = W1IssueApproval.extend({ ...narrow }); +/** + * W1 with a draft past the read bodies' 20,000-character bound (#4197): the + * card shows all of what is approved, in both panes, and never says + * "Truncated". The host posts up to 65,536 characters. + */ +const LONG_ISSUE_DRAFT = `${"The tally of the wine store, night by night. ".repeat(560)}The last line of the draft.`; +export const W1LongDraft = meta.story({ + ...desktop, + render: () => ( +