Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 55 additions & 53 deletions apps/web/src/components/DiffPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ import {
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuRadioGroup,
DropdownMenuRadioItem,
DropdownMenuSub,
DropdownMenuSubContent,
DropdownMenuSubTrigger,
Expand Down Expand Up @@ -644,6 +645,26 @@ export default function DiffPanel({
if (!routeThreadRef) return;
useDiffPanelStore.getState().selectBranchBaseRef(routeThreadRef, baseRef);
};
// The scope menu has two radio groups: the top-level one treats the latest
// turn as "latest", while the turn sub-menu keys every turn by id so the
// latest turn is also marked there.
const selectedTurnValue = selectedTurn ? `turn:${selectedTurn.turnId}` : "";
const selectedScopeValue =
selectedTurnId === null
? selectedGitScope
: selectedTurn?.turnId === latestTurn?.turnId
? "latest"
: selectedTurnValue;
const selectScopeValue = (value: string) => {
if (value === "unstaged" || value === "branch") {
selectGitScope(value);
} else if (value === "latest") {
if (latestTurn) selectTurn(latestTurn.turnId);
} else {
const turn = orderedTurnDiffSummaries.find((summary) => `turn:${summary.turnId}` === value);
if (turn) selectTurn(turn.turnId);
}
};

const headerRow = (
<>
Expand All @@ -657,61 +678,42 @@ export default function DiffPanel({
<ChevronDownIcon className="size-3.5 shrink-0 opacity-70" />
</DropdownMenuTrigger>
<DropdownMenuContent align="start" className="w-60">
<DropdownMenuItem
className={
selectedTurnId === null && selectedGitScope === "unstaged"
? "bg-foreground/[0.08]"
: undefined
}
onClick={() => selectGitScope("unstaged")}
>
<span>Working tree</span>
</DropdownMenuItem>
<DropdownMenuItem
className={
selectedTurnId === null && selectedGitScope === "branch"
? "bg-foreground/[0.08]"
: undefined
}
onClick={() => selectGitScope("branch")}
>
<span>Branch changes</span>
</DropdownMenuItem>
<DropdownMenuItem
className={
selectedTurnId !== null && selectedTurn?.turnId === latestTurn?.turnId
? "bg-foreground/[0.08]"
: undefined
}
onClick={() => {
if (latestTurn) selectTurn(latestTurn.turnId);
}}
>
<span>Latest turn</span>
</DropdownMenuItem>
<DropdownMenuRadioGroup value={selectedScopeValue} onValueChange={selectScopeValue}>
<DropdownMenuRadioItem value="unstaged" closeOnClick>
<span>Working tree</span>
</DropdownMenuRadioItem>
<DropdownMenuRadioItem value="branch" closeOnClick>
<span>Branch changes</span>
</DropdownMenuRadioItem>
<DropdownMenuRadioItem value="latest" closeOnClick>
<span>Latest turn</span>
</DropdownMenuRadioItem>
</DropdownMenuRadioGroup>
<DropdownMenuSub>
<DropdownMenuSubTrigger>Turn</DropdownMenuSubTrigger>
<DropdownMenuSubContent className="w-64">
{orderedTurnDiffSummaries.map((summary) => {
const turnCount =
summary.checkpointTurnCount ??
inferredCheckpointTurnCountByTurnId[summary.turnId] ??
"?";
return (
<DropdownMenuItem
key={summary.turnId}
className={
summary.turnId === selectedTurn?.turnId ? "bg-foreground/[0.08]" : undefined
}
onClick={() => selectTurn(summary.turnId)}
>
<span>Turn {turnCount}</span>
<span className="ml-auto text-xs tabular-nums text-muted-foreground">
{formatShortTimestamp(summary.completedAt, settings.timestampFormat)}
</span>
</DropdownMenuItem>
);
})}
<DropdownMenuRadioGroup value={selectedTurnValue} onValueChange={selectScopeValue}>
{orderedTurnDiffSummaries.map((summary) => {
const turnCount =
summary.checkpointTurnCount ??
inferredCheckpointTurnCountByTurnId[summary.turnId] ??
"?";
return (
<DropdownMenuRadioItem
key={summary.turnId}
value={`turn:${summary.turnId}`}
closeOnClick
>
<span className="flex min-w-0 flex-1 items-center gap-2">
<span>Turn {turnCount}</span>
<span className="ml-auto text-xs tabular-nums text-muted-foreground">
{formatShortTimestamp(summary.completedAt, settings.timestampFormat)}
</span>
</span>
</DropdownMenuRadioItem>
);
})}
</DropdownMenuRadioGroup>
</DropdownMenuSubContent>
</DropdownMenuSub>
</DropdownMenuContent>
Expand Down
77 changes: 47 additions & 30 deletions apps/web/src/components/files/FileBreadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
MenuGroup,
MenuItem,
MenuPopup,
MenuRadioGroup,
MenuRadioItem,
MenuSeparator,
MenuTrigger,
} from "~/components/ui/menu";
Expand Down Expand Up @@ -143,36 +145,51 @@ function BreadcrumbMenuContent(props: {
: "This folder is empty."}
</MenuItem>
) : (
children.map((entry) => {
const isCurrentFile = entry.kind === "file" && entry.path === props.currentFilePath;
return (
<MenuItem
key={entry.path}
closeOnClick={entry.kind === "file"}
aria-current={isCurrentFile ? "page" : undefined}
className={cn(isCurrentFile && "bg-foreground/[0.08]")}
onClick={() => {
if (entry.kind === "directory") {
props.onDirectoryChange(entry.path);
return;
}
props.onOpenChange(false);
props.onOpenFile(entry.path);
}}
>
<PierreEntryIcon pathValue={entry.path} kind={entry.kind} theme={resolvedTheme} />
<Tooltip>
<TooltipTrigger render={<span className="min-w-0 flex-1 truncate" />}>
{entry.label}
</TooltipTrigger>
<TooltipPopup side="right" className="max-w-80">
{entry.path}
</TooltipPopup>
</Tooltip>
{entry.kind === "directory" ? <ChevronRightIcon /> : null}
</MenuItem>
);
})
// Files form a radio group keyed by path so the open file is marked as checked;
// directories only navigate the menu, so they stay plain items.
<MenuRadioGroup
value={props.currentFilePath}
onValueChange={(path) => {
props.onOpenChange(false);
props.onOpenFile(path);
}}
>
{children.map((entry) => {
const isCurrentFile = entry.kind === "file" && entry.path === props.currentFilePath;
const row = (
<>
<PierreEntryIcon pathValue={entry.path} kind={entry.kind} theme={resolvedTheme} />
<Tooltip>
<TooltipTrigger render={<span className="min-w-0 flex-1 truncate" />}>
{entry.label}
</TooltipTrigger>
<TooltipPopup side="right" className="max-w-80">
{entry.path}
</TooltipPopup>
</Tooltip>
</>
);
return entry.kind === "directory" ? (
<MenuItem
key={entry.path}
closeOnClick={false}
onClick={() => props.onDirectoryChange(entry.path)}
>
{row}
<ChevronRightIcon />
</MenuItem>
) : (
<MenuRadioItem
key={entry.path}
value={entry.path}
closeOnClick
aria-current={isCurrentFile ? "page" : undefined}
>
<span className="flex min-w-0 flex-1 items-center gap-2">{row}</span>
</MenuRadioItem>
);
})}
</MenuRadioGroup>
)}
</MenuGroup>
{entriesQuery.error && entriesQuery.data !== null ? (
Expand Down
50 changes: 26 additions & 24 deletions apps/web/src/components/pullRequest/PullRequestCodeTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuRadioGroup,
DropdownMenuRadioItem,
DropdownMenuTrigger,
} from "../ui/menu";
import { toastManager } from "../ui/toast";
Expand Down Expand Up @@ -1048,31 +1050,31 @@ function PullRequestCodeTab({
<ChevronDownIcon className="size-3.5 shrink-0 opacity-70" />
</DropdownMenuTrigger>
<DropdownMenuContent align="start" className="w-80">
<DropdownMenuItem
className={commit === null ? "bg-foreground/[0.08]" : undefined}
onClick={() => onSelectedCommitChange(null)}
<DropdownMenuRadioGroup
value={commit ?? "all"}
onValueChange={(value) => onSelectedCommitChange(value === "all" ? null : value)}
>
<span>All commits</span>
</DropdownMenuItem>
{orderedCommits.slice(0, visibleCommitCount).map((entry) => (
<DropdownMenuItem
key={entry.oid}
className={entry.oid === commit ? "bg-foreground/[0.08]" : undefined}
onClick={() => onSelectedCommitChange(entry.oid)}
>
{/* Headlines run long, and the abbreviated oid after one is what a reader
matches against the commit list on the host. */}
<Tooltip>
<TooltipTrigger
render={<span className="min-w-0 truncate">{entry.messageHeadline}</span>}
/>
<TooltipPopup side="top">{entry.messageHeadline}</TooltipPopup>
</Tooltip>
<span className="ml-auto shrink-0 font-mono text-xs text-muted-foreground">
{entry.oid.slice(0, 7)}
</span>
</DropdownMenuItem>
))}
<DropdownMenuRadioItem value="all" closeOnClick>
<span>All commits</span>
</DropdownMenuRadioItem>
{orderedCommits.slice(0, visibleCommitCount).map((entry) => (
<DropdownMenuRadioItem key={entry.oid} value={entry.oid} closeOnClick>
{/* Headlines run long, and the abbreviated oid after one is what a reader
matches against the commit list on the host. */}
<span className="flex min-w-0 flex-1 items-center gap-2">
<Tooltip>
<TooltipTrigger
render={<span className="min-w-0 truncate">{entry.messageHeadline}</span>}
/>
<TooltipPopup side="top">{entry.messageHeadline}</TooltipPopup>
</Tooltip>
<span className="ml-auto shrink-0 font-mono text-xs text-muted-foreground">
{entry.oid.slice(0, 7)}
</span>
</span>
</DropdownMenuRadioItem>
))}
</DropdownMenuRadioGroup>
{orderedCommits.length > visibleCommitCount ? (
// Kept out of the radio group: it changes how much of the list is on screen
// rather than what the diff is scoped to.
Expand Down
Loading