import type { FileDiffContentsLoader, FileDiffMetadata } from "@pierre/diffs"; import type { PullRequestReviewGuideAttention, PullRequestReviewGuideStop, } from "@t3tools/contracts"; import { ArrowRightIcon, ChevronDownIcon, ChevronRightIcon, ChevronUpIcon, EyeIcon, FileIcon, MessageCircleQuestionIcon, MessageSquareIcon, } from "lucide-react"; import { useMemo, type ReactNode } from "react"; import { getDiffLineStat } from "~/lib/diffRendering"; import { cn } from "~/lib/utils"; import { DiffWorkerPoolProvider } from "../../DiffWorkerPoolProvider"; import { Alert, AlertDescription, AlertTitle } from "../../ui/alert"; import { Button } from "../../ui/button"; import { Kbd } from "../../ui/kbd"; import { PullRequestDiffStat } from "../pullRequestPresentation"; import { Collapsible, CollapsiblePanel, CollapsibleTrigger } from "../../ui/collapsible"; import { GuideExcerpt, type ExcerptCommenting } from "./GuideExcerpt"; import { GuideFileDiff } from "./GuideFileDiff"; import { GuideNotes } from "./GuideNotes"; import { GuideProse } from "./GuideProse"; import { letterStopNotes } from "@t3tools/client-runtime/review-guide-tour"; const ATTENTION_LABELS = { tradeoff: "A tradeoff to weigh", contract: "A contract to check", product: "A product call", risk: "A risk to judge", accessibility: "An accessibility call", } as const satisfies Record; /** * One stop of the tour: what it is about, where to look, and the two things a reader does with * it: comment on its lines for the review, or ask an agent about it. */ export function GuideStop({ stop, index, stopCount, railOpen, onRailOpenChange, stopList, nextTitle, files, loadDiffFiles, diffLoading, commenting, onStep, onAsk, onFinish, onOpenFile, }: { stop: PullRequestReviewGuideStop; index: number; stopCount: number; /** Whether the stop list is folded open under the header, on a narrow panel. */ railOpen: boolean; onRailOpenChange: (open: boolean) => void; /** The tour's stop list, folded under the header on a narrow panel. */ stopList: ReactNode; /** The following stop's title, null on the last stop. */ nextTitle: string | null; files: ReadonlyMap; /** Loads a file's unchanged lines for the bars between hunks. */ loadDiffFiles: FileDiffContentsLoader; diffLoading: boolean; /** Commenting on excerpt lines; null where the reader can neither comment nor ask. */ commenting: ExcerptCommenting | null; onStep: (delta: 1 | -1) => void; /** Opens an agent thread about this stop, with the question prefilled or empty. */ onAsk: ((question: string) => void) | null; /** Opens the review composer, on the last stop. Null where the reader cannot review. */ onFinish: (() => void) | null; onOpenFile: (path: string) => void; }) { const { lettered, byExcerpt } = useMemo(() => letterStopNotes(stop), [stop]); const excerptPaths = new Set(stop.excerpts.map((excerpt) => excerpt.path)); // Files the stop owns without excerpting, and excerpted ones listed again with a note. const otherFiles = stop.files.filter((file) => !excerptPaths.has(file.path)); const hasNotes = lettered.length > 0; return ( // On a maximized panel the notes take a sticky column of their own beside the stop; a stop // without notes keeps the whole width. Narrower, they follow the excerpts.
{/* Narrow, the stop list folds open under this line like an accordion, so one place says where the reader is. Wide, the list sits beside the stop and this is a label. */}

Stop {index + 1} of {stopCount}

} > Stop {index + 1} of {stopCount}
J K
{stopList}

{stop.title}

{stop.summary.trim() !== "" ? (
) : null}
{stop.attention !== null ? ( // A call for the reader to make, not a warning, so it reads as a plain notice. {ATTENTION_LABELS[stop.attention.kind]}
) : null} {stop.excerpts.length > 0 ? (
{stop.excerpts.map((excerpt, excerptIndex) => ( ))}
) : null} {otherFiles.length > 0 ? (

{stop.excerpts.length > 0 ? "Also in this stop" : "Files in this stop"}

    {otherFiles.map((file) => { const diff = files.get(file.path); const stat = diff === undefined ? null : getDiffLineStat([diff]); return (
  • {file.path} {file.note !== undefined && file.note.trim() !== "" ? ( ) : null} {stat !== null ? ( ) : null} {diff !== undefined ? ( ) : (

    {diffLoading ? "Loading the diff..." : "This file is not in the loaded diff."}

    )}
  • ); })}
) : null} {stop.questions.length > 0 || onAsk !== null ? (
{stop.questions.length > 0 ? (

Questions to consider

) : null}
{stop.questions.map((question) => onAsk === null ? (
) : ( // A question is a sentence, so it wraps rather than truncating as a button would. ), )} {onAsk !== null ? ( ) : null}
) : null}
{nextTitle !== null ? ( ) : onFinish !== null ? ( ) : null}
{hasNotes ? ( ) : null}
); }