Skip to content

Commit c02fc91

Browse files
committed
fix(web): resolve linked pr merge preferences by repository
1 parent e7aca94 commit c02fc91

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ import {
1515
import { useCallback, useMemo } from "react";
1616

1717
import { writeTextToClipboard } from "~/hooks/useCopyToClipboard";
18-
import { useOpenPrLink } from "~/lib/openPullRequestLink";
18+
import { findProjectForChangeRequest, useOpenPrLink } from "~/lib/openPullRequestLink";
1919
import { cn } from "~/lib/utils";
2020
import { useShortcutModifierState } from "~/shortcutModifierState";
21-
import { useServerConfigs, useThreadShell } from "~/state/entities";
21+
import { useProjects, useServerConfigs, useThreadShell } from "~/state/entities";
2222
import { PullRequestsUnavailableState } from "./PullRequestsUnavailableState";
2323
import { threadEnvironment } from "~/state/threads";
2424
import { useAtomCommand } from "~/state/use-atom-command";
@@ -303,6 +303,16 @@ export function ThreadPullRequestsPanel({ threadRef }: { threadRef: ScopedThread
303303

304304
function EnabledThreadPullRequestsPanel({ threadRef }: { threadRef: ScopedThreadRef }) {
305305
const thread = useThreadShell(threadRef);
306+
const projects = useProjects();
307+
const environmentProjects = useMemo(
308+
() =>
309+
projects
310+
.filter((project) => project.environmentId === threadRef.environmentId)
311+
.toSorted((left, right) =>
312+
left.id === thread?.projectId ? -1 : right.id === thread?.projectId ? 1 : 0,
313+
),
314+
[projects, threadRef.environmentId, thread?.projectId],
315+
);
306316
const modifiers = useShortcutModifierState(true);
307317
const speedMode =
308318
modifiers.shiftKey && !modifiers.metaKey && !modifiers.ctrlKey && !modifiers.altKey;
@@ -381,7 +391,13 @@ function EnabledThreadPullRequestsPanel({ threadRef }: { threadRef: ScopedThread
381391
key={`${line.link.host}/${line.link.repository}#${line.link.number}`}
382392
line={line}
383393
threadRef={threadRef}
384-
projectId={capabilities?.pullRequests === true ? (thread?.projectId ?? null) : null}
394+
projectId={
395+
capabilities?.pullRequests === true
396+
? (findProjectForChangeRequest(environmentProjects, line.link)?.id ??
397+
thread?.projectId ??
398+
null)
399+
: null
400+
}
385401
speedMode={speedMode}
386402
onUnlink={handleUnlink}
387403
onSetWatching={supportsWatch ? handleSetWatching : null}

0 commit comments

Comments
 (0)