Skip to content

Commit 21f44fb

Browse files
t3dotggclaude
andcommitted
feat(web): sidebar cards list a thread's PR numbers, open ones first
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent ca0964d commit 21f44fb

5 files changed

Lines changed: 126 additions & 7 deletions

File tree

‎apps/web/src/components/ThreadStatusIndicators.tsx‎

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ import {
2626
resolveThreadPullRequestBadge,
2727
resolveThreadPullRequestChains,
2828
type ThreadPullRequestBadge,
29+
threadPullRequestsOpenFirst,
2930
visibleThreadPullRequests,
3031
} from "@t3tools/client-runtime/thread-pull-requests";
3132
import { useRender } from "@base-ui/react/use-render";
33+
import { InlineButton } from "./ui/button";
3234
import { type ReactNode, type AnimationEvent, type MouseEvent, type ReactElement } from "react";
3335
import { cn } from "../lib/utils";
3436
import { revealThreadTerminal } from "../lib/revealThreadTerminal";
@@ -242,6 +244,80 @@ export function ThreadPullRequestBadgeControl({
242244
);
243245
}
244246

247+
const SHOWN_PULL_REQUEST_NUMBERS = 2;
248+
249+
/** Compact form for threads with several PRs: the first numbers, then a count that opens the list. */
250+
export function ThreadPullRequestNumbers({
251+
badge,
252+
pullRequests,
253+
onOpenList,
254+
onOpenPullRequest,
255+
}: {
256+
badge: ThreadPullRequestBadge;
257+
pullRequests: ReadonlyArray<ThreadPullRequestLink>;
258+
onOpenList: () => void;
259+
onOpenPullRequest: (event: MouseEvent<HTMLElement>, url: string) => void;
260+
}) {
261+
const ordered = threadPullRequestsOpenFirst(pullRequests);
262+
const shown = ordered.slice(0, SHOWN_PULL_REQUEST_NUMBERS);
263+
const hidden = ordered.length - shown.length;
264+
const aggregate = PULL_REQUEST_STATE_PRESENTATION[badge.state];
265+
const Icon = badge.kind === "stack" ? PullRequestGlyph.stack : aggregate.Icon;
266+
const terminology = changeRequestTerminologyForUrl(shown[0]?.url);
267+
return (
268+
<span className="flex min-w-0 items-center gap-1 text-xs tabular-nums">
269+
<Icon aria-hidden className={cn("size-3 shrink-0", aggregate.toneClassName)} />
270+
{shown.map((link) => {
271+
const state =
272+
link.snapshot === null
273+
? null
274+
: resolvePullRequestState({
275+
state: link.snapshot.state,
276+
isDraft: link.snapshot.isDraft,
277+
});
278+
return (
279+
<InlineButton
280+
key={link.url}
281+
render={<a href={link.url} target="_blank" rel="noopener noreferrer" />}
282+
aria-label={[
283+
`${terminology.shortLabel} #${link.number}`,
284+
state?.label,
285+
link.snapshot?.title,
286+
]
287+
.filter(Boolean)
288+
.join(", ")}
289+
onPointerDown={(event: MouseEvent<HTMLElement>) => event.stopPropagation()}
290+
onClick={(event: MouseEvent<HTMLElement>) => onOpenPullRequest(event, link.url)}
291+
>
292+
<span
293+
className={cn(
294+
"contents font-normal",
295+
state?.toneClassName ?? "text-muted-foreground",
296+
)}
297+
>
298+
{link.number}
299+
</span>
300+
</InlineButton>
301+
);
302+
})}
303+
{hidden > 0 ? (
304+
<InlineButton
305+
tone="muted"
306+
aria-label={`Show all ${ordered.length} ${terminology.plural}`}
307+
onPointerDown={(event: MouseEvent<HTMLElement>) => event.stopPropagation()}
308+
onClick={(event: MouseEvent<HTMLElement>) => {
309+
event.preventDefault();
310+
event.stopPropagation();
311+
onOpenList();
312+
}}
313+
>
314+
<span className="contents font-normal">+{hidden}</span>
315+
</InlineButton>
316+
) : null}
317+
</span>
318+
);
319+
}
320+
245321
function PullRequestBadge({
246322
render,
247323
presentation,

‎apps/web/src/components/sidebar/SidebarThreadRow.tsx‎

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ import {
8989
import { resolveLocalCheckoutBranchMismatch } from "../BranchToolbar.logic";
9090
import {
9191
ThreadPullRequestBadgeControl,
92+
ThreadPullRequestNumbers,
9293
ThreadPullRequestsMiniList,
9394
prStatusIndicator,
9495
resolveThreadPullRequestBadge,
@@ -884,14 +885,16 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
884885
// Closing here, not just masking, keeps the menu from reopening when the button returns.
885886
if (snoozeMenuOpenRaw && !showSnoozeButton) setSnoozeMenuOpen(false);
886887
const snoozeMenuOpen = snoozeMenuOpenRaw && showSnoozeButton;
888+
const openPr = (event: ReactMouseEvent<HTMLElement>, url: string, inRightPanel: boolean) => {
889+
const openedInRightPanel = openPrLink(event, url, inRightPanel ? threadRef : undefined);
890+
if (openedInRightPanel && inRightPanel && !props.isRouteThread) {
891+
onThreadActivate(threadRef);
892+
}
893+
};
887894
const handlePrClick = (event: ReactMouseEvent<HTMLElement>, targetUrl?: string) => {
888895
const url = targetUrl ?? pr?.url ?? currentLinkedPr?.url;
889896
if (!url) return;
890-
const showInRightPanel = targetUrl !== undefined || openPullRequestsInRightPanel;
891-
const openedInRightPanel = openPrLink(event, url, showInRightPanel ? threadRef : undefined);
892-
if (openedInRightPanel && showInRightPanel && !props.isRouteThread) {
893-
onThreadActivate(threadRef);
894-
}
897+
openPr(event, url, targetUrl !== undefined || openPullRequestsInRightPanel);
895898
};
896899

897900
const rowSurfaceClassName = cn(
@@ -1024,6 +1027,17 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
10241027
onOpenPullRequest={handlePrClick}
10251028
/>
10261029
) : null;
1030+
const cardPrBadge =
1031+
prBadgeShape !== null && (prBadgeShape.kind === "stack" || prBadgeShape.others > 0) ? (
1032+
<ThreadPullRequestNumbers
1033+
badge={prBadgeShape}
1034+
pullRequests={thread.pullRequests}
1035+
onOpenList={handlePrListClick}
1036+
onOpenPullRequest={(event, url) => openPr(event, url, openPullRequestsInRightPanel)}
1037+
/>
1038+
) : (
1039+
prBadge
1040+
);
10271041
const terminalStatusIcon = (
10281042
<ThreadTerminalStatusButton
10291043
threadRef={threadRef}
@@ -1443,8 +1457,8 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
14431457
</div>
14441458
<div className="mt-0.5 flex min-w-0 items-center gap-1.5 text-secondary-label text-xs">
14451459
{/* The PR takes the branch's slot; the hover card still shows the branch. */}
1446-
{prBadge ? (
1447-
prBadge
1460+
{cardPrBadge ? (
1461+
cardPrBadge
14481462
) : thread.branch ? (
14491463
<span className="flex min-w-0 flex-1 text-muted-foreground/40">
14501464
<MiddleTruncate value={thread.branch} showTitle={false} />

‎packages/client-runtime/src/threadPullRequests.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
resolveThreadPullRequestChains,
1313
resolveThreadPullRequestBadge,
1414
threadPullRequestKeysEqual,
15+
threadPullRequestsOpenFirst,
1516
} from "./threadPullRequests.ts";
1617

1718
// Remove ES2023 array methods to match Hermes on mobile.
@@ -432,6 +433,20 @@ describe("threadPullRequestSearchTerms", () => {
432433
});
433434
});
434435

436+
describe("threadPullRequestsOpenFirst", () => {
437+
it("puts open links first, newest first, and drops dismissed links", () => {
438+
const at = (updatedAt: string) => ({ updatedAt: `2026-01-0${updatedAt}T00:00:00.000Z` });
439+
const ordered = threadPullRequestsOpenFirst([
440+
link(1, { snapshot: snapshot({ state: "merged", ...at("9") }) }),
441+
link(2, { snapshot: snapshot(at("2")) }),
442+
link(3, { snapshot: snapshot({ state: "closed", ...at("3") }) }),
443+
link(4, { snapshot: snapshot({ isDraft: true, ...at("4") }) }),
444+
link(5, { source: "stack-dismissed", snapshot: snapshot(at("8")) }),
445+
]);
446+
expect(ordered.map((entry) => entry.number)).toEqual([4, 2, 1, 3]);
447+
});
448+
});
449+
435450
it("searches the legacy projection when old environments decode to an empty links list", () => {
436451
const linkedPullRequest = {
437452
projectId: ProjectId.make("project"),

‎packages/client-runtime/src/threadPullRequests.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { sourceControlClients } from "./sourceControlClients.ts";
44

55
export {
66
threadPullRequestSearchTerms,
7+
threadPullRequestsOpenFirst,
78
visibleThreadPullRequests,
89
} from "@t3tools/shared/threadPullRequests";
910
export {

‎packages/shared/src/threadPullRequests.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,19 @@ function latestUpdatedAt(link: ThreadPullRequestLink): number {
1313
return Number.isNaN(ms) ? 0 : ms;
1414
}
1515

16+
/** Visible links, open ones first, then most recently updated. */
17+
export function threadPullRequestsOpenFirst(
18+
links: ReadonlyArray<ThreadPullRequestLink>,
19+
): ReadonlyArray<ThreadPullRequestLink> {
20+
const isOpen = (link: ThreadPullRequestLink) =>
21+
link.snapshot === null || link.snapshot.state === "open";
22+
return [...visibleThreadPullRequests(links)].sort(
23+
(left, right) =>
24+
Number(isOpen(right)) - Number(isOpen(left)) ||
25+
latestUpdatedAt(right) - latestUpdatedAt(left),
26+
);
27+
}
28+
1629
export interface ThreadSearchPullRequest {
1730
readonly number: number;
1831
readonly title: string | null;

0 commit comments

Comments
 (0)