Skip to content

Commit 5e61e63

Browse files
committed
fix(web): reuse pull request list data while loading
1 parent d5825e1 commit 5e61e63

3 files changed

Lines changed: 152 additions & 17 deletions

File tree

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
type EnvironmentId,
55
type PullRequestAction,
66
type PullRequestMergeMethod,
7+
type PullRequestListEntry,
78
type PullRequestUpdateMethod,
89
type PullRequestRef,
910
type PullRequestState,
@@ -447,6 +448,7 @@ export function PullRequestDetailPanel({
447448
environmentId,
448449
threadRef = null,
449450
reference,
451+
listEntry = null,
450452
refreshToken: forcedRefreshToken = 0,
451453
onActed,
452454
onClose,
@@ -463,6 +465,8 @@ export function PullRequestDetailPanel({
463465
*/
464466
threadRef?: ScopedThreadRef | null;
465467
reference: PullRequestRef;
468+
/** Row fields already loaded by the pull-request list, used while richer detail arrives. */
469+
listEntry?: PullRequestListEntry | null;
466470
/**
467471
* Bumped by whatever holds the panel when a reader asks for everything on screen to be read
468472
* again. The panel owns its own reads, so the page cannot refresh them for it — it says when,
@@ -491,6 +495,12 @@ export function PullRequestDetailPanel({
491495
composerDraftTarget?: ScopedThreadRef | DraftId;
492496
}) {
493497
const pullRequestKey = `${reference.projectId}:${reference.repository}#${reference.number}`;
498+
const matchingListEntry =
499+
listEntry?.projectId === reference.projectId &&
500+
listEntry.repository.toLowerCase() === reference.repository.toLowerCase() &&
501+
listEntry.number === reference.number
502+
? listEntry
503+
: null;
494504
const [tab, setTab] = useState<DetailTab>("summary");
495505
const [timelineOrder, setTimelineOrder] = useState<"newest" | "oldest">("newest");
496506
const [codeCommitScope, setCodeCommitScope] = useState<{
@@ -1296,10 +1306,10 @@ export function PullRequestDetailPanel({
12961306
).length
12971307
: 0;
12981308

1299-
// A reopen already has last time's title, author, and counts. Keep them on screen
1300-
// and let the live read replace fields — especially the diff counts — in place.
1309+
// The list already has the pull request's identity and summary. Keep them on screen
1310+
// and let the richer detail read replace the remaining placeholders in place.
13011311
if (detailQuery.isPending && !detail) {
1302-
return <PullRequestDetailGhost />;
1312+
return <PullRequestDetailGhost seed={matchingListEntry} />;
13031313
}
13041314

13051315
return (

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

Lines changed: 129 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,19 @@
77
* both themes) and the single `animate-skeleton` pulse, applied once on the container so any
88
* number of bars costs one opacity animation.
99
*/
10+
import type { PullRequestListEntry } from "@t3tools/contracts";
11+
import { ArrowLeftIcon } from "lucide-react";
12+
1013
import { cn } from "~/lib/utils";
14+
import { formatRelativeTimeLabel } from "~/timestampFormat";
15+
16+
import { pullRequestLabelColor } from "./pullRequestList.logic";
17+
import {
18+
PullRequestActorLabel,
19+
PullRequestDiffStat,
20+
pullRequestChecksStatePresentation,
21+
resolvePullRequestState,
22+
} from "./pullRequestPresentation";
1123

1224
function GhostBar({ className }: { className?: string | undefined }) {
1325
return <div aria-hidden className={cn("h-3 rounded bg-muted-foreground/15", className)} />;
@@ -60,18 +72,48 @@ export function PullRequestListGhost({
6072
* boundaries in the ghost prevents the loaded pull request from replacing one layout with
6173
* another a moment later.
6274
*/
63-
export function PullRequestDetailGhost() {
75+
export function PullRequestDetailGhost({ seed }: { seed?: PullRequestListEntry | null }) {
76+
const statePresentation = seed
77+
? resolvePullRequestState({
78+
state: seed.state,
79+
isDraft: seed.isDraft,
80+
mergeability: seed.mergeability,
81+
baseBranch: seed.baseBranch,
82+
})
83+
: null;
84+
const checksPresentation = seed?.checksState
85+
? pullRequestChecksStatePresentation(seed.checksState)
86+
: null;
87+
6488
return (
6589
<div
6690
role="status"
6791
aria-label="Loading pull request"
68-
className="motion-safe:animate-skeleton flex h-full min-h-0 flex-col overflow-hidden bg-background"
92+
className={cn(
93+
"flex h-full min-h-0 flex-col overflow-hidden bg-background",
94+
!seed && "motion-safe:animate-skeleton",
95+
)}
6996
>
7097
<div className="shrink-0 border-b border-border/60">
7198
<div className="flex h-7 items-center justify-between gap-3 px-4">
7299
<div className="flex min-w-0 flex-1 items-center gap-1.5">
73-
<GhostBar className="w-24" />
74-
<GhostBar className="w-9" />
100+
{seed && statePresentation ? (
101+
<>
102+
<span className="min-w-0 truncate text-xs font-medium text-muted-foreground">
103+
{seed.repository}
104+
</span>
105+
<span
106+
className={cn("shrink-0 text-xs font-medium", statePresentation.toneClassName)}
107+
>
108+
#{seed.number}
109+
</span>
110+
</>
111+
) : (
112+
<>
113+
<GhostBar className="w-24" />
114+
<GhostBar className="w-9" />
115+
</>
116+
)}
75117
</div>
76118
<div className="flex shrink-0 items-center gap-1">
77119
<GhostBar className="h-5 w-16 rounded-md" />
@@ -80,18 +122,58 @@ export function PullRequestDetailGhost() {
80122
</div>
81123

82124
<div className="px-4 pb-4 pt-1">
83-
<GhostBar className="h-5 w-4/5 max-w-md" />
125+
{seed ? (
126+
<h1 className="truncate text-base font-semibold leading-snug">{seed.title}</h1>
127+
) : (
128+
<GhostBar className="h-5 w-4/5 max-w-md" />
129+
)}
84130
<div className="mt-2 flex items-center gap-1.5">
85-
<GhostBar className="size-4 rounded-full" />
86-
<GhostBar className="w-24" />
131+
{seed ? (
132+
<>
133+
<PullRequestActorLabel
134+
actor={seed.author}
135+
className="font-medium"
136+
tooltip={false}
137+
/>
138+
<span className="text-xs text-muted-foreground">
139+
updated {formatRelativeTimeLabel(seed.updatedAt)}
140+
</span>
141+
</>
142+
) : (
143+
<>
144+
<GhostBar className="size-4 rounded-full" />
145+
<GhostBar className="w-24" />
146+
</>
147+
)}
87148
</div>
88149
<div className="mt-4 flex min-w-0 items-center gap-2">
89-
<GhostBar className="h-6 w-24 rounded-md" />
90-
<GhostBar className="size-3 rounded-full" />
91-
<GhostBar className="h-6 w-32 rounded-md" />
150+
{seed ? (
151+
<span className="flex min-w-0 flex-1 items-center gap-1.5 font-mono text-xs text-muted-foreground/70">
152+
<code className="min-w-0 max-w-[40%] shrink-0 truncate">{seed.baseBranch}</code>
153+
<ArrowLeftIcon
154+
aria-label="receives changes from"
155+
className="size-3.5 shrink-0 opacity-60"
156+
/>
157+
<code className="min-w-0 flex-1 truncate">{seed.headBranch}</code>
158+
</span>
159+
) : (
160+
<>
161+
<GhostBar className="h-6 w-24 rounded-md" />
162+
<GhostBar className="size-3 rounded-full" />
163+
<GhostBar className="h-6 w-32 rounded-md" />
164+
</>
165+
)}
92166
<div className="ml-auto flex shrink-0 items-center gap-2">
93167
<GhostBar className="w-10" />
94-
<GhostBar className="w-20" />
168+
{seed ? (
169+
<PullRequestDiffStat
170+
additions={seed.additions}
171+
deletions={seed.deletions}
172+
className="font-mono text-xs"
173+
/>
174+
) : (
175+
<GhostBar className="w-20" />
176+
)}
95177
</div>
96178
</div>
97179
</div>
@@ -102,7 +184,19 @@ export function PullRequestDetailGhost() {
102184
<GhostBar className="h-6 w-16 rounded-md" />
103185
<GhostBar className="h-6 w-12 rounded-md" />
104186
</div>
105-
<GhostBar className="w-20" />
187+
{checksPresentation ? (
188+
<span
189+
className={cn(
190+
"inline-flex items-center gap-1.5 text-xs",
191+
checksPresentation.toneClassName,
192+
)}
193+
>
194+
<checksPresentation.Icon aria-hidden className="size-3.5" />
195+
{checksPresentation.label}
196+
</span>
197+
) : (
198+
<GhostBar className="w-20" />
199+
)}
106200
</div>
107201
</div>
108202

@@ -125,8 +219,29 @@ export function PullRequestDetailGhost() {
125219
<GhostBar className="w-10" />
126220
</div>
127221
<div className="flex items-center gap-1">
128-
<GhostBar className="h-5 w-24 rounded-full" />
129-
<GhostBar className="h-5 w-20 rounded-full" />
222+
{seed ? (
223+
seed.labels.slice(0, 3).map((label) => {
224+
const color = pullRequestLabelColor(label.color);
225+
return (
226+
<span
227+
key={label.name}
228+
className="inline-flex h-5 max-w-32 items-center gap-1 truncate rounded-full border border-border/70 bg-muted/40 px-2 text-[10px] text-muted-foreground"
229+
>
230+
<span
231+
aria-hidden
232+
className="size-2 shrink-0 rounded-full bg-muted-foreground"
233+
{...(color ? { style: { backgroundColor: color } } : {})}
234+
/>
235+
<span className="truncate">{label.name}</span>
236+
</span>
237+
);
238+
})
239+
) : (
240+
<>
241+
<GhostBar className="h-5 w-24 rounded-full" />
242+
<GhostBar className="h-5 w-20 rounded-full" />
243+
</>
244+
)}
130245
</div>
131246
</div>
132247
<div className="grid min-h-8 grid-cols-[6rem_minmax(0,1fr)] items-center gap-2">

‎apps/web/src/routes/_chat.pull-requests.tsx‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,6 +1436,15 @@ function PullRequestsRouteView() {
14361436
entry.additions + entry.deletions > 0 || statsByRow.has(pullRequestDiffStatKey(entry)),
14371437
);
14381438
}, [groups, sort, statsByRow, typedParsed.text]);
1439+
const listedPullRequestsBySurface = useMemo(
1440+
() =>
1441+
new Map(
1442+
displayGroups.flatMap((group) =>
1443+
group.entries.map((entry) => [pullRequestSurfaceId(entry), entry] as const),
1444+
),
1445+
),
1446+
[displayGroups],
1447+
);
14391448

14401449
const linkedSelection = useMemo(
14411450
() =>
@@ -1939,6 +1948,7 @@ function PullRequestsRouteView() {
19391948
repository: renderedPullRequestSurface.repository,
19401949
number: renderedPullRequestSurface.number,
19411950
}}
1951+
listEntry={listedPullRequestsBySurface.get(renderedPullRequestSurface.id) ?? null}
19421952
refreshToken={detailRefreshToken}
19431953
// Merging, closing or reopening changes the row this panel was opened from, so
19441954
// the list behind it is out of date the moment the host takes the action.

0 commit comments

Comments
 (0)