Skip to content

Commit 33b7d7b

Browse files
authored
feat(web): add shift-held pull request quick actions (pingdotgg#15549)
Co-authored-by: maria-rcks <[email protected]>
1 parent eac52f0 commit 33b7d7b

8 files changed

Lines changed: 392 additions & 199 deletions

‎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: 10 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { scopedThreadKey, scopeProjectRef } from "@t3tools/client-runtime/enviro
66
import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
77
import {
88
type EnvironmentId,
9-
DEFAULT_SERVER_SETTINGS,
109
type PullRequestAction,
1110
type PullRequestMergeMethod,
1211
type PullRequestListEntry,
@@ -15,7 +14,6 @@ import {
1514
resolveEnvironmentMachineKind,
1615
type ScopedThreadRef,
1716
} from "@t3tools/contracts";
18-
import { resolveProjectSettings } from "@t3tools/shared/projectSettings";
1917
import {
2018
ArrowDownUpIcon,
2119
ArrowLeftIcon,
@@ -63,20 +61,14 @@ import {
6361
type ShortcutMatchContext,
6462
} from "~/keybindings";
6563
import { primaryServerKeybindingsAtom } from "~/state/server";
66-
import { useClientSettings } from "~/hooks/useSettings";
67-
import {
68-
deriveLogicalProjectKeyFromSettings,
69-
derivePhysicalProjectKey,
70-
selectProjectGroupingSettings,
71-
} from "~/logicalProject";
64+
import { usePullRequestDefaultMergeMethodResolver } from "./usePullRequestActions";
7265
import { changeRequestRepositoryUrl, gitHubPullRequestBrowserUrl } from "~/lib/openPullRequestLink";
7366
import { usePreparePullRequestThreadAction } from "~/lib/sourceControlActions";
7467
import { cn } from "~/lib/utils";
7568
import { readLocalApi } from "~/localApi";
7669
import type { ReviewCommentContext } from "~/reviewCommentContext";
77-
import { buildPhysicalToLogicalProjectKeyMap } from "~/sidebarProjectGrouping";
7870
import { useProjects, useServerConfigs } from "~/state/entities";
79-
import { useEnvironments, usePrimaryEnvironmentId } from "~/state/environments";
71+
import { useEnvironments } from "~/state/environments";
8072
import { useEnvironmentQuery } from "~/state/query";
8173
import { useLiveRefresh } from "~/hooks/useLiveRefresh";
8274
import {
@@ -563,19 +555,14 @@ export function PullRequestDetailPanel({
563555
}, [condensed]);
564556
const lastSelectedMergeMethod = useUiStateStore((state) => state.pullRequestMergeMethod);
565557
const setLastSelectedMergeMethod = useUiStateStore((state) => state.setPullRequestMergeMethod);
566-
// Server-side and per project, like every other project setting. The
567-
// client-local per-project map from before still answers when the server
568-
// has no value, so a choice made on an older release keeps applying until
569-
// it is set (or reset) in Settings.
570-
const legacyMergeMethodOverrides = useClientSettings(
571-
(settings) => settings.pullRequestMergeMethodOverrides,
558+
const resolveProjectDefaultMergeMethod = usePullRequestDefaultMergeMethodResolver(
559+
environmentId,
560+
reference.projectId,
561+
);
562+
const projectDefaultMergeMethod = useMemo(
563+
() => resolveProjectDefaultMergeMethod(),
564+
[resolveProjectDefaultMergeMethod],
572565
);
573-
const projectGroupingSettings = useClientSettings(selectProjectGroupingSettings);
574-
const projectDefaultMergeMethod =
575-
resolveProjectSettings(
576-
environmentConfigs.get(environmentId)?.settings ?? DEFAULT_SERVER_SETTINGS,
577-
reference.projectId,
578-
).settings.pullRequestMergeMethod ?? undefined;
579566
const [mergeMethodSelection, setMergeMethodSelection] = useState<{
580567
readonly pullRequestKey: string;
581568
readonly method: PullRequestMergeMethod;
@@ -887,39 +874,12 @@ export function PullRequestDetailPanel({
887874
const [titleSaving, setTitleSaving] = useState(false);
888875
const newThread = useNewThreadHandler();
889876
const { environments } = useEnvironments();
890-
const primaryEnvironmentId = usePrimaryEnvironmentId();
891877
const unavailableGitHubUrl = useMemo(() => {
892878
const identity = projects.find(
893879
(project) => project.id === reference.projectId && project.environmentId === environmentId,
894880
)?.repositoryIdentity;
895881
return gitHubPullRequestBrowserUrl(identity, reference.repository, reference.number);
896882
}, [environmentId, projects, reference.number, reference.projectId, reference.repository]);
897-
// Project settings stored the override under the sidebar group's key, which a duplicate row
898-
// borrows from its siblings, so the project alone does not always name the same key.
899-
const legacyProjectDefaultMergeMethod = useMemo(() => {
900-
if (projectDefaultMergeMethod !== undefined) return undefined;
901-
const project = projects.find(
902-
(candidate) =>
903-
candidate.environmentId === environmentId && candidate.id === reference.projectId,
904-
);
905-
if (!project) return undefined;
906-
const projectKey =
907-
buildPhysicalToLogicalProjectKeyMap({
908-
projects,
909-
settings: projectGroupingSettings,
910-
primaryEnvironmentId,
911-
}).get(derivePhysicalProjectKey(project)) ??
912-
deriveLogicalProjectKeyFromSettings(project, projectGroupingSettings);
913-
return legacyMergeMethodOverrides[projectKey];
914-
}, [
915-
environmentId,
916-
legacyMergeMethodOverrides,
917-
primaryEnvironmentId,
918-
projectDefaultMergeMethod,
919-
projectGroupingSettings,
920-
projects,
921-
reference.projectId,
922-
]);
923883
// Beside a thread there is nothing to pick: the hand-offs land in that thread's composer, and
924884
// the thread is already on one server's copy of the branch.
925885
const pickableEnvironments = useMemo(
@@ -1421,7 +1381,7 @@ export function PullRequestDetailPanel({
14211381
const selectedMergeMethod = resolvePullRequestMergeMethod(
14221382
allowedMergeMethods,
14231383
currentMergeMethod,
1424-
projectDefaultMergeMethod ?? legacyProjectDefaultMergeMethod,
1384+
projectDefaultMergeMethod,
14251385
lastSelectedMergeMethod,
14261386
);
14271387
const selectedMergeMethodLabel = PULL_REQUEST_MERGE_METHOD_LABELS[selectedMergeMethod];

0 commit comments

Comments
 (0)