Skip to content

Commit e8f56f2

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 05e74da commit e8f56f2

5 files changed

Lines changed: 120 additions & 7 deletions

File tree

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

Lines changed: 69 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";
@@ -238,6 +240,73 @@ export function ThreadPullRequestBadgeControl({
238240
);
239241
}
240242

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

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

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ import {
9090
import { resolveLocalCheckoutBranchMismatch } from "../BranchToolbar.logic";
9191
import {
9292
ThreadPullRequestBadgeControl,
93+
ThreadPullRequestNumbers,
9394
ThreadPullRequestsMiniList,
9495
prStatusIndicator,
9596
resolveThreadPullRequestBadge,
@@ -902,14 +903,16 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
902903
// Closing here, not just masking, keeps the menu from reopening when the button returns.
903904
if (snoozeMenuOpenRaw && !showSnoozeButton) setSnoozeMenuOpen(false);
904905
const snoozeMenuOpen = snoozeMenuOpenRaw && showSnoozeButton;
906+
const openPr = (event: ReactMouseEvent<HTMLElement>, url: string, inRightPanel: boolean) => {
907+
const openedInRightPanel = openPrLink(event, url, inRightPanel ? threadRef : undefined);
908+
if (openedInRightPanel && inRightPanel && !props.isRouteThread) {
909+
onThreadActivate(threadRef);
910+
}
911+
};
905912
const handlePrClick = (event: ReactMouseEvent<HTMLElement>, targetUrl?: string) => {
906913
const url = targetUrl ?? pr?.url ?? currentLinkedPr?.url;
907914
if (!url) return;
908-
const showInRightPanel = targetUrl !== undefined || openPullRequestsInRightPanel;
909-
const openedInRightPanel = openPrLink(event, url, showInRightPanel ? threadRef : undefined);
910-
if (openedInRightPanel && showInRightPanel && !props.isRouteThread) {
911-
onThreadActivate(threadRef);
912-
}
915+
openPr(event, url, targetUrl !== undefined || openPullRequestsInRightPanel);
913916
};
914917

915918
const rowSurfaceClassName = cn(
@@ -1034,6 +1037,17 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
10341037
onOpenPullRequest={handlePrClick}
10351038
/>
10361039
) : null;
1040+
const cardPrBadge =
1041+
prBadgeShape !== null && (prBadgeShape.kind === "stack" || prBadgeShape.others > 0) ? (
1042+
<ThreadPullRequestNumbers
1043+
badge={prBadgeShape}
1044+
pullRequests={thread.pullRequests}
1045+
onOpenList={handlePrListClick}
1046+
onOpenPullRequest={(event, url) => openPr(event, url, openPullRequestsInRightPanel)}
1047+
/>
1048+
) : (
1049+
prBadge
1050+
);
10371051
const terminalStatusIcon = (
10381052
<ThreadTerminalStatusButton
10391053
threadRef={threadRef}
@@ -1474,8 +1488,8 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
14741488
{metaLineEmpty ? null : (
14751489
<div className="mt-0.5 flex min-w-0 items-center gap-1.5 text-secondary-label text-xs">
14761490
{/* The PR takes the branch's slot; the hover card still shows the branch. */}
1477-
{prBadge ? (
1478-
prBadge
1491+
{cardPrBadge ? (
1492+
cardPrBadge
14791493
) : thread.branch ? (
14801494
<span className="flex min-w-0 flex-1">
14811495
<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.
@@ -481,6 +482,20 @@ describe("threadPullRequestSearchTerms", () => {
481482
});
482483
});
483484

485+
describe("threadPullRequestsOpenFirst", () => {
486+
it("puts open links first, newest first, and drops dismissed links", () => {
487+
const at = (updatedAt: string) => ({ updatedAt: `2026-01-0${updatedAt}T00:00:00.000Z` });
488+
const ordered = threadPullRequestsOpenFirst([
489+
link(1, { snapshot: snapshot({ state: "merged", ...at("9") }) }),
490+
link(2, { snapshot: snapshot(at("2")) }),
491+
link(3, { snapshot: snapshot({ state: "closed", ...at("3") }) }),
492+
link(4, { snapshot: snapshot({ isDraft: true, ...at("4") }) }),
493+
link(5, { source: "stack-dismissed", snapshot: snapshot(at("8")) }),
494+
]);
495+
expect(ordered.map((entry) => entry.number)).toEqual([4, 2, 1, 3]);
496+
});
497+
});
498+
484499
it("searches the legacy projection when old environments decode to an empty links list", () => {
485500
const linkedPullRequest = {
486501
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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,20 @@ 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+
return visibleThreadPullRequests(links)
21+
.map((link) => ({
22+
link,
23+
open: link.snapshot === null || link.snapshot.state === "open" ? 1 : 0,
24+
updatedAt: latestUpdatedAt(link),
25+
}))
26+
.sort((left, right) => right.open - left.open || right.updatedAt - left.updatedAt)
27+
.map((entry) => entry.link);
28+
}
29+
1630
export interface ThreadSearchPullRequest {
1731
readonly number: number;
1832
readonly title: string | null;

0 commit comments

Comments
 (0)