TypeScript
refactor(web): mark the current menu value with MenuRadioGroup (#13022)
Julius Marmingece98d4107758
diff --git a/apps/web/src/components/DiffPanel.tsx b/apps/web/src/components/DiffPanel.tsxindex 21cd54792d1..2a598ff1292 100644--- a/apps/web/src/components/DiffPanel.tsx+++ b/apps/web/src/components/DiffPanel.tsx@@ -72,7 +72,8 @@ import {import {DropdownMenu,DropdownMenuContent,- DropdownMenuItem,+ DropdownMenuRadioGroup,+ DropdownMenuRadioItem,DropdownMenuSub,DropdownMenuSubContent,DropdownMenuSubTrigger,@@ -645,6 +646,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 = (<>@@ -658,61 +679,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 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>diff --git a/apps/web/src/components/files/FileBreadcrumbs.tsx b/apps/web/src/components/files/FileBreadcrumbs.tsxindex 3021ff0fab6..aa7bc97be0f 100644--- a/apps/web/src/components/files/FileBreadcrumbs.tsx+++ b/apps/web/src/components/files/FileBreadcrumbs.tsx@@ -10,6 +10,8 @@ import {MenuGroup,MenuItem,MenuPopup,+ MenuRadioGroup,+ MenuRadioItem,MenuSeparator,MenuTrigger,} from "~/components/ui/menu";@@ -141,39 +143,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]",- entry.ignored && "text-muted-foreground",- )}- 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">{entry.path}</TooltipPopup>+ </Tooltip>+ </>+ );+ return entry.kind === "directory" ? (+ <MenuItem+ key={entry.path}+ closeOnClick={false}+ className={entry.ignored ? "text-muted-foreground" : undefined}+ onClick={() => props.onDirectoryChange(entry.path)}+ >+ {row}+ <ChevronRightIcon />+ </MenuItem>+ ) : (+ <MenuRadioItem+ key={entry.path}+ value={entry.path}+ closeOnClick+ aria-current={isCurrentFile ? "page" : undefined}+ className={entry.ignored ? "text-muted-foreground" : undefined}+ >+ <span className="flex min-w-0 items-center gap-2">{row}</span>+ </MenuRadioItem>+ );+ })}+ </MenuRadioGroup>)}</MenuGroup>{entriesQuery.error && entriesQuery.data !== null ? (diff --git a/apps/web/src/components/pullRequest/PullRequestCodeTab.tsx b/apps/web/src/components/pullRequest/PullRequestCodeTab.tsxindex 131593ab6d2..aa56ac66d19 100644--- a/apps/web/src/components/pullRequest/PullRequestCodeTab.tsx+++ b/apps/web/src/components/pullRequest/PullRequestCodeTab.tsx@@ -70,6 +70,8 @@ import {DropdownMenu,DropdownMenuContent,DropdownMenuItem,+ DropdownMenuRadioGroup,+ DropdownMenuRadioItem,DropdownMenuTrigger,} from "../ui/menu";import { toastManager } from "../ui/toast";@@ -1076,31 +1078,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 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.diff --git a/scripts/lint-restyle-ceiling.ts b/scripts/lint-restyle-ceiling.tsindex a73c8006c82..78babaf7405 100644--- a/scripts/lint-restyle-ceiling.ts+++ b/scripts/lint-restyle-ceiling.ts@@ -8,7 +8,7 @@ import * as NodeURL from "node:url";// components/ui exports are migrated to variants (see vite.config.ts). This gate keeps the// count from growing: CI fails when findings exceed the ceiling. Lower the ceiling when you// migrate a file, and delete this script when the rule becomes an error.-export const RESTYLE_CEILING = 1165;+export const RESTYLE_CEILING = 1159;const RULE = "shadcn(no-restyle)";