@@ -17,10 +17,12 @@ import {
1717 canPerformPullRequestAction ,
1818 mergeUnavailableReason ,
1919 MERGE_METHODS ,
20+ PR_ACTION_ICONS ,
2021 pullRequestActionLabel ,
2122} from "./pullRequestActions" ;
2223import { pullRequestStackMerge , singlePullRequestMergeAllowed } from "./pullRequestStack" ;
2324import { pullRequestTarget , type PullRequestParams } from "./usePullRequestDiff" ;
25+ import { usePullRequestAction } from "./usePullRequestAction" ;
2426import { usePullRequestPermissions } from "./usePullRequestPermissions" ;
2527import { PullRequestGlyph } from "./pullRequestGlyphs" ;
2628import type { AppSymbolName } from "../../components/ui/AppSymbol" ;
@@ -35,6 +37,7 @@ export function PullRequestMergeControls(props: {
3537 const terminology = sourceControlClients . get ( pr . provider ) . changeRequest ;
3638 const target = pullRequestTarget ( props . params ) ;
3739 const permissions = usePullRequestPermissions ( props . params , pr ) ;
40+ const stateAction = usePullRequestAction ( props . params , pr ) ;
3841 const preferences = useAtomValue ( mobilePreferencesAtom ) ;
3942 const savePreferences = useAtomSet ( updateMobilePreferencesAtom ) ;
4043 const runAction = useAtomCommand ( composerPullRequests . runAction , { reportFailure : false } ) ;
@@ -82,24 +85,39 @@ export function PullRequestMergeControls(props: {
8285 ? `${ MERGE_METHODS [ method ] . title } stack (${ scope . layers . length } )`
8386 : MERGE_METHODS [ method ] . title
8487 : "Merge unavailable" ;
85- // States the button itself names, instead of a reason line under it.
86- const status : { label : string ; icon : AppSymbolName ; final ?: boolean } | null =
87- pr . state === "merged"
88- ? { label : "Merged" , icon : PullRequestGlyph . merged , final : true }
89- : pr . state === "closed"
90- ? { label : "Closed" , icon : PullRequestGlyph . closed , final : true }
91- : pr . isDraft
92- ? { label : "Draft" , icon : PullRequestGlyph . draft }
93- : pr . mergeability === "conflicting"
94- ? { label : "Resolve conflicts to merge" , icon : PullRequestGlyph . conflicting }
95- : pr . autoMergeEnabled
96- ? {
97- label : `Auto-merge pending${ pr . autoMergeMethod ? ` (${ pr . autoMergeMethod } )` : "" } ` ,
98- icon : "clock" ,
99- }
100- : checkingStack && ! busy
101- ? { label : "Checking stack…" , icon : PullRequestGlyph . merged }
102- : null ;
88+ const nextAction =
89+ pr . state === "closed" ? "reopen" : pr . state === "open" && pr . isDraft ? "ready" : null ;
90+ // States the button itself names, instead of a reason line under it. Draft and
91+ // closed offer their way forward when the viewer can take it.
92+ const status : {
93+ label : string ;
94+ icon : AppSymbolName ;
95+ final ?: boolean ;
96+ action ?: "ready" | "reopen" ;
97+ } | null =
98+ nextAction && stateAction . available ( nextAction )
99+ ? {
100+ label : pullRequestActionLabel ( nextAction , terminology ) ,
101+ icon : PR_ACTION_ICONS [ nextAction ] ,
102+ final : nextAction === "reopen" ,
103+ action : nextAction ,
104+ }
105+ : pr . state === "merged"
106+ ? { label : "Merged" , icon : PullRequestGlyph . merged , final : true }
107+ : pr . state === "closed"
108+ ? { label : "Closed" , icon : PullRequestGlyph . closed , final : true }
109+ : pr . isDraft
110+ ? { label : "Draft" , icon : PullRequestGlyph . draft }
111+ : pr . mergeability === "conflicting"
112+ ? { label : "Resolve conflicts to merge" , icon : PullRequestGlyph . conflicting }
113+ : pr . autoMergeEnabled
114+ ? {
115+ label : `Auto-merge pending${ pr . autoMergeMethod ? ` (${ pr . autoMergeMethod } )` : "" } ` ,
116+ icon : "clock" ,
117+ }
118+ : checkingStack && ! busy
119+ ? { label : "Checking stack…" , icon : PullRequestGlyph . merged }
120+ : null ;
103121 const autoAction = pr . autoMergeEnabled ? "disable-auto-merge" : "enable-auto-merge" ;
104122 const canAutoMerge =
105123 ! busy &&
@@ -186,7 +204,7 @@ export function PullRequestMergeControls(props: {
186204 < View className = "gap-2 border-t border-border-subtle p-3" >
187205 < SplitButton
188206 label = {
189- busy
207+ busy || stateAction . busy
190208 ? "Working…"
191209 : ! permissions . connected
192210 ? "Reconnect to merge"
@@ -200,9 +218,11 @@ export function PullRequestMergeControls(props: {
200218 : label
201219 }
202220 icon = { status ?. icon ?? PullRequestGlyph . merged }
203- disabled = { ! canMerge || status !== null }
204- loading = { busy || checkingStack }
205- onPress = { ( ) => confirm ( "merge" ) }
221+ disabled = { status ?. action ? stateAction . busy : ! canMerge || status !== null }
222+ loading = { busy || stateAction . busy || ( ! status ?. action && checkingStack ) }
223+ onPress = { ( ) =>
224+ status ?. action ? void stateAction . perform ( status . action ) : confirm ( "merge" )
225+ }
206226 menuTitle = "Merge options"
207227 actions = {
208228 status ?. final
0 commit comments