@@ -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 ) ;
0 commit comments