Skip to content

Commit defb5ca

Browse files
committed
fix(web): refresh quick merge details and resolve settings on demand
1 parent 5c59658 commit defb5ca

4 files changed

Lines changed: 22 additions & 10 deletions

File tree

‎apps/web/src/components/pullRequest/PullRequestDetailPanel.test.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ vi.mock("~/state/environments", () => ({
3232
usePrimaryEnvironmentId: () => EnvironmentId.make("env-1"),
3333
}));
3434
vi.mock("~/hooks/useSettings", () => ({
35+
useEnvironmentSettings: () => undefined,
3536
useClientSettings: (select: (settings: typeof DEFAULT_CLIENT_SETTINGS) => unknown) =>
3637
select(DEFAULT_CLIENT_SETTINGS),
3738
}));

‎apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ import {
6161
type ShortcutMatchContext,
6262
} from "~/keybindings";
6363
import { primaryServerKeybindingsAtom } from "~/state/server";
64-
import { usePullRequestDefaultMergeMethod } from "./usePullRequestActions";
64+
import { usePullRequestDefaultMergeMethodResolver } from "./usePullRequestActions";
6565
import { changeRequestRepositoryUrl, gitHubPullRequestBrowserUrl } from "~/lib/openPullRequestLink";
6666
import { usePreparePullRequestThreadAction } from "~/lib/sourceControlActions";
6767
import { cn } from "~/lib/utils";
@@ -555,10 +555,14 @@ export function PullRequestDetailPanel({
555555
}, [condensed]);
556556
const lastSelectedMergeMethod = useUiStateStore((state) => state.pullRequestMergeMethod);
557557
const setLastSelectedMergeMethod = useUiStateStore((state) => state.setPullRequestMergeMethod);
558-
const projectDefaultMergeMethod = usePullRequestDefaultMergeMethod(
558+
const resolveProjectDefaultMergeMethod = usePullRequestDefaultMergeMethodResolver(
559559
environmentId,
560560
reference.projectId,
561561
);
562+
const projectDefaultMergeMethod = useMemo(
563+
() => resolveProjectDefaultMergeMethod(),
564+
[resolveProjectDefaultMergeMethod],
565+
);
562566
const [mergeMethodSelection, setMergeMethodSelection] = useState<{
563567
readonly pullRequestKey: string;
564568
readonly method: PullRequestMergeMethod;

‎apps/web/src/components/pullRequest/PullRequestSpeedActions.tsx‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { PullRequestGlyph } from "./pullRequestIcons";
1212
import type { EnvironmentPullRequestEntry } from "./pullRequestList.logic";
1313
import {
1414
usePullRequestActionRunner,
15-
usePullRequestDefaultMergeMethod,
15+
usePullRequestDefaultMergeMethodResolver,
1616
} from "./usePullRequestActions";
1717

1818
export interface PullRequestSpeedActionResult {
@@ -30,7 +30,10 @@ export function PullRequestSpeedActions({
3030
visible: boolean;
3131
onActed: (result: PullRequestSpeedActionResult) => void;
3232
}) {
33-
const projectDefault = usePullRequestDefaultMergeMethod(entry.environmentId, entry.projectId);
33+
const resolveProjectDefault = usePullRequestDefaultMergeMethodResolver(
34+
entry.environmentId,
35+
entry.projectId,
36+
);
3437
const reference = {
3538
projectId: entry.projectId,
3639
host: entry.host,
@@ -43,7 +46,10 @@ export function PullRequestSpeedActions({
4346
onSuccess: (action) => onActed({ entry, action }),
4447
resolveMergeMethod: async () => {
4548
const target = { environmentId: entry.environmentId, input: reference };
46-
const detailAtom = pullRequestEnvironment.detail(target);
49+
const detailAtom = pullRequestEnvironment.detail({
50+
...target,
51+
input: { ...reference, allowStale: false },
52+
});
4753
appAtomRegistry.refresh(detailAtom);
4854
const detail = await Effect.runPromise(
4955
AtomRegistry.getResult(appAtomRegistry, detailAtom, { suspendOnWaiting: true }),
@@ -72,7 +78,7 @@ export function PullRequestSpeedActions({
7278
return resolvePullRequestMergeMethod(
7379
allowed,
7480
null,
75-
projectDefault ?? undefined,
81+
resolveProjectDefault(),
7682
useUiStateStore.getState().pullRequestMergeMethod,
7783
);
7884
},

‎apps/web/src/components/pullRequest/usePullRequestActions.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import type {
1414
PullRequestMergeMethod,
1515
PullRequestRef,
1616
} from "@t3tools/contracts";
17-
import { useMemo, useRef, useState } from "react";
17+
import { useCallback, useRef, useState } from "react";
1818
import { resolveProjectSettings } from "@t3tools/shared/projectSettings";
1919
import { useClientSettings, useEnvironmentSettings } from "~/hooks/useSettings";
2020
import {
@@ -36,8 +36,8 @@ import { useAtomCommand } from "~/state/use-atom-command";
3636
import { toastManager } from "../ui/toast";
3737
import { handoffPrompt, handoffReviewComments, readableFailure } from "./pullRequestDetail.logic";
3838

39-
/** Both detail and quick actions honor the server setting and its older client-local fallback. */
40-
export function usePullRequestDefaultMergeMethod(
39+
/** Resolve on demand so hidden quick actions do not rebuild the legacy project grouping. */
40+
export function usePullRequestDefaultMergeMethodResolver(
4141
environmentId: EnvironmentId,
4242
projectId: ProjectId,
4343
) {
@@ -49,8 +49,9 @@ export function usePullRequestDefaultMergeMethod(
4949
const grouping = useClientSettings(selectProjectGroupingSettings);
5050
const projects = useProjects();
5151
const primaryEnvironmentId = usePrimaryEnvironmentId();
52-
return useMemo(() => {
52+
return useCallback(() => {
5353
if (projectDefault != null) return projectDefault;
54+
if (Object.keys(legacyOverrides).length === 0) return undefined;
5455
const project = projects.find(
5556
(candidate) => candidate.environmentId === environmentId && candidate.id === projectId,
5657
);

0 commit comments

Comments
 (0)