@devries-cameron20 / t3code-1 / commits / 09bd654754
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

refactor(web): the pull requests column lives in its own component (#22671)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 21, 2026 at 01:28 UTC 09bd6547548c31b95b2cf7de160c88e3767366de
4 files changed +435 -411
apps/web/src/components/pullRequest/PullRequestCompactFilterMenu.tsx new
+93
@@ -0,0 +1,93 @@
1 +import { ChevronDownIcon } from "lucide-react";
2 +import type { ReactNode } from "react";
3 +
4 +import { cn } from "~/lib/utils";
5 +import { Button } from "../ui/button";
6 +import { Menu, MenuPopup, MenuRadioGroup, MenuRadioItem, MenuTrigger } from "../ui/menu";
7 +import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
8 +import {
9 + PullRequestFilterOptionIcon,
10 + type PullRequestFilterOption,
11 +} from "./PullRequestListFilters";
12 +
13 +export function PullRequestCompactFilterMenu<Value extends string>({
14 + label,
15 + triggerIcon,
16 + triggerLabel,
17 + outlined = false,
18 + iconOnly = false,
19 + value,
20 + options,
21 + onChange,
22 + className,
23 +}: {
24 + label: string;
25 + triggerIcon?: ReactNode;
26 + triggerLabel?: string;
27 + outlined?: boolean;
28 + iconOnly?: boolean;
29 + value: Value;
30 + options: ReadonlyArray<PullRequestFilterOption<Value>>;
31 + onChange: (value: Value) => void;
32 + className?: string;
33 +}) {
34 + const current = options.find((option) => option.value === value) ?? options[0];
35 + if (!current) return null;
36 + return (
37 + <Menu>
38 + <MenuTrigger
39 + aria-label={triggerLabel || iconOnly ? `${label}: ${current.label}` : label}
40 + title={iconOnly ? `${label}: ${current.label}` : undefined}
41 + render={
42 + outlined ? (
43 + <Button variant="outline" size={iconOnly ? "icon" : "default"} />
44 + ) : (
45 + <Button variant="ghost-muted" size="sm" />
46 + )
47 + }
48 + className={cn("min-w-0", className)}
49 + >
50 + {iconOnly ? (
51 + <current.Icon aria-hidden className="size-4" />
52 + ) : triggerLabel ? (
53 + <>
54 + {triggerIcon}
55 + <span>{triggerLabel}</span>
56 + </>
57 + ) : (
58 + <>
59 + <span className="truncate">{current.label}</span>
60 + <ChevronDownIcon aria-hidden className="size-3 shrink-0 text-muted-foreground/70" />
61 + </>
62 + )}
63 + </MenuTrigger>
64 + <MenuPopup align="start" side="bottom">
65 + <MenuRadioGroup value={value} onValueChange={(next) => onChange(next as Value)}>
66 + {options.map((option) => {
67 + const item = (
68 + <MenuRadioItem
69 + key={option.value}
70 + value={option.value}
71 + disabled={option.unavailable !== undefined}
72 + className="data-disabled:pointer-events-auto"
73 + >
74 + <span className="flex min-w-0 items-center gap-2">
75 + <PullRequestFilterOptionIcon option={option} />
76 + {option.label}
77 + </span>
78 + </MenuRadioItem>
79 + );
80 + return option.unavailable === undefined ? (
81 + item
82 + ) : (
83 + <Tooltip key={option.value}>
84 + <TooltipTrigger render={item} />
85 + <TooltipPopup side="right">{option.unavailable}</TooltipPopup>
86 + </Tooltip>
87 + );
88 + })}
89 + </MenuRadioGroup>
90 + </MenuPopup>
91 + </Menu>
92 + );
93 +}
apps/web/src/components/pullRequest/PullRequestsColumn.tsx new
+293
@@ -0,0 +1,293 @@
1 +import type { PullRequestInvolvement, PullRequestListState } from "@t3tools/contracts";
2 +import { Plug2Icon, SearchIcon } from "lucide-react";
3 +import { useEffect, useRef, useState, type ReactNode, type RefObject } from "react";
4 +
5 +import { isElectron } from "~/env";
6 +import { cn } from "~/lib/utils";
7 +import { Button } from "../ui/button";
8 +import { RefreshIcon } from "../ui/refresh-icon";
9 +import {
10 + WorkspaceBreadcrumb,
11 + WorkspaceBreadcrumbItem,
12 + WorkspaceBreadcrumbSeparator,
13 +} from "../WorkspaceBreadcrumb";
14 +import { WorkspacePageContainer } from "../WorkspacePageContainer";
15 +import { WorkspacePageHeader } from "../WorkspacePageHeader";
16 +import { PullRequestCompactFilterMenu } from "./PullRequestCompactFilterMenu";
17 +import type { PullRequestFilterOption } from "./PullRequestListFilters";
18 +import { INVOLVEMENT_TABS, STATE_TABS } from "./pullRequestListOptions";
19 +
20 +function ExpandableSearch({
21 + searchInput,
22 + searchValue,
23 + open,
24 + onOpenChange,
25 + focusToken,
26 + onFocusWithin,
27 +}: {
28 + searchInput: ReactNode;
29 + searchValue: string;
30 + open: boolean;
31 + onOpenChange: (open: boolean) => void;
32 + focusToken: number;
33 + /**
34 + * An unmount fires no blur, which is the point: whoever unmounted this can still see the reader
35 + * was mid-typing and move the focus somewhere that continues the sentence.
36 + */
37 + onFocusWithin?: (focused: boolean) => void;
38 +}) {
39 + const containerRef = useRef<HTMLDivElement | null>(null);
40 + useEffect(() => {
41 + if (!open) return;
42 + containerRef.current?.querySelector("input")?.focus();
43 + }, [open]);
44 + const appliedFocusToken = useRef(focusToken);
45 + useEffect(() => {
46 + if (appliedFocusToken.current === focusToken) return;
47 + appliedFocusToken.current = focusToken;
48 + const input = containerRef.current?.querySelector("input");
49 + input?.focus();
50 + input?.select();
51 + }, [focusToken]);
52 + if (open || searchValue.length > 0) {
53 + return (
54 + <div
55 + ref={containerRef}
56 + className="w-56 min-w-24 shrink"
57 + onFocus={() => onFocusWithin?.(true)}
58 + onBlur={() => {
59 + onFocusWithin?.(false);
60 + if (searchValue.length === 0) onOpenChange(false);
61 + }}
62 + >
63 + {searchInput}
64 + </div>
65 + );
66 + }
67 + return (
68 + <Button
69 + size="icon-sm"
70 + variant="ghost"
71 + aria-label="Search pull requests"
72 + onClick={() => onOpenChange(true)}
73 + >
74 + <SearchIcon className="size-4" />
75 + </Button>
76 + );
77 +}
78 +
79 +export function PullRequestsColumn({
80 + refreshing,
81 + onRefresh,
82 + searchValue,
83 + involvement,
84 + state,
85 + host,
86 + hostMenuOptions,
87 + onInvolvement,
88 + onState,
89 + onHost,
90 + searchInput,
91 + sortMenu,
92 + filtersMenu,
93 + rightPanelControl,
94 + titlebarControls,
95 + rightPanelOpen,
96 + maximizedAway,
97 + listBody,
98 + scrollRef,
99 +}: {
100 + refreshing: boolean;
101 + onRefresh: () => void;
102 + searchValue: string;
103 + involvement: PullRequestInvolvement;
104 + state: PullRequestListState;
105 + host: string | undefined;
106 + hostMenuOptions: ReadonlyArray<PullRequestFilterOption<string>>;
107 + onInvolvement: (involvement: PullRequestInvolvement) => void;
108 + onState: (state: PullRequestListState) => void;
109 + onHost: (host: string | undefined) => void;
110 + searchInput: ReactNode;
111 + sortMenu: ReactNode;
112 + filtersMenu: ReactNode;
113 + rightPanelControl: ReactNode;
114 + titlebarControls: ReactNode;
115 + rightPanelOpen: boolean;
116 + maximizedAway: boolean;
117 + listBody: ReactNode;
118 + scrollRef: RefObject<HTMLDivElement | null>;
119 +}) {
120 + const markerRef = useRef<HTMLDivElement | null>(null);
121 + const [condensed, setCondensed] = useState(false);
122 + useEffect(() => {
123 + const marker = markerRef.current;
124 + if (!marker) return;
125 + const observer = new IntersectionObserver(
126 + ([entry]) => setCondensed(entry ? !entry.isIntersecting : false),
127 + { root: scrollRef.current },
128 + );
129 + observer.observe(marker);
130 + return () => observer.disconnect();
131 + }, [scrollRef]);
132 + // Typing into the topbar search narrows the list, and a short enough list un-scrolls the
133 + // page — which dissolves the condensed topbar and unmounts the very input being typed in.
134 + const topbarSearchFocusedRef = useRef(false);
135 + const inFlowSearchRef = useRef<HTMLDivElement | null>(null);
136 + const [searchOpen, setSearchOpen] = useState(false);
137 + const [searchFocusToken, setSearchFocusToken] = useState(0);
138 + const searchExpanded = searchOpen || searchValue.length > 0;
139 + useEffect(() => {
140 + const onKeyDown = (event: KeyboardEvent) => {
141 + if (event.defaultPrevented) return;
142 + if (event.key.toLowerCase() !== "f" || !(event.metaKey || event.ctrlKey)) return;
143 + if (event.altKey || event.shiftKey) return;
144 + event.preventDefault();
145 + if (condensed) {
146 + setSearchOpen(true);
147 + setSearchFocusToken((token) => token + 1);
148 + return;
149 + }
150 + const input = inFlowSearchRef.current?.querySelector("input");
151 + input?.focus();
152 + input?.select();
153 + };
154 + window.addEventListener("keydown", onKeyDown);
155 + return () => window.removeEventListener("keydown", onKeyDown);
156 + }, [condensed]);
157 + if (!condensed && searchOpen) setSearchOpen(false);
158 + useEffect(() => {
159 + if (condensed) return;
160 + if (!topbarSearchFocusedRef.current) return;
161 + topbarSearchFocusedRef.current = false;
162 + const input = inFlowSearchRef.current?.querySelector("input");
163 + if (!input) return;
164 + input.focus();
165 + input.setSelectionRange(input.value.length, input.value.length);
166 + }, [condensed]);
167 +
168 + return (
169 + <div
170 + className={cn(
171 + "@container/pr-list flex min-h-0 min-w-0 flex-col overflow-x-hidden bg-background",
172 + maximizedAway ? "w-0 flex-none" : "flex-1",
173 + )}
174 + >
175 + <WorkspacePageHeader
176 + electron={isElectron}
177 + reserveNativeControls={!rightPanelOpen}
178 + className="relative bg-background"
179 + >
180 + {titlebarControls}
181 + {condensed ? (
182 + <WorkspaceBreadcrumb ariaLabel="Pull request scope" className="overflow-hidden">
183 + <WorkspaceBreadcrumbItem current className={cn(searchExpanded && "sr-only")}>
184 + <h1 className="truncate">Pull Requests</h1>
185 + </WorkspaceBreadcrumbItem>
186 + {searchExpanded ? null : <WorkspaceBreadcrumbSeparator />}
187 + <WorkspaceBreadcrumbItem className="shrink gap-1.5">
188 + <PullRequestCompactFilterMenu
189 + label="Filter by state"
190 + value={state}
191 + options={STATE_TABS}
192 + onChange={onState}
193 + className="shrink-0"
194 + />
195 + <PullRequestCompactFilterMenu
196 + label="Filter by involvement"
197 + value={involvement}
198 + options={INVOLVEMENT_TABS}
199 + onChange={onInvolvement}
200 + />
201 + {hostMenuOptions.length > 2 ? (
202 + <PullRequestCompactFilterMenu
203 + label="Filter by host"
204 + value={host ?? ""}
205 + options={hostMenuOptions}
206 + onChange={(next) => onHost(next === "" ? undefined : next)}
207 + />
208 + ) : null}
209 + </WorkspaceBreadcrumbItem>
210 + </WorkspaceBreadcrumb>
211 + ) : (
212 + <WorkspaceBreadcrumb ariaLabel="Pull requests breadcrumb">
213 + <WorkspaceBreadcrumbItem current>
214 + <h1 className="truncate">Pull Requests</h1>
215 + </WorkspaceBreadcrumbItem>
216 + </WorkspaceBreadcrumb>
217 + )}
218 + <div className="min-w-0 flex-1" />
219 + {condensed ? (
220 + <div className="flex shrink items-center gap-1.5">
221 + <ExpandableSearch
222 + searchInput={searchInput}
223 + searchValue={searchValue}
224 + open={searchOpen}
225 + onOpenChange={setSearchOpen}
226 + focusToken={searchFocusToken}
227 + onFocusWithin={(focused) => {
228 + topbarSearchFocusedRef.current = focused;
229 + }}
230 + />
231 + <PullRequestRefreshControl compact refreshing={refreshing} onRefresh={onRefresh} />
232 + </div>
233 + ) : null}
234 + {rightPanelControl}
235 + </WorkspacePageHeader>
236 +
237 + <div
238 + ref={scrollRef}
239 + className="topbar-scroll-fade scrollbar-gutter-both min-h-0 flex-1 overflow-y-auto"
240 + >
241 + <WorkspacePageContainer width="expanded" className="min-h-full gap-4">
242 + <div className="flex flex-col gap-3">
243 + <div ref={inFlowSearchRef} className="flex flex-wrap items-center gap-2">
244 + <div className="min-w-0 basis-full @lg/pr-list:basis-0 @lg/pr-list:flex-1">
245 + {searchInput}
246 + </div>
247 + {sortMenu}
248 + {filtersMenu}
249 + <PullRequestCompactFilterMenu
250 + label="Filter by provider"
251 + outlined
252 + iconOnly={host !== undefined}
253 + triggerIcon={<Plug2Icon aria-hidden className="size-4" />}
254 + triggerLabel="All"
255 + value={host ?? ""}
256 + options={hostMenuOptions}
257 + onChange={(next) => onHost(next === "" ? undefined : next)}
258 + />
259 + {!condensed ? (
260 + <PullRequestRefreshControl refreshing={refreshing} onRefresh={onRefresh} />
261 + ) : null}
262 + </div>
263 + <div ref={markerRef} aria-hidden className="-mt-3 h-px w-full" />
264 + </div>
265 +
266 + {listBody}
267 + </WorkspacePageContainer>
268 + </div>
269 + </div>
270 + );
271 +}
272 +
273 +function PullRequestRefreshControl({
274 + compact = false,
275 + refreshing,
276 + onRefresh,
277 +}: {
278 + compact?: boolean;
279 + refreshing: boolean;
280 + onRefresh: () => void;
281 +}) {
282 + return (
283 + <Button
284 + size={compact ? "icon-sm" : "icon"}
285 + variant={compact ? "ghost" : "outline"}
286 + aria-label="Refresh pull requests"
287 + onClick={onRefresh}
288 + disabled={refreshing}
289 + >
290 + <RefreshIcon size="md" refreshing={refreshing} />
291 + </Button>
292 + );
293 +}
apps/web/src/components/pullRequest/pullRequestListOptions.ts new
+40
@@ -0,0 +1,40 @@
1 +import type { PullRequestInvolvement, PullRequestListState } from "@t3tools/contracts";
2 +import {
3 + CalendarArrowDownIcon,
4 + CalendarArrowUpIcon,
5 + ClockIcon,
6 + EyeIcon,
7 + LayersIcon,
8 + ListChecksIcon,
9 + Maximize2Icon,
10 + Minimize2Icon,
11 + PenLineIcon,
12 + UserLockIcon,
13 +} from "lucide-react";
14 +
15 +import type { PullRequestFilterOption } from "./PullRequestListFilters";
16 +import type { PullRequestListSort } from "./pullRequestListPreferences";
17 +import { PullRequestGlyph } from "./pullRequestIcons";
18 +
19 +export const INVOLVEMENT_TABS = [
20 + { value: "all", label: "All", Icon: LayersIcon },
21 + { value: "reviewing", label: "Reviewing", Icon: EyeIcon },
22 + { value: "authored", label: "Authored", Icon: PenLineIcon },
23 +] as const satisfies ReadonlyArray<PullRequestFilterOption<PullRequestInvolvement>>;
24 +
25 +export const STATE_TABS = [
26 + { value: "all", label: "All", Icon: LayersIcon },
27 + { value: "open", label: "Open", Icon: PullRequestGlyph.pullRequest },
28 + { value: "closed", label: "Closed", Icon: PullRequestGlyph.closed },
29 + { value: "merged", label: "Merged", Icon: PullRequestGlyph.merged },
30 +] as const satisfies ReadonlyArray<PullRequestFilterOption<PullRequestListState>>;
31 +
32 +export const SORT_OPTIONS = [
33 + { value: "ready", label: "Merge readiness", Icon: ListChecksIcon },
34 + { value: "blocked", label: "Blocked on me", Icon: UserLockIcon },
35 + { value: "updated", label: "Recently updated", Icon: ClockIcon },
36 + { value: "newest", label: "Newest shown", Icon: CalendarArrowDownIcon },
37 + { value: "oldest", label: "Oldest shown", Icon: CalendarArrowUpIcon },
38 + { value: "largest", label: "Largest shown", Icon: Maximize2Icon },
39 + { value: "smallest", label: "Smallest shown", Icon: Minimize2Icon },
40 +] as const satisfies ReadonlyArray<PullRequestFilterOption<PullRequestListSort>>;
apps/web/src/routes/_chat.pull-requests.tsx
+9 -411
@@ -2,7 +2,6 @@ import {
2 applyPullRequestDraftFilterChange,
3 parsePullRequestQuery,
4 } from "@t3tools/client-runtime/pull-request-query";
5 -import { RefreshIcon } from "~/components/ui/refresh-icon";
5 import { Spinner } from "~/components/ui/spinner";
6 import { useShortcutModifierState } from "~/shortcutModifierState";
7 import type { PullRequestSpeedActionResult } from "~/components/pullRequest/PullRequestSpeedActions";
@@ -27,31 +26,14 @@ import { useAtomValue } from "@effect/atom-react";
26 import { createFileRoute, useNavigate } from "@tanstack/react-router";
27 import {
28 ArrowDownUpIcon,
30 - CalendarArrowDownIcon,
31 - CalendarArrowUpIcon,
32 - ChevronDownIcon,
33 - ClockIcon,
29 EyeIcon,
30 LayersIcon,
36 - ListChecksIcon,
31 PenLineIcon,
32 UsersIcon,
33 Plug2Icon,
40 - Maximize2Icon,
41 - Minimize2Icon,
42 - SearchIcon,
43 - UserLockIcon,
34 type LucideIcon,
35 } from "lucide-react";
46 -import {
47 - useEffect,
48 - useEffectEvent,
49 - useRef,
50 - useState,
51 - type ComponentProps,
52 - type ReactNode,
53 - type RefObject,
54 -} from "react";
36 +import { useEffect, useEffectEvent, useRef, useState, type ComponentProps } from "react";
37
38 import {
39 filterPullRequestsByInvolvement,
@@ -109,13 +91,19 @@ import { environmentMachineIcon } from "../components/EnvironmentMachineIcon";
91 import { PullRequestDetailPanel } from "../components/pullRequest/PullRequestDetailPanel";
92 import {
93 PullRequestFiltersMenu,
112 - PullRequestFilterOptionIcon,
94 PullRequestSearchInput,
95 pullRequestHostLabel,
96 pullRequestProjectKey,
97 type PullRequestExpectedHost,
98 type PullRequestFilterOption,
99 } from "../components/pullRequest/PullRequestListFilters";
100 +import { PullRequestCompactFilterMenu } from "../components/pullRequest/PullRequestCompactFilterMenu";
101 +import {
102 + INVOLVEMENT_TABS,
103 + SORT_OPTIONS,
104 + STATE_TABS,
105 +} from "../components/pullRequest/pullRequestListOptions";
106 +import { PullRequestsColumn } from "../components/pullRequest/PullRequestsColumn";
107 import { PullRequestListEmptyState } from "../components/pullRequest/PullRequestListEmptyState";
108 import { PullRequestListGhost } from "../components/pullRequest/PullRequestGhosts";
109 import {
@@ -124,13 +112,6 @@ import {
112 } from "../components/pullRequest/PullRequestRow";
113 import { PullRequestsUnavailableState } from "../components/pullRequest/PullRequestsUnavailableState";
114 import { RightPanelTabs, type PullRequestTabStatusSeed } from "../components/RightPanelTabs";
127 -import {
128 - WorkspaceBreadcrumb,
129 - WorkspaceBreadcrumbItem,
130 - WorkspaceBreadcrumbSeparator,
131 -} from "../components/WorkspaceBreadcrumb";
132 -import { WorkspacePageContainer } from "../components/WorkspacePageContainer";
133 -import { WorkspacePageHeader } from "../components/WorkspacePageHeader";
115 import { isCommandPaletteOpen } from "../commandPaletteBus";
116 import { isElectron } from "../env";
117 import { resolveShortcutCommand, shortcutLabelForCommand } from "../keybindings";
@@ -140,9 +121,7 @@ import {
121 RightPanelMaximizeControl,
122 } from "../components/chat/PanelLayoutControls";
123 import { Button } from "../components/ui/button";
143 -import { Menu, MenuPopup, MenuRadioGroup, MenuRadioItem, MenuTrigger } from "../components/ui/menu";
124 import { SidebarInset } from "../components/ui/sidebar";
145 -import { Tooltip, TooltipPopup, TooltipTrigger } from "../components/ui/tooltip";
125 import { useLiveRefresh } from "../hooks/useLiveRefresh";
126 import { useStableCallback } from "../hooks/useStableCallback";
127 import { useOpenPanelPullRequestUrl } from "../hooks/useOpenPanelPullRequestUrl";
@@ -175,7 +154,6 @@ import { cn } from "~/lib/utils";
154 import { Separator } from "~/components/ui/separator";
155 import { primaryServerKeybindingsAtom } from "~/state/server";
156 import { getSourceControlPresentationForKind } from "~/sourceControlPresentation";
178 -import { PullRequestGlyph } from "~/components/pullRequest/pullRequestIcons";
157
158 function getShortcutContext() {
159 return {
@@ -222,29 +200,6 @@ function PullRequestGroupHeader({
200 );
201 }
202
225 -const INVOLVEMENT_TABS = [
226 - { value: "all", label: "All", Icon: LayersIcon },
227 - { value: "reviewing", label: "Reviewing", Icon: EyeIcon },
228 - { value: "authored", label: "Authored", Icon: PenLineIcon },
229 -] as const satisfies ReadonlyArray<PullRequestFilterOption<PullRequestInvolvement>>;
230 -
231 -const STATE_TABS = [
232 - { value: "all", label: "All", Icon: LayersIcon },
233 - { value: "open", label: "Open", Icon: PullRequestGlyph.pullRequest },
234 - { value: "closed", label: "Closed", Icon: PullRequestGlyph.closed },
235 - { value: "merged", label: "Merged", Icon: PullRequestGlyph.merged },
236 -] as const satisfies ReadonlyArray<PullRequestFilterOption<PullRequestListState>>;
237 -
238 -const SORT_OPTIONS = [
239 - { value: "ready", label: "Merge readiness", Icon: ListChecksIcon },
240 - { value: "blocked", label: "Blocked on me", Icon: UserLockIcon },
241 - { value: "updated", label: "Recently updated", Icon: ClockIcon },
242 - { value: "newest", label: "Newest shown", Icon: CalendarArrowDownIcon },
243 - { value: "oldest", label: "Oldest shown", Icon: CalendarArrowUpIcon },
244 - { value: "largest", label: "Largest shown", Icon: Maximize2Icon },
245 - { value: "smallest", label: "Smallest shown", Icon: Minimize2Icon },
246 -] as const satisfies ReadonlyArray<PullRequestFilterOption<PullRequestListSort>>;
247 -
203 const SEARCH_DEBOUNCE_MS = 250;
204 const MATCHED_ELSEWHERE_SCORE = 10;
205 /**
@@ -1445,7 +1400,7 @@ function PullRequestsRouteView() {
1400 })),
1401 ];
1402 const sortMenu = (
1448 - <CompactFilterMenu
1403 + <PullRequestCompactFilterMenu
1404 label="Sort pull requests"
1405 triggerIcon={<ArrowDownUpIcon aria-hidden className="size-4" />}
1406 triggerLabel="Sort"
@@ -2143,360 +2098,3 @@ function PullRequestFiltersMenuInSidebarOrder(
2098 const projects = sortProjectsByGroupOrder(props.projects, sidebarProjectGroups);
2099 return <PullRequestFiltersMenu {...props} projects={projects} />;
2100 }
2146 -
2147 -function CompactFilterMenu<Value extends string>({
2148 - label,
2149 - triggerIcon,
2150 - triggerLabel,
2151 - outlined = false,
2152 - iconOnly = false,
2153 - value,
2154 - options,
2155 - onChange,
2156 - className,
2157 -}: {
2158 - label: string;
2159 - triggerIcon?: ReactNode;
2160 - triggerLabel?: string;
2161 - outlined?: boolean;
2162 - iconOnly?: boolean;
2163 - value: Value;
2164 - options: ReadonlyArray<PullRequestFilterOption<Value>>;
2165 - onChange: (value: Value) => void;
2166 - className?: string;
2167 -}) {
2168 - const current = options.find((option) => option.value === value) ?? options[0];
2169 - if (!current) return null;
2170 - return (
2171 - <Menu>
2172 - <MenuTrigger
2173 - aria-label={triggerLabel || iconOnly ? `${label}: ${current.label}` : label}
2174 - title={iconOnly ? `${label}: ${current.label}` : undefined}
2175 - render={
2176 - outlined ? (
2177 - <Button variant="outline" size={iconOnly ? "icon" : "default"} />
2178 - ) : (
2179 - <Button variant="ghost-muted" size="sm" />
2180 - )
2181 - }
2182 - className={cn("min-w-0", className)}
2183 - >
2184 - {iconOnly ? (
2185 - <current.Icon aria-hidden className="size-4" />
2186 - ) : triggerLabel ? (
2187 - <>
2188 - {triggerIcon}
2189 - <span>{triggerLabel}</span>
2190 - </>
2191 - ) : (
2192 - <>
2193 - <span className="truncate">{current.label}</span>
2194 - <ChevronDownIcon aria-hidden className="size-3 shrink-0 text-muted-foreground/70" />
2195 - </>
2196 - )}
2197 - </MenuTrigger>
2198 - <MenuPopup align="start" side="bottom">
2199 - <MenuRadioGroup value={value} onValueChange={(next) => onChange(next as Value)}>
2200 - {options.map((option) => {
2201 - const item = (
2202 - <MenuRadioItem
2203 - key={option.value}
2204 - value={option.value}
2205 - disabled={option.unavailable !== undefined}
2206 - className="data-disabled:pointer-events-auto"
2207 - >
2208 - <span className="flex min-w-0 items-center gap-2">
2209 - <PullRequestFilterOptionIcon option={option} />
2210 - {option.label}
2211 - </span>
2212 - </MenuRadioItem>
2213 - );
2214 - return option.unavailable === undefined ? (
2215 - item
2216 - ) : (
2217 - <Tooltip key={option.value}>
2218 - <TooltipTrigger render={item} />
2219 - <TooltipPopup side="right">{option.unavailable}</TooltipPopup>
2220 - </Tooltip>
2221 - );
2222 - })}
2223 - </MenuRadioGroup>
2224 - </MenuPopup>
2225 - </Menu>
2226 - );
2227 -}
2228 -
2229 -function ExpandableSearch({
2230 - searchInput,
2231 - searchValue,
2232 - open,
2233 - onOpenChange,
2234 - focusToken,
2235 - onFocusWithin,
2236 -}: {
2237 - searchInput: ReactNode;
2238 - searchValue: string;
2239 - open: boolean;
2240 - onOpenChange: (open: boolean) => void;
2241 - focusToken: number;
2242 - /**
2243 - * An unmount fires no blur, which is the point: whoever unmounted this can still see the reader
2244 - * was mid-typing and move the focus somewhere that continues the sentence.
2245 - */
2246 - onFocusWithin?: (focused: boolean) => void;
2247 -}) {
2248 - const containerRef = useRef<HTMLDivElement | null>(null);
2249 - useEffect(() => {
2250 - if (!open) return;
2251 - containerRef.current?.querySelector("input")?.focus();
2252 - }, [open]);
2253 - const appliedFocusToken = useRef(focusToken);
2254 - useEffect(() => {
2255 - if (appliedFocusToken.current === focusToken) return;
2256 - appliedFocusToken.current = focusToken;
2257 - const input = containerRef.current?.querySelector("input");
2258 - input?.focus();
2259 - input?.select();
2260 - }, [focusToken]);
2261 - if (open || searchValue.length > 0) {
2262 - return (
2263 - <div
2264 - ref={containerRef}
2265 - className="w-56 min-w-24 shrink"
2266 - onFocus={() => onFocusWithin?.(true)}
2267 - onBlur={() => {
2268 - onFocusWithin?.(false);
2269 - if (searchValue.length === 0) onOpenChange(false);
2270 - }}
2271 - >
2272 - {searchInput}
2273 - </div>
2274 - );
2275 - }
2276 - return (
2277 - <Button
2278 - size="icon-sm"
2279 - variant="ghost"
2280 - aria-label="Search pull requests"
2281 - onClick={() => onOpenChange(true)}
2282 - >
2283 - <SearchIcon className="size-4" />
2284 - </Button>
2285 - );
2286 -}
2287 -
2288 -function PullRequestsColumn({
2289 - refreshing,
2290 - onRefresh,
2291 - searchValue,
2292 - involvement,
2293 - state,
2294 - host,
2295 - hostMenuOptions,
2296 - onInvolvement,
2297 - onState,
2298 - onHost,
2299 - searchInput,
2300 - sortMenu,
2301 - filtersMenu,
2302 - rightPanelControl,
2303 - titlebarControls,
2304 - rightPanelOpen,
2305 - maximizedAway,
2306 - listBody,
2307 - scrollRef,
2308 -}: {
2309 - refreshing: boolean;
2310 - onRefresh: () => void;
2311 - searchValue: string;
2312 - involvement: PullRequestInvolvement;
2313 - state: PullRequestListState;
2314 - host: string | undefined;
2315 - hostMenuOptions: ReadonlyArray<PullRequestFilterOption<string>>;
2316 - onInvolvement: (involvement: PullRequestInvolvement) => void;
2317 - onState: (state: PullRequestListState) => void;
2318 - onHost: (host: string | undefined) => void;
2319 - searchInput: ReactNode;
2320 - sortMenu: ReactNode;
2321 - filtersMenu: ReactNode;
2322 - rightPanelControl: ReactNode;
2323 - titlebarControls: ReactNode;
2324 - rightPanelOpen: boolean;
2325 - maximizedAway: boolean;
2326 - listBody: ReactNode;
2327 - scrollRef: RefObject<HTMLDivElement | null>;
2328 -}) {
2329 - const markerRef = useRef<HTMLDivElement | null>(null);
2330 - const [condensed, setCondensed] = useState(false);
2331 - useEffect(() => {
2332 - const marker = markerRef.current;
2333 - if (!marker) return;
2334 - const observer = new IntersectionObserver(
2335 - ([entry]) => setCondensed(entry ? !entry.isIntersecting : false),
2336 - { root: scrollRef.current },
2337 - );
2338 - observer.observe(marker);
2339 - return () => observer.disconnect();
2340 - }, [scrollRef]);
2341 - // Typing into the topbar search narrows the list, and a short enough list un-scrolls the
2342 - // page — which dissolves the condensed topbar and unmounts the very input being typed in.
2343 - const topbarSearchFocusedRef = useRef(false);
2344 - const inFlowSearchRef = useRef<HTMLDivElement | null>(null);
2345 - const [searchOpen, setSearchOpen] = useState(false);
2346 - const [searchFocusToken, setSearchFocusToken] = useState(0);
2347 - const searchExpanded = searchOpen || searchValue.length > 0;
2348 - useEffect(() => {
2349 - const onKeyDown = (event: KeyboardEvent) => {
2350 - if (event.defaultPrevented) return;
2351 - if (event.key.toLowerCase() !== "f" || !(event.metaKey || event.ctrlKey)) return;
2352 - if (event.altKey || event.shiftKey) return;
2353 - event.preventDefault();
2354 - if (condensed) {
2355 - setSearchOpen(true);
2356 - setSearchFocusToken((token) => token + 1);
2357 - return;
2358 - }
2359 - const input = inFlowSearchRef.current?.querySelector("input");
2360 - input?.focus();
2361 - input?.select();
2362 - };
2363 - window.addEventListener("keydown", onKeyDown);
2364 - return () => window.removeEventListener("keydown", onKeyDown);
2365 - }, [condensed]);
2366 - if (!condensed && searchOpen) setSearchOpen(false);
2367 - useEffect(() => {
2368 - if (condensed) return;
2369 - if (!topbarSearchFocusedRef.current) return;
2370 - topbarSearchFocusedRef.current = false;
2371 - const input = inFlowSearchRef.current?.querySelector("input");
2372 - if (!input) return;
2373 - input.focus();
2374 - input.setSelectionRange(input.value.length, input.value.length);
2375 - }, [condensed]);
2376 -
2377 - return (
2378 - <div
2379 - className={cn(
2380 - "@container/pr-list flex min-h-0 min-w-0 flex-col overflow-x-hidden bg-background",
2381 - maximizedAway ? "w-0 flex-none" : "flex-1",
2382 - )}
2383 - >
2384 - <WorkspacePageHeader
2385 - electron={isElectron}
2386 - reserveNativeControls={!rightPanelOpen}
2387 - className="relative bg-background"
2388 - >
2389 - {titlebarControls}
2390 - {condensed ? (
2391 - <WorkspaceBreadcrumb ariaLabel="Pull request scope" className="overflow-hidden">
2392 - <WorkspaceBreadcrumbItem current className={cn(searchExpanded && "sr-only")}>
2393 - <h1 className="truncate">Pull Requests</h1>
2394 - </WorkspaceBreadcrumbItem>
2395 - {searchExpanded ? null : <WorkspaceBreadcrumbSeparator />}
2396 - <WorkspaceBreadcrumbItem className="shrink gap-1.5">
2397 - <CompactFilterMenu
2398 - label="Filter by state"
2399 - value={state}
2400 - options={STATE_TABS}
2401 - onChange={onState}
2402 - className="shrink-0"
2403 - />
2404 - <CompactFilterMenu
2405 - label="Filter by involvement"
2406 - value={involvement}
2407 - options={INVOLVEMENT_TABS}
2408 - onChange={onInvolvement}
2409 - />
2410 - {hostMenuOptions.length > 2 ? (
2411 - <CompactFilterMenu
2412 - label="Filter by host"
2413 - value={host ?? ""}
2414 - options={hostMenuOptions}
2415 - onChange={(next) => onHost(next === "" ? undefined : next)}
2416 - />
2417 - ) : null}
2418 - </WorkspaceBreadcrumbItem>
2419 - </WorkspaceBreadcrumb>
2420 - ) : (
2421 - <WorkspaceBreadcrumb ariaLabel="Pull requests breadcrumb">
2422 - <WorkspaceBreadcrumbItem current>
2423 - <h1 className="truncate">Pull Requests</h1>
2424 - </WorkspaceBreadcrumbItem>
2425 - </WorkspaceBreadcrumb>
2426 - )}
2427 - <div className="min-w-0 flex-1" />
2428 - {condensed ? (
2429 - <div className="flex shrink items-center gap-1.5">
2430 - <ExpandableSearch
2431 - searchInput={searchInput}
2432 - searchValue={searchValue}
2433 - open={searchOpen}
2434 - onOpenChange={setSearchOpen}
2435 - focusToken={searchFocusToken}
2436 - onFocusWithin={(focused) => {
2437 - topbarSearchFocusedRef.current = focused;
2438 - }}
2439 - />
2440 - <PullRequestRefreshControl compact refreshing={refreshing} onRefresh={onRefresh} />
2441 - </div>
2442 - ) : null}
2443 - {rightPanelControl}
2444 - </WorkspacePageHeader>
2445 -
2446 - <div
2447 - ref={scrollRef}
2448 - className="topbar-scroll-fade scrollbar-gutter-both min-h-0 flex-1 overflow-y-auto"
2449 - >
2450 - <WorkspacePageContainer width="expanded" className="min-h-full gap-4">
2451 - <div className="flex flex-col gap-3">
2452 - <div ref={inFlowSearchRef} className="flex flex-wrap items-center gap-2">
2453 - <div className="min-w-0 basis-full @lg/pr-list:basis-0 @lg/pr-list:flex-1">
2454 - {searchInput}
2455 - </div>
2456 - {sortMenu}
2457 - {filtersMenu}
2458 - <CompactFilterMenu
2459 - label="Filter by provider"
2460 - outlined
2461 - iconOnly={host !== undefined}
2462 - triggerIcon={<Plug2Icon aria-hidden className="size-4" />}
2463 - triggerLabel="All"
2464 - value={host ?? ""}
2465 - options={hostMenuOptions}
2466 - onChange={(next) => onHost(next === "" ? undefined : next)}
2467 - />
2468 - {!condensed ? (
2469 - <PullRequestRefreshControl refreshing={refreshing} onRefresh={onRefresh} />
2470 - ) : null}
2471 - </div>
2472 - <div ref={markerRef} aria-hidden className="-mt-3 h-px w-full" />
2473 - </div>
2474 -
2475 - {listBody}
2476 - </WorkspacePageContainer>
2477 - </div>
2478 - </div>
2479 - );
2480 -}
2481 -
2482 -function PullRequestRefreshControl({
2483 - compact = false,
2484 - refreshing,
2485 - onRefresh,
2486 -}: {
2487 - compact?: boolean;
2488 - refreshing: boolean;
2489 - onRefresh: () => void;
2490 -}) {
2491 - return (
2492 - <Button
2493 - size={compact ? "icon-sm" : "icon"}
2494 - variant={compact ? "ghost" : "outline"}
2495 - aria-label="Refresh pull requests"
2496 - onClick={onRefresh}
2497 - disabled={refreshing}
2498 - >
2499 - <RefreshIcon size="md" refreshing={refreshing} />
2500 - </Button>
2501 - );
2502 -}