Skip to content
TypeScript

fix(mobile): close and reopen pull requests from the actions menu (#29962)

Julius Marminge499727ddad87
diff --git a/apps/mobile/src/features/pull-requests/PullRequestRouteScreen.tsx b/apps/mobile/src/features/pull-requests/PullRequestRouteScreen.tsx
index 4e55ed4ef65..6129f80d439 100644
--- a/apps/mobile/src/features/pull-requests/PullRequestRouteScreen.tsx
+++ b/apps/mobile/src/features/pull-requests/PullRequestRouteScreen.tsx
@@ -423,6 +423,13 @@ export function PullRequestRouteScreen({ route }: StaticScreenProps<PullRequestP
permissions.canEditMaintainerEdits,
);
const showsDeleteBranch = pr !== null && canPerformPullRequestAction(pr, "delete-branch");
+ const stateAction = action.available("close")
+ ? "close"
+ : action.available("reopen")
+ ? "reopen"
+ : null;
+ const runStateAction = () =>
+ stateAction === "close" ? action.confirmClose() : void action.perform("reopen");
const confirmDeleteBranch = () =>
pr &&
action.confirm(
@@ -557,6 +564,17 @@ export function PullRequestRouteScreen({ route }: StaticScreenProps<PullRequestP
},
]
: []),
+ ...(stateAction
+ ? [
+ {
+ accessibilityLabel: pullRequestActionLabel(stateAction, terminology),
+ icon: PR_ACTION_ICONS[stateAction],
+ destructive: stateAction === "close",
+ overflowOnly: true,
+ onPress: runStateAction,
+ },
+ ]
+ : []),
...(showsDeleteBranch
? [
{
@@ -648,6 +666,15 @@ export function PullRequestRouteScreen({ route }: StaticScreenProps<PullRequestP
<Toolbar.Label>Share…</Toolbar.Label>
</Toolbar.MenuAction>
) : null}
+ {stateAction ? (
+ <Toolbar.MenuAction
+ icon={PR_ACTION_ICONS[stateAction]}
+ destructive={stateAction === "close"}
+ onPress={runStateAction}
+ >
+ <Toolbar.Label>{pullRequestActionLabel(stateAction, terminology)}</Toolbar.Label>
+ </Toolbar.MenuAction>
+ ) : null}
{showsDeleteBranch ? (
<Toolbar.MenuAction
icon={PR_ACTION_ICONS["delete-branch"]}
diff --git a/apps/mobile/src/features/pull-requests/PullRequestStatusRows.tsx b/apps/mobile/src/features/pull-requests/PullRequestStatusRows.tsx
index 185d555cc77..52d5505c456 100644
--- a/apps/mobile/src/features/pull-requests/PullRequestStatusRows.tsx
+++ b/apps/mobile/src/features/pull-requests/PullRequestStatusRows.tsx
@@ -86,12 +86,7 @@ export function PullRequestStatusMenu(props: RowProps) {
onPressAction={({ nativeEvent }) => {
const selected = actions.find((id) => id === nativeEvent.event);
if (!selected) return;
- if (selected === "close")
- action.confirm(
- selected,
- pullRequestActionLabel("close", terminology),
- `Close this ${terminology.singular} without merging its changes?`,
- );
+ if (selected === "close") action.confirmClose();
else if (selected === "revert")
action.confirm(
selected,
diff --git a/apps/mobile/src/features/pull-requests/usePullRequestAction.ts b/apps/mobile/src/features/pull-requests/usePullRequestAction.ts
index f53a8523d6b..4658330dd6c 100644
--- a/apps/mobile/src/features/pull-requests/usePullRequestAction.ts
+++ b/apps/mobile/src/features/pull-requests/usePullRequestAction.ts
@@ -11,7 +11,7 @@ import type {
import { useRef, useState } from "react";
import { composerPullRequests } from "../../state/pull-requests";
import { useAtomCommand } from "../../state/use-atom-command";
-import { canPerformPullRequestAction } from "./pullRequestActions";
+import { canPerformPullRequestAction, pullRequestActionLabel } from "./pullRequestActions";
import { pullRequestTarget, type PullRequestParams } from "./usePullRequestDiff";
import { usePullRequestPermissions } from "./usePullRequestPermissions";
@@ -55,5 +55,13 @@ export function usePullRequestAction(params: PullRequestParams, pr: PullRequestD
onPress: () => void perform(action),
},
]);
- return { available, perform, confirm, busy };
+ const confirmClose = () => {
+ const terminology = sourceControlClients.get(pr?.provider).changeRequest;
+ confirm(
+ "close",
+ pullRequestActionLabel("close", terminology),
+ `Close this ${terminology.singular} without merging its changes?`,
+ );
+ };
+ return { available, perform, confirm, confirmClose, busy };
}