Skip to content

Commit 332836d

Browse files
committed
fix(web): reuse PR conflict status in the sidebar
1 parent 803f94e commit 332836d

7 files changed

Lines changed: 533 additions & 37 deletions

File tree

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,13 @@ export function useLinkedThreadPullRequest(
8383
!enabled || environmentId === null || reference === null
8484
? null
8585
: linkedPullRequestDetailAtom({ environmentId, input: reference }),
86-
).data;
87-
const detail = useSharedPullRequestSummary(environmentId, reference, queried);
86+
);
87+
const detail = useSharedPullRequestSummary(
88+
environmentId,
89+
reference,
90+
queried.data,
91+
queried.dataUpdatedAt,
92+
);
8893

8994
return useMemo(() => {
9095
if (current !== null) return linkedPullRequestSnapshotStatus(current);

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

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
ThreadId,
55
type ScopedThreadRef,
66
type PullRequestDetailView,
7+
type PullRequestSummary,
78
type ThreadPullRequestLink,
89
} from "@t3tools/contracts";
910
import { DEFAULT_CLIENT_SETTINGS } from "@t3tools/contracts/settings";
@@ -41,16 +42,17 @@ vi.mock("~/lib/sourceControlActions", () => ({
4142
usePreparePullRequestThreadAction: () => ({ run: prepareThread }),
4243
}));
4344
vi.mock("~/state/use-atom-command", () => ({ useAtomCommand: () => vi.fn() }));
44-
vi.mock("~/state/pullRequests", () => ({
45+
vi.mock("~/state/pullRequests", async (importOriginal) => ({
46+
...(await importOriginal<typeof import("~/state/pullRequests")>()),
4547
pullRequestEnvironment: { detail: () => "detail", activity: () => "activity" },
4648
usePullRequestTurnRefresh: () => 0,
47-
useSharedPullRequestSummary: () => null,
49+
useSharedPullRequestSummary: () => observedSummary,
4850
}));
4951
vi.mock("~/state/vcs", () => ({ vcsEnvironment: { listRefs: () => null } }));
5052
vi.mock("~/state/query", () => ({
5153
useEnvironmentQuery: (query: string) => ({
52-
data: query === "detail" ? detail : null,
53-
isPending: false,
54+
data: query === "detail" ? loadedDetail : null,
55+
isPending: query === "detail" && loadedDetail === null,
5456
isSuccess: true,
5557
error: null,
5658
refresh,
@@ -202,8 +204,12 @@ const threadRef: ScopedThreadRef = {
202204
const draftId = DraftId.make("draft-1");
203205
const newDraftId = DraftId.make("new-draft");
204206
let renderer: ReactTestRenderer;
207+
let loadedDetail: PullRequestDetailView | null = detail;
208+
let observedSummary: PullRequestSummary | null = null;
205209

206210
beforeEach(() => {
211+
loadedDetail = detail;
212+
observedSummary = null;
207213
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
208214
vi.stubGlobal("window", { addEventListener: vi.fn(), removeEventListener: vi.fn() });
209215
useComposerDraftStore.setState({ draftsByThreadKey: {} });
@@ -335,3 +341,53 @@ describe.each([
335341
}
336342
});
337343
});
344+
345+
describe("PR list status in the sidebar detail", () => {
346+
const panel = () => (
347+
<PullRequestDetailPanel
348+
environmentId={threadRef.environmentId}
349+
reference={detail}
350+
shortcutsEnabled={false}
351+
getShortcutContext={() => ({
352+
terminalFocus: false,
353+
terminalOpen: false,
354+
previewFocus: false,
355+
previewOpen: false,
356+
isWeb: true,
357+
isDesktop: false,
358+
})}
359+
/>
360+
);
361+
362+
it("shows the known title and conflict before full detail arrives", async () => {
363+
loadedDetail = null;
364+
observedSummary = detail;
365+
await act(async () => {
366+
renderer = create(panel());
367+
});
368+
expect(
369+
renderer.root.findAll((node) => node.children.includes("Conflicts with main")),
370+
).toHaveLength(1);
371+
expect(renderer.root.findAll((node) => node.children.includes(detail.title))).toHaveLength(1);
372+
expect(renderer.root.findAllByType("button")).toHaveLength(0);
373+
});
374+
375+
it("uses the list conflict while an older detail snapshot is displayed", async () => {
376+
loadedDetail = { ...detail, mergeability: "mergeable" };
377+
await act(async () => {
378+
renderer = create(panel());
379+
});
380+
expect(
381+
renderer.root.findAll((node) => node.children.includes("Resolve conflicts")),
382+
).toHaveLength(0);
383+
384+
loadedDetail = null;
385+
observedSummary = detail;
386+
await act(async () => {
387+
renderer.update(panel());
388+
});
389+
expect(
390+
renderer.root.findAll((node) => node.children.includes("Resolve conflicts")).length,
391+
).toBeGreaterThan(0);
392+
});
393+
});

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

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,13 @@ import { useProjects, useServerConfigs } from "~/state/entities";
7878
import { useEnvironments, usePrimaryEnvironmentId } from "~/state/environments";
7979
import { useEnvironmentQuery } from "~/state/query";
8080
import { useLiveRefresh } from "~/hooks/useLiveRefresh";
81-
import { pullRequestEnvironment } from "~/state/pullRequests";
82-
import { usePullRequestTurnRefresh, useSharedPullRequestSummary } from "~/state/pullRequests";
81+
import {
82+
pullRequestEnvironment,
83+
pullRequestListEntryToSummary,
84+
newestPullRequestSummary,
85+
usePullRequestTurnRefresh,
86+
useSharedPullRequestSummary,
87+
} from "~/state/pullRequests";
8388
import { useAtomCommand } from "~/state/use-atom-command";
8489
import { PullRequestStackMenu } from "./PullRequestStackMenu";
8590
import { PullRequestThreadLinks } from "./PullRequestThreadLinks";
@@ -542,6 +547,8 @@ export function PullRequestDetailPanel({
542547
const matchingListEntry =
543548
listEntry?.projectId === reference.projectId &&
544549
listEntry.repository.toLowerCase() === reference.repository.toLowerCase() &&
550+
(reference.host === undefined ||
551+
listEntry.host.toLowerCase() === reference.host.toLowerCase()) &&
545552
listEntry.number === reference.number
546553
? listEntry
547554
: null;
@@ -675,14 +682,31 @@ export function PullRequestDetailPanel({
675682
cached: cachedDetail,
676683
reference,
677684
});
678-
const sharedSummary = useSharedPullRequestSummary(environmentId, reference, resolvedCoreDetail);
685+
const listSummary = useMemo(
686+
() => (matchingListEntry === null ? null : pullRequestListEntryToSummary(matchingListEntry)),
687+
[matchingListEntry],
688+
);
689+
const observedSummary = useSharedPullRequestSummary(
690+
environmentId,
691+
reference,
692+
detailQuery.data,
693+
detailQuery.dataUpdatedAt,
694+
);
695+
const sharedSummary = useMemo(
696+
() => newestPullRequestSummary(resolvedCoreDetail, observedSummary ?? listSummary),
697+
[resolvedCoreDetail, observedSummary, listSummary],
698+
);
679699
const coreDetail = useMemo(
680700
() =>
681701
resolvedCoreDetail === null || sharedSummary === null || sharedSummary === resolvedCoreDetail
682702
? resolvedCoreDetail
683703
: {
684704
...resolvedCoreDetail,
685-
...sharedSummary,
705+
title: sharedSummary.title,
706+
state: sharedSummary.state,
707+
headBranch: sharedSummary.headBranch,
708+
baseBranch: sharedSummary.baseBranch,
709+
updatedAt: sharedSummary.updatedAt,
686710
author: sharedSummary.author ?? resolvedCoreDetail.author,
687711
additions: sharedSummary.additions ?? resolvedCoreDetail.additions,
688712
deletions: sharedSummary.deletions ?? resolvedCoreDetail.deletions,
@@ -1512,7 +1536,7 @@ export function PullRequestDetailPanel({
15121536
// The list already has the pull request's identity and summary. Keep them on screen
15131537
// and let the richer detail read replace the remaining placeholders in place.
15141538
if (detailQuery.isPending && !detail) {
1515-
return <PullRequestDetailGhost seed={matchingListEntry} />;
1539+
return <PullRequestDetailGhost seed={matchingListEntry} summary={sharedSummary} />;
15161540
}
15171541

15181542
return (

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

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
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";
10+
import type { PullRequestListEntry, PullRequestSummary } from "@t3tools/contracts";
1111
import { ArrowLeftIcon } from "lucide-react";
1212

1313
import { cn } from "~/lib/utils";
@@ -18,6 +18,7 @@ import {
1818
PullRequestActorLabel,
1919
PullRequestDiffStat,
2020
pullRequestChecksStatePresentation,
21+
resolvePullRequestConflict,
2122
resolvePullRequestState,
2223
} from "./pullRequestPresentation";
2324

@@ -72,16 +73,32 @@ export function PullRequestListGhost({
7273
* boundaries in the ghost prevents the loaded pull request from replacing one layout with
7374
* another a moment later.
7475
*/
75-
export function PullRequestDetailGhost({ seed }: { seed?: PullRequestListEntry | null }) {
76+
export function PullRequestDetailGhost({
77+
seed: entry,
78+
summary,
79+
}: {
80+
seed?: PullRequestListEntry | null;
81+
summary?: PullRequestSummary | null;
82+
}) {
83+
const seed = summary ? { ...entry, ...summary } : entry;
7684
const statePresentation = seed
7785
? resolvePullRequestState({
7886
state: seed.state,
79-
isDraft: seed.isDraft,
87+
isDraft: seed.isDraft ?? false,
8088
})
8189
: null;
8290
const checksPresentation = seed?.checksState
8391
? pullRequestChecksStatePresentation(seed.checksState)
8492
: null;
93+
const conflictSource = summary ?? seed;
94+
const conflictPresentation = conflictSource
95+
? resolvePullRequestConflict({
96+
state: conflictSource.state,
97+
isDraft: conflictSource.isDraft ?? false,
98+
mergeability: conflictSource.mergeability ?? "unknown",
99+
baseBranch: conflictSource.baseBranch,
100+
})
101+
: null;
85102

86103
return (
87104
<div
@@ -129,7 +146,7 @@ export function PullRequestDetailGhost({ seed }: { seed?: PullRequestListEntry |
129146
{seed ? (
130147
<>
131148
<PullRequestActorLabel
132-
actor={seed.author}
149+
actor={seed.author ?? null}
133150
className="font-medium"
134151
tooltip={false}
135152
/>
@@ -165,8 +182,8 @@ export function PullRequestDetailGhost({ seed }: { seed?: PullRequestListEntry |
165182
<GhostBar className="w-10" />
166183
{seed ? (
167184
<PullRequestDiffStat
168-
additions={seed.additions}
169-
deletions={seed.deletions}
185+
additions={seed.additions ?? 0}
186+
deletions={seed.deletions ?? 0}
170187
className="font-mono text-xs"
171188
/>
172189
) : (
@@ -182,7 +199,17 @@ export function PullRequestDetailGhost({ seed }: { seed?: PullRequestListEntry |
182199
<GhostBar className="h-6 w-16 rounded-md" />
183200
<GhostBar className="h-6 w-12 rounded-md" />
184201
</div>
185-
{checksPresentation ? (
202+
{conflictPresentation ? (
203+
<span
204+
className={cn(
205+
"inline-flex items-center gap-1.5 text-xs",
206+
conflictPresentation.toneClassName,
207+
)}
208+
>
209+
<conflictPresentation.Icon aria-hidden className="size-3.5" />
210+
{conflictPresentation.label}
211+
</span>
212+
) : checksPresentation ? (
186213
<span
187214
className={cn(
188215
"inline-flex items-center gap-1.5 text-xs",
@@ -217,7 +244,7 @@ export function PullRequestDetailGhost({ seed }: { seed?: PullRequestListEntry |
217244
<GhostBar className="w-10" />
218245
</div>
219246
<div className="flex items-center gap-1">
220-
{seed ? (
247+
{seed?.labels ? (
221248
seed.labels.slice(0, 3).map((label) => {
222249
const color = pullRequestLabelColor(label.color);
223250
return (

0 commit comments

Comments
 (0)