@@ -262,6 +262,7 @@ import { environmentCatalog } from "../connection/catalog";
262262import { selectThreadTerminalUiState , useTerminalUiStateStore } from "../terminalUiStateStore" ;
263263import { useKnownTerminalSessions , useThreadRunningTerminalIds } from "../state/terminalSessions" ;
264264import { projectEnvironment } from "../state/projects" ;
265+ import { linkedPullRequestDetailAtom } from "../state/pullRequests" ;
265266import { useEnvironmentQuery } from "../state/query" ;
266267import {
267268 environmentServerConfigsAtom ,
@@ -317,6 +318,7 @@ import {
317318} from "./chat/ThreadErrorBanner" ;
318319import {
319320 resolveDisplayedThreadPr ,
321+ threadPullRequestRefreshSource ,
320322 threadChangeRequestSnapshotsAtom ,
321323 useLinkedThreadPullRequest ,
322324} from "./ThreadStatusIndicators" ;
@@ -1745,14 +1747,16 @@ function ChatViewContent(props: ChatViewProps) {
17451747 // the tab is found again whether or not that surface was opened with an environment on it.
17461748 const activePullRequestSurfaceId =
17471749 activeRightPanelSurface ?. kind === "pull-request" ? activeRightPanelSurface . id : undefined ;
1748- const handlePullRequestTabStatusChange = useCallback (
1750+ const updatePullRequestTabStatusFromPanel = useCallback (
17491751 ( status : PullRequestTabStatus ) => {
17501752 const id = activePullRequestSurfaceId ;
17511753 if ( id === undefined ) return ;
17521754 setPullRequestTabStatuses ( ( current ) => updatePullRequestTabStatus ( current , id , status ) ) ;
17531755 } ,
17541756 [ activePullRequestSurfaceId ] ,
17551757 ) ;
1758+ const refreshVcsStatus = useAtomCommand ( vcsEnvironment . refreshStatus , { reportFailure : false } ) ;
1759+ const sidebarPrRefreshKeyRef = useRef < string | null > ( null ) ;
17561760 const activeFileSurface =
17571761 activeRightPanelSurface ?. kind === "file" ? activeRightPanelSurface : null ;
17581762 const activePreviewState = useThreadPreviewState ( activeThreadRef ) ;
@@ -4594,6 +4598,62 @@ function ChatViewContent(props: ChatViewProps) {
45944598 linkedPullRequest : linkedThreadPullRequest ,
45954599 linkedPullRequestStatus,
45964600 } ) ;
4601+ const handlePullRequestTabStatusChange = useCallback (
4602+ ( status : PullRequestTabStatus ) => {
4603+ updatePullRequestTabStatusFromPanel ( status ) ;
4604+ const source = threadPullRequestRefreshSource ( {
4605+ panel : status ,
4606+ thread : {
4607+ repository : threadRepository ,
4608+ number : linkedThreadPullRequest ?. number ?? activeThreadPr ?. number ?? null ,
4609+ state : activeThreadPr ?. state ?? null ,
4610+ linked : linkedThreadPullRequest !== null ,
4611+ } ,
4612+ } ) ;
4613+ if ( source === null ) {
4614+ sidebarPrRefreshKeyRef . current = null ;
4615+ return ;
4616+ }
4617+ const refreshKey = `${ source } :${ status . repository } #${ status . number } :${ status . state } ` ;
4618+ if ( sidebarPrRefreshKeyRef . current === refreshKey ) return ;
4619+ sidebarPrRefreshKeyRef . current = refreshKey ;
4620+
4621+ if ( source === "linked-detail" && activeThreadRef && linkedThreadPullRequest ) {
4622+ appAtomRegistry . refresh (
4623+ linkedPullRequestDetailAtom ( {
4624+ environmentId : activeThreadRef . environmentId ,
4625+ input : {
4626+ projectId : linkedThreadPullRequest . projectId ,
4627+ repository : linkedThreadPullRequest . repository ,
4628+ number : linkedThreadPullRequest . number ,
4629+ } ,
4630+ } ) ,
4631+ ) ;
4632+ sidebarPrRefreshKeyRef . current = null ;
4633+ return ;
4634+ }
4635+ if ( source === "vcs" && activeThreadRef && gitCwd !== null ) {
4636+ void refreshVcsStatus ( {
4637+ environmentId : activeThreadRef . environmentId ,
4638+ input : { cwd : gitCwd } ,
4639+ } ) . then ( ( ) => {
4640+ if ( sidebarPrRefreshKeyRef . current === refreshKey ) {
4641+ sidebarPrRefreshKeyRef . current = null ;
4642+ }
4643+ } ) ;
4644+ }
4645+ } ,
4646+ [
4647+ activeThreadPr ?. number ,
4648+ activeThreadPr ?. state ,
4649+ activeThreadRef ,
4650+ gitCwd ,
4651+ linkedThreadPullRequest ,
4652+ refreshVcsStatus ,
4653+ threadRepository ,
4654+ updatePullRequestTabStatusFromPanel ,
4655+ ] ,
4656+ ) ;
45974657 const activeThreadReferenceCopyTarget = useMemo (
45984658 ( ) =>
45994659 activeThreadId === null || ! isServerThread
0 commit comments