Skip to content

Commit 0847a44

Browse files
fix(mobile): merge button names merged, closed, draft, and conflict states (#29486)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 8657eec commit 0847a44

2 files changed

Lines changed: 69 additions & 38 deletions

File tree

‎apps/mobile/src/features/pull-requests/PullRequestMergeControls.tsx‎

Lines changed: 68 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -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";
2323
import { pullRequestStackMerge, singlePullRequestMergeAllowed } from "./pullRequestStack";
2424
import { pullRequestTarget, type PullRequestParams } from "./usePullRequestDiff";
25+
import { usePullRequestAction } from "./usePullRequestAction";
2526
import { usePullRequestPermissions } from "./usePullRequestPermissions";
2627
import { PullRequestGlyph } from "./pullRequestGlyphs";
28+
import type { AppSymbolName } from "../../components/ui/AppSymbol";
2729
import type { PullRequestStackState } from "./usePullRequestStack";
2830

2931
export 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,8 +85,39 @@ export function PullRequestMergeControls(props: {
8285
? `${MERGE_METHODS[method].title} stack (${scope.layers.length})`
8386
: MERGE_METHODS[method].title
8487
: "Merge unavailable";
85-
const autoMergeArmed = pr.state === "open" && pr.autoMergeEnabled === true;
86-
const armedLabel = `Auto-merge pending${pr.autoMergeMethod ? ` (${pr.autoMergeMethod})` : ""}`;
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;
87121
const autoAction = pr.autoMergeEnabled ? "disable-auto-merge" : "enable-auto-merge";
88122
const canAutoMerge =
89123
!busy &&
@@ -170,43 +204,47 @@ export function PullRequestMergeControls(props: {
170204
<View className="gap-2 border-t border-border-subtle p-3">
171205
<SplitButton
172206
label={
173-
busy
207+
busy || stateAction.busy
174208
? "Working…"
175209
: !permissions.connected
176210
? "Reconnect to merge"
177-
: autoMergeArmed
178-
? armedLabel
179-
: label
211+
: (status?.label ?? label)
180212
}
181213
accessibilityLabel={
182-
autoMergeArmed
183-
? `${armedLabel}, merges once its requirements are met`
214+
status
215+
? status.label
184216
: scope
185217
? `${label}, ${scope.layers.length} stack layers through #${pr.number}`
186218
: label
187219
}
188-
icon={autoMergeArmed ? "clock" : PullRequestGlyph.merged}
189-
disabled={!canMerge || autoMergeArmed}
190-
loading={busy || (!autoMergeArmed && checkingStack)}
191-
onPress={() => confirm("merge")}
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")
225+
}
192226
menuTitle="Merge options"
193-
actions={[
194-
...methods.map((id) => ({
195-
id,
196-
title: MERGE_METHODS[id].title,
197-
state: id === method ? ("on" as const) : ("off" as const),
198-
attributes: { disabled: !canMerge && !canAutoMerge },
199-
})),
200-
...(canAutoMerge
201-
? [
202-
{
203-
id: autoAction,
204-
title: pr.autoMergeEnabled ? "Disable auto-merge" : "Enable auto-merge",
205-
image: "clock",
206-
},
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+
: []),
207246
]
208-
: []),
209-
]}
247+
}
210248
onPressAction={(id) => {
211249
const selected = methods.find((method) => method === id);
212250
if (selected) {
@@ -215,12 +253,7 @@ export function PullRequestMergeControls(props: {
215253
} else if (id === autoAction && canAutoMerge) confirm(autoAction);
216254
}}
217255
/>
218-
{permissions.connected &&
219-
!autoMergeArmed &&
220-
reason &&
221-
reason !== MERGE_CONFLICT_REASON &&
222-
reason !== "Checking stack membership…" &&
223-
!(checkingStack && reason === "Refresh the stack before merging.") ? (
256+
{permissions.connected && !status && reason ? (
224257
<Text className="px-1 text-xs text-foreground-muted">{reason}</Text>
225258
) : null}
226259
{stack.error && stack.supportsStackActions ? (

‎apps/mobile/src/features/pull-requests/pullRequestActions.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,6 @@ export function canPerformPullRequestAction(pr: ActionDetail, action: PullReques
117117
}
118118
}
119119

120-
export const MERGE_CONFLICT_REASON = "Resolve the branch conflicts before merging.";
121-
122120
export function mergeUnavailableReason(
123121
pr: ActionDetail,
124122
connectionAllowsWrites: boolean,
@@ -132,7 +130,7 @@ export function mergeUnavailableReason(
132130
if (!pr.viewerPermissions.actions.includes("merge"))
133131
return `Your account cannot merge this ${terminology.singular}.`;
134132
if (pr.isDraft) return "Mark this draft ready for review before merging.";
135-
if (pr.mergeability === "conflicting") return MERGE_CONFLICT_REASON;
133+
if (pr.mergeability === "conflicting") return "Resolve the branch conflicts before merging.";
136134
if (!allowedMergeMethods(pr).length) return "This repository has no available merge methods.";
137135
return null;
138136
}

0 commit comments

Comments
 (0)