@@ -16,14 +16,16 @@ import {
1616 allowedMergeMethods ,
1717 canPerformPullRequestAction ,
1818 mergeUnavailableReason ,
19- MERGE_CONFLICT_REASON ,
2019 MERGE_METHODS ,
20+ PR_ACTION_ICONS ,
2121 pullRequestActionLabel ,
2222} from "./pullRequestActions" ;
2323import { pullRequestStackMerge , singlePullRequestMergeAllowed } from "./pullRequestStack" ;
2424import { pullRequestTarget , type PullRequestParams } from "./usePullRequestDiff" ;
25+ import { usePullRequestAction } from "./usePullRequestAction" ;
2526import { usePullRequestPermissions } from "./usePullRequestPermissions" ;
2627import { PullRequestGlyph } from "./pullRequestGlyphs" ;
28+ import type { AppSymbolName } from "../../components/ui/AppSymbol" ;
2729import type { PullRequestStackState } from "./usePullRequestStack" ;
2830
2931export function PullRequestMergeControls ( props : {
@@ -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,6 +85,39 @@ export function PullRequestMergeControls(props: {
8285 ? `${ MERGE_METHODS [ method ] . title } stack (${ scope . layers . length } )`
8386 : MERGE_METHODS [ method ] . title
8487 : "Merge unavailable" ;
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 ;
85121 const autoAction = pr . autoMergeEnabled ? "disable-auto-merge" : "enable-auto-merge" ;
86122 const canAutoMerge =
87123 ! busy &&
@@ -167,32 +203,48 @@ export function PullRequestMergeControls(props: {
167203 return (
168204 < View className = "gap-2 border-t border-border-subtle p-3" >
169205 < SplitButton
170- label = { busy ? "Working…" : ! permissions . connected ? "Reconnect to merge" : label }
206+ label = {
207+ busy || stateAction . busy
208+ ? "Working…"
209+ : ! permissions . connected
210+ ? "Reconnect to merge"
211+ : ( status ?. label ?? label )
212+ }
171213 accessibilityLabel = {
172- scope ? `${ label } , ${ scope . layers . length } stack layers through #${ pr . number } ` : label
214+ status
215+ ? status . label
216+ : scope
217+ ? `${ label } , ${ scope . layers . length } stack layers through #${ pr . number } `
218+ : label
219+ }
220+ icon = { status ?. icon ?? PullRequestGlyph . merged }
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" )
173225 }
174- icon = { PullRequestGlyph . merged }
175- disabled = { ! canMerge }
176- loading = { busy || checkingStack }
177- onPress = { ( ) => confirm ( "merge" ) }
178226 menuTitle = "Merge options"
179- actions = { [
180- ...methods . map ( ( id ) => ( {
181- id,
182- title : MERGE_METHODS [ id ] . title ,
183- state : id === method ? ( "on" as const ) : ( "off" as const ) ,
184- attributes : { disabled : ! canMerge && ! canAutoMerge } ,
185- } ) ) ,
186- ...( canAutoMerge
187- ? [
188- {
189- id : autoAction ,
190- title : pr . autoMergeEnabled ? "Disable auto-merge" : "Enable auto-merge" ,
191- image : "clock" ,
192- } ,
227+ actions = {
228+ status ?. final
229+ ? [ ]
230+ : [
231+ ...methods . map ( ( id ) => ( {
232+ id,
233+ title : MERGE_METHODS [ id ] . title ,
234+ state : id === method ? ( "on" as const ) : ( "off" as const ) ,
235+ attributes : { disabled : ! canMerge && ! canAutoMerge } ,
236+ } ) ) ,
237+ ...( canAutoMerge
238+ ? [
239+ {
240+ id : autoAction ,
241+ title : pr . autoMergeEnabled ? "Disable auto-merge" : "Enable auto-merge" ,
242+ image : "clock" ,
243+ } ,
244+ ]
245+ : [ ] ) ,
193246 ]
194- : [ ] ) ,
195- ] }
247+ }
196248 onPressAction = { ( id ) => {
197249 const selected = methods . find ( ( method ) => method === id ) ;
198250 if ( selected ) {
@@ -201,18 +253,9 @@ export function PullRequestMergeControls(props: {
201253 } else if ( id === autoAction && canAutoMerge ) confirm ( autoAction ) ;
202254 } }
203255 />
204- { permissions . connected &&
205- reason &&
206- reason !== MERGE_CONFLICT_REASON &&
207- reason !== "Checking stack membership…" &&
208- ! ( checkingStack && reason === "Refresh the stack before merging." ) ? (
256+ { permissions . connected && ! status && reason ? (
209257 < Text className = "px-1 text-xs text-foreground-muted" > { reason } </ Text >
210258 ) : null }
211- { pr . autoMergeEnabled ? (
212- < Text className = "px-1 text-xs text-foreground-muted" >
213- Auto-merge is enabled{ pr . autoMergeMethod ? ` · ${ pr . autoMergeMethod } ` : "" }
214- </ Text >
215- ) : null }
216259 { stack . error && stack . supportsStackActions ? (
217260 < Button label = "Retry stack lookup" tone = "text" onPress = { stack . refresh } />
218261 ) : null }
0 commit comments