11import { scopeThreadRef } from "@t3tools/client-runtime/environment" ;
2- import { Link } from "@tanstack/react-router " ;
2+ import { openCommandPalette } from "~/commandPaletteBus " ;
33import type { EnvironmentId , PullRequestRef , ScopedThreadRef , ThreadId } from "@t3tools/contracts" ;
44import { CheckIcon , LinkIcon , MessageSquareIcon , UnlinkIcon } from "lucide-react" ;
55import { useState } from "react" ;
@@ -10,11 +10,10 @@ import { parseChangeRequestUrl } from "~/lib/openPullRequestLink";
1010import { useProjects , useServerConfigs , useThreadShell , useThreadShells } from "~/state/entities" ;
1111import { pullRequestEnvironment } from "~/state/pullRequests" ;
1212import { useEnvironmentQuery } from "~/state/query" ;
13- import { buildThreadRouteParams } from "~/threadRoutes" ;
1413import { Button } from "../ui/button" ;
1514import { Command , CommandInput , CommandItem , CommandList } from "../ui/command" ;
1615import { Dialog , DialogPopup , DialogTitle } from "../ui/dialog" ;
17- import { Menu , MenuItem , MenuPopup , MenuTrigger } from "../ui/menu" ;
16+ import { MenuItem } from "../ui/menu" ;
1817import { toastManager } from "../ui/toast" ;
1918
2019interface PullRequestThreadLinksProps {
@@ -59,8 +58,7 @@ function EnabledPullRequestThreadLinks({
5958 } )
6059 : null ,
6160 ) ;
62- // Refreshes can briefly clear the query value. Keep the last response so polling
63- // does not unmount an open menu or move its highlighted thread.
61+ // Keep the count stable while its query refreshes.
6462 const [ lastRelations , setLastRelations ] = useState ( relations . data ) ;
6563 if ( relations . data !== null && relations . data !== lastRelations ) {
6664 setLastRelations ( relations . data ) ;
@@ -96,47 +94,19 @@ function EnabledPullRequestThreadLinks({
9694 return (
9795 < >
9896 { display === "count" && ( linkedThreads . length > 0 || relations . error !== null ) ? (
99- < Menu >
100- < MenuTrigger
101- render = {
102- < Button
103- size = "xs"
104- variant = "ghost"
105- aria-label = { linkedThreadsLabel }
106- title = { linkedThreadsLabel }
107- />
108- }
109- >
110- < MessageSquareIcon aria-hidden className = "size-3.5" />
111- < span className = "@max-[40rem]/pr-header:hidden" > { linkedThreadsLabel } </ span >
112- < span aria-hidden className = "hidden @max-[40rem]/pr-header:inline" >
113- { linkedThreads . length || "?" }
114- </ span >
115- </ MenuTrigger >
116- < MenuPopup align = "end" className = "max-h-72 max-w-80 overflow-y-auto" >
117- { relations . error !== null ? (
118- < MenuItem onClick = { relations . refresh } > Could not load linked threads. Retry</ MenuItem >
119- ) : null }
120- { linkedThreads . map ( ( linkedThread ) => (
121- < MenuItem
122- key = { linkedThread . id }
123- render = {
124- < Link
125- to = "/$environmentId/$threadId"
126- params = { buildThreadRouteParams ( scopeThreadRef ( environmentId , linkedThread . id ) ) }
127- />
128- }
129- >
130- < span className = "min-w-0 flex-1 truncate" >
131- { linkedThread . title || "Untitled thread" }
132- </ span >
133- { linkedThread . archivedAt !== null ? (
134- < span className = "text-xs text-muted-foreground" > Archived</ span >
135- ) : null }
136- </ MenuItem >
137- ) ) }
138- </ MenuPopup >
139- </ Menu >
97+ < Button
98+ size = "xs"
99+ variant = "ghost"
100+ aria-label = { linkedThreadsLabel }
101+ title = { linkedThreadsLabel }
102+ onClick = { ( ) => openCommandPalette ( { query : url } ) }
103+ >
104+ < MessageSquareIcon aria-hidden className = "size-3.5" />
105+ < span className = "@max-[40rem]/pr-header:hidden" > { linkedThreadsLabel } </ span >
106+ < span aria-hidden className = "hidden @max-[40rem]/pr-header:inline" >
107+ { linkedThreads . length || "?" }
108+ </ span >
109+ </ Button >
140110 ) : null }
141111 { display === "menu-item" ? (
142112 < MenuItem
0 commit comments