Skip to content

Commit b04b9dc

Browse files
committed
fix(web): PR code toolbar fits narrow panels
1 parent d60a71e commit b04b9dc

1 file changed

Lines changed: 117 additions & 63 deletions

File tree

‎apps/web/src/components/pullRequest/PullRequestCodeTab.tsx‎

Lines changed: 117 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
MessageSquareOffIcon,
2020
PilcrowIcon,
2121
Rows3Icon,
22+
Settings2Icon,
2223
TextWrapIcon,
2324
TriangleAlertIcon,
2425
} from "lucide-react";
@@ -68,10 +69,12 @@ import { Checkbox } from "../ui/checkbox";
6869
import { Collapsible, CollapsiblePanel, CollapsibleTrigger } from "../ui/collapsible";
6970
import {
7071
DropdownMenu,
72+
DropdownMenuCheckboxItem,
7173
DropdownMenuContent,
7274
DropdownMenuItem,
7375
DropdownMenuRadioGroup,
7476
DropdownMenuRadioItem,
77+
DropdownMenuSeparator,
7578
DropdownMenuTrigger,
7679
} from "../ui/menu";
7780
import { toastManager } from "../ui/toast";
@@ -1059,8 +1062,13 @@ function PullRequestCodeTab({
10591062
}
10601063
}, [commit, onSelectedCommitChange, selectedCommit]);
10611064
const scopeLabel = selectedCommit ? selectedCommit.messageHeadline : "All commits";
1065+
const changeIgnoreWhitespace = (next: boolean) => {
1066+
setIgnoreWhitespace(next);
1067+
setDraft(null);
1068+
setSelectedLines(null);
1069+
};
10621070
const toolbar = (
1063-
<div className="flex h-10 min-h-10 shrink-0 items-center justify-between gap-2 border-b border-border/60 bg-background px-4 text-xs text-muted-foreground">
1071+
<div className="@container flex h-10 min-h-10 shrink-0 items-center justify-between gap-2 border-b border-border/60 bg-background px-4 text-xs text-muted-foreground">
10641072
<div className="flex min-w-0 flex-1 items-center gap-3">
10651073
{/* A host that reports no commits has nothing to scope by, and a dropdown whose only
10661074
entry is the scope already showing is a control that does nothing. */}
@@ -1117,7 +1125,7 @@ function PullRequestCodeTab({
11171125
) : null}
11181126
{/* One count, and the caveats as icons that carry their own words. Spelled out they
11191127
competed for a strip this narrow and every one of them truncated to nothing. */}
1120-
<PullRequestMetaLine className="shrink-0">
1128+
<PullRequestMetaLine>
11211129
<span className="shrink-0 tabular-nums">
11221130
{files.length} {files.length === 1 ? "file" : "files"}
11231131
{nextCursor === null ? "" : "+"}
@@ -1208,30 +1216,115 @@ function PullRequestCodeTab({
12081216
</PullRequestMetaLine>
12091217
</div>
12101218
<div className="flex shrink-0 items-center gap-1">
1211-
<Tooltip>
1212-
<TooltipTrigger
1213-
render={
1214-
<Toggle
1215-
aria-label={
1216-
ignoreWhitespace ? "Show whitespace changes" : "Hide whitespace changes"
1219+
{/* View settings fold into one menu when the panel is too narrow to show them
1220+
beside the scope and file count. */}
1221+
<DropdownMenu>
1222+
<Tooltip>
1223+
<TooltipTrigger
1224+
render={
1225+
<DropdownMenuTrigger
1226+
render={<Button size="icon-sm" variant="ghost" />}
1227+
className="@lg:hidden"
1228+
aria-label="Diff options"
1229+
/>
1230+
}
1231+
>
1232+
<Settings2Icon className="size-3.5" />
1233+
</TooltipTrigger>
1234+
<TooltipPopup side="top">Diff options</TooltipPopup>
1235+
</Tooltip>
1236+
<DropdownMenuContent align="end">
1237+
<DropdownMenuCheckboxItem
1238+
checked={ignoreWhitespace}
1239+
onCheckedChange={(checked) => changeIgnoreWhitespace(checked)}
1240+
>
1241+
Hide whitespace changes
1242+
</DropdownMenuCheckboxItem>
1243+
<DropdownMenuCheckboxItem
1244+
checked={wordWrap}
1245+
onCheckedChange={(checked) => setWordWrap(checked)}
1246+
>
1247+
Wrap lines
1248+
</DropdownMenuCheckboxItem>
1249+
<DropdownMenuSeparator />
1250+
<DropdownMenuRadioGroup
1251+
value={diffLayout}
1252+
onValueChange={(value) => {
1253+
if (value === "stacked" || value === "split") {
1254+
updateClientSettings({ diffLayout: value });
12171255
}
1218-
variant="ghost"
1219-
size="sm"
1220-
pressed={ignoreWhitespace}
1221-
onPressedChange={(pressed) => {
1222-
setIgnoreWhitespace(Boolean(pressed));
1223-
setDraft(null);
1224-
setSelectedLines(null);
1225-
}}
1226-
/>
1227-
}
1256+
}}
1257+
>
1258+
<DropdownMenuRadioItem value="stacked" closeOnClick>
1259+
Stacked
1260+
</DropdownMenuRadioItem>
1261+
<DropdownMenuRadioItem value="split" closeOnClick>
1262+
Split
1263+
</DropdownMenuRadioItem>
1264+
</DropdownMenuRadioGroup>
1265+
</DropdownMenuContent>
1266+
</DropdownMenu>
1267+
<div className="hidden items-center gap-1 @lg:flex">
1268+
<Tooltip>
1269+
<TooltipTrigger
1270+
render={
1271+
<Toggle
1272+
aria-label={
1273+
ignoreWhitespace ? "Show whitespace changes" : "Hide whitespace changes"
1274+
}
1275+
variant="ghost"
1276+
size="sm"
1277+
pressed={ignoreWhitespace}
1278+
onPressedChange={(pressed) => changeIgnoreWhitespace(Boolean(pressed))}
1279+
/>
1280+
}
1281+
>
1282+
<PilcrowIcon className="size-3.5" />
1283+
</TooltipTrigger>
1284+
<TooltipPopup side="top">
1285+
{ignoreWhitespace ? "Show whitespace changes" : "Hide whitespace changes"}
1286+
</TooltipPopup>
1287+
</Tooltip>
1288+
<ToggleGroup
1289+
aria-label="Diff layout"
1290+
className="shrink-0"
1291+
variant="segmented"
1292+
value={[diffLayout]}
1293+
onValueChange={(value) => {
1294+
const next = value[0];
1295+
if (next === "stacked" || next === "split") {
1296+
updateClientSettings({ diffLayout: next });
1297+
}
1298+
}}
12281299
>
1229-
<PilcrowIcon className="size-3.5" />
1230-
</TooltipTrigger>
1231-
<TooltipPopup side="top">
1232-
{ignoreWhitespace ? "Show whitespace changes" : "Hide whitespace changes"}
1233-
</TooltipPopup>
1234-
</Tooltip>
1300+
<Toggle aria-label="Stacked diff view" value="stacked">
1301+
<Rows3Icon className="size-3.5" />
1302+
</Toggle>
1303+
<Toggle aria-label="Split diff view" value="split">
1304+
<Columns2Icon className="size-3.5" />
1305+
</Toggle>
1306+
</ToggleGroup>
1307+
<Tooltip>
1308+
<TooltipTrigger
1309+
render={
1310+
<Toggle
1311+
aria-label={wordWrap ? "Disable diff line wrapping" : "Enable diff line wrapping"}
1312+
variant="ghost"
1313+
size="sm"
1314+
pressed={wordWrap}
1315+
onPressedChange={(pressed) => {
1316+
setWordWrap(Boolean(pressed));
1317+
}}
1318+
/>
1319+
}
1320+
>
1321+
<TextWrapIcon className="size-3.5" />
1322+
</TooltipTrigger>
1323+
<TooltipPopup side="top">
1324+
{wordWrap ? "Disable line wrapping" : "Enable line wrapping"}
1325+
</TooltipPopup>
1326+
</Tooltip>
1327+
</div>
12351328
{fileKeys.length > 0 ? (
12361329
<Tooltip>
12371330
<TooltipTrigger
@@ -1255,45 +1348,6 @@ function PullRequestCodeTab({
12551348
</TooltipPopup>
12561349
</Tooltip>
12571350
) : null}
1258-
<ToggleGroup
1259-
aria-label="Diff layout"
1260-
className="shrink-0"
1261-
variant="segmented"
1262-
value={[diffLayout]}
1263-
onValueChange={(value) => {
1264-
const next = value[0];
1265-
if (next === "stacked" || next === "split") {
1266-
updateClientSettings({ diffLayout: next });
1267-
}
1268-
}}
1269-
>
1270-
<Toggle aria-label="Stacked diff view" value="stacked">
1271-
<Rows3Icon className="size-3.5" />
1272-
</Toggle>
1273-
<Toggle aria-label="Split diff view" value="split">
1274-
<Columns2Icon className="size-3.5" />
1275-
</Toggle>
1276-
</ToggleGroup>
1277-
<Tooltip>
1278-
<TooltipTrigger
1279-
render={
1280-
<Toggle
1281-
aria-label={wordWrap ? "Disable diff line wrapping" : "Enable diff line wrapping"}
1282-
variant="ghost"
1283-
size="sm"
1284-
pressed={wordWrap}
1285-
onPressedChange={(pressed) => {
1286-
setWordWrap(Boolean(pressed));
1287-
}}
1288-
/>
1289-
}
1290-
>
1291-
<TextWrapIcon className="size-3.5" />
1292-
</TooltipTrigger>
1293-
<TooltipPopup side="top">
1294-
{wordWrap ? "Disable line wrapping" : "Enable line wrapping"}
1295-
</TooltipPopup>
1296-
</Tooltip>
12971351
{fileKeys.length > 0 ? (
12981352
<Tooltip>
12991353
<TooltipTrigger

0 commit comments

Comments
 (0)