@@ -15,10 +15,10 @@ import {
1515import { useCallback , useMemo } from "react" ;
1616
1717import { writeTextToClipboard } from "~/hooks/useCopyToClipboard" ;
18- import { useOpenPrLink } from "~/lib/openPullRequestLink" ;
18+ import { findProjectForChangeRequest , useOpenPrLink } from "~/lib/openPullRequestLink" ;
1919import { cn } from "~/lib/utils" ;
2020import { useShortcutModifierState } from "~/shortcutModifierState" ;
21- import { useServerConfigs , useThreadShell } from "~/state/entities" ;
21+ import { useProjects , useServerConfigs , useThreadShell } from "~/state/entities" ;
2222import { PullRequestsUnavailableState } from "./PullRequestsUnavailableState" ;
2323import { threadEnvironment } from "~/state/threads" ;
2424import { useAtomCommand } from "~/state/use-atom-command" ;
@@ -303,6 +303,16 @@ export function ThreadPullRequestsPanel({ threadRef }: { threadRef: ScopedThread
303303
304304function 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