Skip to content

Commit 6be0ea3

Browse files
committed
fix(web): keep PR merge confirmation stable while closing
1 parent 5304f3e commit 6be0ea3

2 files changed

Lines changed: 89 additions & 50 deletions

File tree

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

Lines changed: 53 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ import {
100100
buildFixFindingHandoff,
101101
buildFixFindingsHandoff,
102102
buildResolveConflictsPrompt,
103+
describePullRequestConfirmation,
103104
handoffPrompt,
104105
handoffReviewComments,
105106
pullRequestActionNeedsHostRefresh,
@@ -453,9 +454,11 @@ export function PullRequestDetailPanel({
453454
if (scroller) scroller.scrollTop = Math.max(0, scroller.scrollTop + delta);
454455
}, [condensed]);
455456
const [mergeMethod, setMergeMethod] = useState<PullRequestMergeMethod>("merge");
457+
// Keep the action through the exit animation so a closing dialog keeps its original copy.
456458
const [confirmAction, setConfirmAction] = useState<
457459
"merge" | "close" | "enable-auto-merge" | null
458460
>(null);
461+
const [confirmOpen, setConfirmOpen] = useState(false);
459462
// Which handoff is preparing, keyed so a per-finding button can say "Preparing..." on itself
460463
// alone. One at a time whatever the key: they all check the same pull request out.
461464
const [handoff, setHandoff] = useState<string | null>(null);
@@ -995,6 +998,11 @@ export function PullRequestDetailPanel({
995998
const selectedMergeMethod = allowedMergeMethods.includes(mergeMethod)
996999
? mergeMethod
9971000
: (allowedMergeMethods[0] ?? "merge");
1001+
const confirmation = describePullRequestConfirmation(
1002+
confirmAction,
1003+
reference.number,
1004+
selectedMergeMethod,
1005+
);
9981006
const conflicting = detail?.state === "open" && detail.mergeability === "conflicting";
9991007
// Only an outright yes arms it. A host that reports nothing has not said the merge is already
10001008
// spoken for, and an off switch for something that may not be on says the wrong thing twice.
@@ -1219,7 +1227,10 @@ export function PullRequestDetailPanel({
12191227
allowedMergeMethods.length > 0 ? (
12201228
<MenuItem
12211229
disabled={actionPending}
1222-
onClick={() => setConfirmAction("enable-auto-merge")}
1230+
onClick={() => {
1231+
setConfirmAction("enable-auto-merge");
1232+
setConfirmOpen(true);
1233+
}}
12231234
>
12241235
<GitMergeIcon className="size-3.5" />
12251236
Enable auto-merge
@@ -1279,7 +1290,10 @@ export function PullRequestDetailPanel({
12791290
<MenuItem
12801291
variant="destructive"
12811292
disabled={actionPending}
1282-
onClick={() => setConfirmAction("close")}
1293+
onClick={() => {
1294+
setConfirmAction("close");
1295+
setConfirmOpen(true);
1296+
}}
12831297
>
12841298
<GitPullRequestClosedIcon className="size-3.5" />
12851299
Close pull request
@@ -1369,7 +1383,10 @@ export function PullRequestDetailPanel({
13691383
<Button
13701384
size="xs"
13711385
disabled={actionPending}
1372-
onClick={() => setConfirmAction("merge")}
1386+
onClick={() => {
1387+
setConfirmAction("merge");
1388+
setConfirmOpen(true);
1389+
}}
13731390
>
13741391
{pendingAction === "merge" ? "Merging..." : "Merge"}
13751392
</Button>
@@ -1850,54 +1867,40 @@ export function PullRequestDetailPanel({
18501867
</div>
18511868

18521869
<AlertDialog
1853-
open={confirmAction !== null}
1854-
onOpenChange={(open) => !open && setConfirmAction(null)}
1870+
open={confirmOpen}
1871+
onOpenChange={setConfirmOpen}
1872+
onOpenChangeComplete={(open) => {
1873+
if (!open) setConfirmAction(null);
1874+
}}
18551875
>
1856-
<AlertDialogPopup>
1857-
<AlertDialogHeader>
1858-
<AlertDialogTitle>
1859-
{confirmAction === "merge"
1860-
? "Merge pull request?"
1861-
: confirmAction === "enable-auto-merge"
1862-
? "Enable auto-merge?"
1863-
: "Close pull request?"}
1864-
</AlertDialogTitle>
1865-
<AlertDialogDescription>
1866-
{confirmAction === "merge"
1867-
? `This merges #${reference.number} using ${selectedMergeMethod}.`
1868-
: confirmAction === "enable-auto-merge"
1869-
? // The host merges this as soon as it considers the pull request ready, which
1870-
// may be immediately — there is no telling from here whether anything is
1871-
// still outstanding.
1872-
`This merges #${reference.number} using ${selectedMergeMethod} as soon as the host considers it ready, which may be immediately.`
1873-
: `This closes #${reference.number} without merging it.`}
1874-
</AlertDialogDescription>
1875-
</AlertDialogHeader>
1876-
<AlertDialogFooter>
1877-
<AlertDialogClose render={<Button variant="outline" size="sm" />}>
1878-
Cancel
1879-
</AlertDialogClose>
1880-
<Button
1881-
size="sm"
1882-
variant={confirmAction === "close" ? "destructive" : "default"}
1883-
disabled={actionPending}
1884-
onClick={() => {
1885-
const action = confirmAction;
1886-
setConfirmAction(null);
1887-
if (action === "merge") void perform("merge", selectedMergeMethod);
1888-
if (action === "enable-auto-merge")
1889-
void perform("enable-auto-merge", selectedMergeMethod);
1890-
if (action === "close") void perform("close");
1891-
}}
1892-
>
1893-
{confirmAction === "merge"
1894-
? "Merge"
1895-
: confirmAction === "enable-auto-merge"
1896-
? "Enable auto-merge"
1897-
: "Close"}
1898-
</Button>
1899-
</AlertDialogFooter>
1900-
</AlertDialogPopup>
1876+
{confirmation ? (
1877+
<AlertDialogPopup>
1878+
<AlertDialogHeader>
1879+
<AlertDialogTitle>{confirmation.title}</AlertDialogTitle>
1880+
<AlertDialogDescription>{confirmation.description}</AlertDialogDescription>
1881+
</AlertDialogHeader>
1882+
<AlertDialogFooter>
1883+
<AlertDialogClose render={<Button variant="outline" size="sm" />}>
1884+
Cancel
1885+
</AlertDialogClose>
1886+
<Button
1887+
size="sm"
1888+
variant={confirmation.destructive ? "destructive" : "default"}
1889+
disabled={actionPending}
1890+
onClick={() => {
1891+
const action = confirmAction;
1892+
setConfirmOpen(false);
1893+
if (action === "merge") void perform("merge", selectedMergeMethod);
1894+
if (action === "enable-auto-merge")
1895+
void perform("enable-auto-merge", selectedMergeMethod);
1896+
if (action === "close") void perform("close");
1897+
}}
1898+
>
1899+
{confirmation.submitLabel}
1900+
</Button>
1901+
</AlertDialogFooter>
1902+
</AlertDialogPopup>
1903+
) : null}
19011904
</AlertDialog>
19021905
</div>
19031906
);

‎apps/web/src/components/pullRequest/pullRequestDetail.logic.ts‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type {
66
PullRequestComment,
77
PullRequestDetailView,
88
PullRequestMergeability,
9+
PullRequestMergeMethod,
910
PullRequestReaction,
1011
PullRequestReviewThread,
1112
PullRequestState,
@@ -64,6 +65,41 @@ export function describePullRequestState(state: PullRequestState, isDraft: boole
6465
return isDraft ? "Draft" : "Ready for review";
6566
}
6667

68+
/** Copy for a pending PR action. With no pending action, there is no confirmation to render. */
69+
export function describePullRequestConfirmation(
70+
action: "merge" | "close" | "enable-auto-merge" | null,
71+
number: number,
72+
mergeMethod: PullRequestMergeMethod,
73+
) {
74+
if (action === null) return null;
75+
76+
if (action === "merge") {
77+
return {
78+
title: "Merge pull request?",
79+
description: `This merges #${number} using ${mergeMethod}.`,
80+
submitLabel: "Merge",
81+
destructive: false,
82+
};
83+
}
84+
85+
if (action === "enable-auto-merge") {
86+
return {
87+
title: "Enable auto-merge?",
88+
// The host may consider the pull request ready and merge it immediately.
89+
description: `This merges #${number} using ${mergeMethod} as soon as the host considers it ready, which may be immediately.`,
90+
submitLabel: "Enable auto-merge",
91+
destructive: false,
92+
};
93+
}
94+
95+
return {
96+
title: "Close pull request?",
97+
description: `This closes #${number} without merging it.`,
98+
submitLabel: "Close",
99+
destructive: true,
100+
};
101+
}
102+
67103
/** Chronological ascending, oldest to newest — reversed for the "newest" reading order. */
68104
export function orderPullRequestComments<T extends { readonly createdAt: string }>(
69105
comments: ReadonlyArray<T>,

0 commit comments

Comments
 (0)