-
Notifications
You must be signed in to change notification settings - Fork 16
feat: align index route with hosted prologue/chapters + PR description #65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+868
−369
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ca15b55
feat: align index route with hosted prologue/chapters + PR description
dastratakos 60548ea
fix(web): keep overview sidebar on the tab the user is reading
dastratakos ed0abf6
fix(cli): tolerate a null PR body from gh
dastratakos cf82a92
feat(web): copy actions + render HTML in the PR description
dastratakos bd6de77
feat(web): lock the index to the viewport so only panels scroll
dastratakos daa3b96
fix(web): match hosted — drop the scrollTo link from prologue review …
dastratakos 53e5ddb
fix(web): address PR review — safe link sanitization + gate chapters …
dastratakos f348290
fix(web): show chapters copy once the diff settles, not only when non…
dastratakos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,3 +35,4 @@ coverage | |
| # Claude Code | ||
| .claude/scheduled_tasks.lock | ||
| .claude/settings.local.json | ||
| .gstack/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
packages/web/src/components/pull-request/overview-column-header.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import type { ReactNode } from "react"; | ||
|
|
||
| /** | ||
| * Sticky header row shared by the overview sidebar (Prologue/Description tabs) | ||
| * and the chapters column, so both columns' headers align and pin while their | ||
| * content scrolls independently. | ||
| */ | ||
| export function OverviewColumnHeader({ children }: { children: ReactNode }) { | ||
| return ( | ||
| <div className="sticky top-0 z-10 bg-background pb-3"> | ||
| <div className="flex h-7 items-center justify-between">{children}</div> | ||
| </div> | ||
| ); | ||
| } |
107 changes: 107 additions & 0 deletions
107
packages/web/src/components/pull-request/overview-sidebar.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| import type { Prologue } from "@stagereview/types/prologue"; | ||
| import type { GitHubPullRequest } from "@stagereview/types/pull-request"; | ||
| import { useCallback, useState } from "react"; | ||
| import { PrologueSection } from "@/components/prologue/prologue-section"; | ||
| import { OverviewColumnHeader } from "@/components/pull-request/overview-column-header"; | ||
| import { PullRequestBodyCard } from "@/components/pull-request/pull-request-body-card"; | ||
| import { CopyMarkdownButton } from "@/components/shared/copy-markdown-button"; | ||
| import { formatPrologueAsMarkdown } from "@/lib/format-prologue-markdown"; | ||
| import { cn } from "@/lib/utils"; | ||
|
|
||
| const SIDEBAR_TAB = { | ||
| PROLOGUE: "prologue", | ||
| DESCRIPTION: "description", | ||
| } as const; | ||
| type SidebarTab = (typeof SIDEBAR_TAB)[keyof typeof SIDEBAR_TAB]; | ||
|
|
||
| const TAB_CLASS = | ||
| "cursor-pointer rounded-md px-2.5 py-1 font-medium text-[11px] uppercase tracking-wider transition-colors"; | ||
|
|
||
| interface OverviewSidebarProps { | ||
| prologue: Prologue | null; | ||
| pullRequest: GitHubPullRequest | null; | ||
| } | ||
|
|
||
| /** | ||
| * Left overview column: a Prologue tab (the imported run's structured prologue) | ||
| * and a Description tab (the detected PR's markdown body). Each tab is shown | ||
| * only when its content exists; the route renders this only when at least one | ||
| * does. Mirrors hosted Stage's PrologueSidebar. | ||
| */ | ||
| export function OverviewSidebar({ prologue, pullRequest }: OverviewSidebarProps) { | ||
| const hasPrologue = prologue !== null; | ||
| const hasDescription = Boolean(pullRequest?.user && pullRequest.body.trim().length > 0); | ||
| // Default to whichever content exists at mount (the sidebar only renders once at | ||
| // least one does), preferring the prologue. Capturing the initial tab this way — | ||
| // rather than hardcoding Prologue — means a later-arriving tab can't yank the user | ||
| // off the one they're reading: if the PR description loads before the prologue, the | ||
| // view stays on Description instead of jumping to Prologue when it arrives. | ||
| const [activeTab, setActiveTab] = useState<SidebarTab>(() => | ||
| prologue !== null ? SIDEBAR_TAB.PROLOGUE : SIDEBAR_TAB.DESCRIPTION, | ||
| ); | ||
|
|
||
| // Recover to the available tab if the active one ever has no content. | ||
| const resolvedTab: SidebarTab = | ||
| activeTab === SIDEBAR_TAB.DESCRIPTION && !hasDescription | ||
| ? SIDEBAR_TAB.PROLOGUE | ||
| : activeTab === SIDEBAR_TAB.PROLOGUE && !hasPrologue | ||
| ? SIDEBAR_TAB.DESCRIPTION | ||
| : activeTab; | ||
|
cursor[bot] marked this conversation as resolved.
|
||
|
|
||
| const copyPrologue = useCallback( | ||
| () => (prologue ? formatPrologueAsMarkdown(prologue) : null), | ||
| [prologue], | ||
| ); | ||
|
|
||
| return ( | ||
| <div> | ||
| <OverviewColumnHeader> | ||
| <div className="flex items-center gap-1" role="tablist" aria-label="Overview tabs"> | ||
| {hasPrologue && ( | ||
| <button | ||
| type="button" | ||
| role="tab" | ||
| aria-selected={resolvedTab === SIDEBAR_TAB.PROLOGUE} | ||
| onClick={() => setActiveTab(SIDEBAR_TAB.PROLOGUE)} | ||
| className={cn( | ||
| TAB_CLASS, | ||
| resolvedTab === SIDEBAR_TAB.PROLOGUE | ||
| ? "bg-accent text-foreground" | ||
| : "text-muted-foreground hover:text-foreground", | ||
| )} | ||
| > | ||
| Prologue | ||
| </button> | ||
| )} | ||
| {hasDescription && ( | ||
| <button | ||
| type="button" | ||
| role="tab" | ||
| aria-selected={resolvedTab === SIDEBAR_TAB.DESCRIPTION} | ||
| onClick={() => setActiveTab(SIDEBAR_TAB.DESCRIPTION)} | ||
| className={cn( | ||
| TAB_CLASS, | ||
| resolvedTab === SIDEBAR_TAB.DESCRIPTION | ||
| ? "bg-accent text-foreground" | ||
| : "text-muted-foreground hover:text-foreground", | ||
| )} | ||
| > | ||
| Description | ||
| </button> | ||
| )} | ||
| </div> | ||
| {resolvedTab === SIDEBAR_TAB.PROLOGUE && prologue && ( | ||
| <CopyMarkdownButton getMarkdown={copyPrologue} label="prologue" /> | ||
| )} | ||
| </OverviewColumnHeader> | ||
|
|
||
| {resolvedTab === SIDEBAR_TAB.PROLOGUE && prologue ? ( | ||
| <PrologueSection prologue={prologue} /> | ||
| ) : pullRequest ? ( | ||
| <section className="rounded-lg border bg-card p-4"> | ||
| <PullRequestBodyCard pullRequest={pullRequest} /> | ||
| </section> | ||
| ) : null} | ||
| </div> | ||
| ); | ||
| } | ||
57 changes: 57 additions & 0 deletions
57
packages/web/src/components/pull-request/pull-request-body-card.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import type { GitHubPullRequest } from "@stagereview/types/pull-request"; | ||
| import { MessageSquare } from "lucide-react"; | ||
| import { UserName } from "@/components/shared/user-name"; | ||
| import { getUserDisplay } from "@/components/shared/user-utils"; | ||
| import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; | ||
| import { Markdown } from "@/components/ui/markdown"; | ||
| import { formatTimeAgo } from "@/lib/format"; | ||
|
|
||
| /** | ||
| * The PR description rendered as a GitHub-style comment: author avatar/header | ||
| * plus the markdown body. Mirrors hosted Stage's PullRequestBodyCard, minus the | ||
| * write/reaction affordances the CLI doesn't carry. | ||
| */ | ||
| export function PullRequestBodyCard({ pullRequest }: { pullRequest: GitHubPullRequest }) { | ||
| const user = pullRequest.user; | ||
| if (!user) return null; | ||
|
|
||
| const { profileUrl } = getUserDisplay(user); | ||
| const hasBody = pullRequest.body.trim().length > 0; | ||
|
|
||
| return ( | ||
| <div className="flex items-start gap-3"> | ||
| <a href={profileUrl} target="_blank" rel="noopener noreferrer" className="shrink-0"> | ||
| <Avatar className="size-8"> | ||
| <AvatarImage src={user.avatar_url} alt={user.login} /> | ||
| <AvatarFallback className="text-xs">{user.login[0]?.toUpperCase()}</AvatarFallback> | ||
| </Avatar> | ||
| </a> | ||
| <div className="min-w-0 flex-1"> | ||
| <p className="mb-1 text-muted-foreground text-sm"> | ||
| <span className="mr-1.5 inline-flex size-6 items-center justify-center rounded-full bg-muted align-middle text-muted-foreground"> | ||
| <MessageSquare className="size-3" /> | ||
| </span> | ||
| <UserName user={user} /> commented{" "} | ||
| <a | ||
| href={pullRequest.html_url} | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| className="hover:underline" | ||
| > | ||
| <time | ||
| dateTime={pullRequest.created_at} | ||
| title={new Date(pullRequest.created_at).toLocaleString()} | ||
| > | ||
| {formatTimeAgo(pullRequest.created_at)} | ||
| </time> | ||
| </a> | ||
| </p> | ||
| {hasBody ? ( | ||
| <Markdown content={pullRequest.body} allowHtml /> | ||
| ) : ( | ||
| <p className="text-muted-foreground text-sm italic">No description provided.</p> | ||
| )} | ||
| </div> | ||
| </div> | ||
| ); | ||
| } |
40 changes: 40 additions & 0 deletions
40
packages/web/src/components/shared/copy-markdown-button.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import { Copy } from "lucide-react"; | ||
| import { useCallback } from "react"; | ||
| import { Button } from "@/components/ui/button"; | ||
| import { toast } from "@/components/ui/sonner"; | ||
| import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"; | ||
|
|
||
| interface CopyMarkdownButtonProps { | ||
| /** Produces the Markdown to copy. Returning null/empty skips the copy. */ | ||
| getMarkdown: () => string | null; | ||
| /** Lowercase noun for the toast, e.g. "prologue" → "Copied prologue to clipboard". */ | ||
| label: string; | ||
| } | ||
|
|
||
| export function CopyMarkdownButton({ getMarkdown, label }: CopyMarkdownButtonProps) { | ||
| const handleCopy = useCallback(() => { | ||
| const markdown = getMarkdown(); | ||
| if (!markdown) return; | ||
| navigator.clipboard.writeText(markdown).then( | ||
| () => toast.success(`Copied ${label} to clipboard`), | ||
| () => toast.error("Failed to copy to clipboard"), | ||
| ); | ||
| }, [getMarkdown, label]); | ||
|
|
||
| return ( | ||
| <Tooltip> | ||
| <TooltipTrigger asChild> | ||
| <Button | ||
| variant="ghost" | ||
| size="icon" | ||
| aria-label={`Copy ${label}`} | ||
| className="size-6 cursor-pointer rounded-md text-muted-foreground" | ||
| onClick={handleCopy} | ||
| > | ||
| <Copy className="size-3.5" /> | ||
| </Button> | ||
| </TooltipTrigger> | ||
| <TooltipContent>Copy {label} as Markdown</TooltipContent> | ||
| </Tooltip> | ||
| ); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.