@@ -22,6 +22,8 @@ interface PullRequestThreadLinksProps {
2222 reference : PullRequestRef ;
2323 url : string ;
2424 threadRef : ScopedThreadRef | null ;
25+ display : "count" | "menu-item" | "picker" ;
26+ onPickerOpenChange ?: ( open : boolean ) => void ;
2527}
2628
2729/** Thread relations belong to the detail environment, including when another environment is active. */
@@ -41,14 +43,16 @@ function EnabledPullRequestThreadLinks({
4143 reference,
4244 url,
4345 threadRef,
46+ display,
47+ onPickerOpenChange,
4448} : PullRequestThreadLinksProps ) {
4549 const parsed = parseChangeRequestUrl ( url ) ;
4650 const currentThreadRef = threadRef ?. environmentId === environmentId ? threadRef : null ;
4751 const thread = useThreadShell ( currentThreadRef ) ;
4852 const linking = usePullRequestLinking ( environmentId ) ;
4953 const linkedHere = linking . isLinked ( thread , url ) ;
5054 const relations = useEnvironmentQuery (
51- linking . mode === "multiple"
55+ linking . mode === "multiple" && display !== "menu-item"
5256 ? pullRequestEnvironment . linkedThreads ( {
5357 environmentId,
5458 input : parsed === null ? reference : { ...reference , ...parsed } ,
@@ -61,7 +65,6 @@ function EnabledPullRequestThreadLinks({
6165 if ( relations . data !== null && relations . data !== lastRelations ) {
6266 setLastRelations ( relations . data ) ;
6367 }
64- const [ pickerOpen , setPickerOpen ] = useState ( false ) ;
6568 const [ pending , setPending ] = useState ( false ) ;
6669
6770 const changeLink = async ( threadId : ThreadId , remove : boolean ) => {
@@ -80,7 +83,7 @@ function EnabledPullRequestThreadLinks({
8083 setPending ( false ) ;
8184 }
8285 relations . refresh ( ) ;
83- setPickerOpen ( false ) ;
86+ onPickerOpenChange ?. ( false ) ;
8487 } ;
8588
8689 if ( parsed === null || ( ! linkedHere && ! linking . canLink ( url ) ) ) return null ;
@@ -92,7 +95,7 @@ function EnabledPullRequestThreadLinks({
9295 : "Linked threads" ;
9396 return (
9497 < >
95- { linkedThreads . length > 0 || relations . error !== null ? (
98+ { display === "count" && ( linkedThreads . length > 0 || relations . error !== null ) ? (
9699 < Menu >
97100 < MenuTrigger
98101 render = {
@@ -135,47 +138,42 @@ function EnabledPullRequestThreadLinks({
135138 </ MenuPopup >
136139 </ Menu >
137140 ) : null }
138- { currentThreadRef !== null ? (
139- < Button
140- size = "xs"
141- variant = "outline"
141+ { display === "menu-item" ? (
142+ < MenuItem
142143 disabled = { pending }
143- onClick = { ( ) => void changeLink ( currentThreadRef . threadId , linkedHere ) }
144- aria-label = { linkedHere ? "Unlink from this thread" : "Link to this thread" }
144+ onClick = { ( ) => {
145+ if ( currentThreadRef !== null ) {
146+ void changeLink ( currentThreadRef . threadId , linkedHere ) ;
147+ } else {
148+ onPickerOpenChange ?.( true ) ;
149+ }
150+ } }
145151 >
146152 { linkedHere ? (
147153 < UnlinkIcon aria-hidden className = "size-3.5" />
148154 ) : (
149155 < LinkIcon aria-hidden className = "size-3.5" />
150156 ) }
151- < span className = "@max-[40rem]/pr-header:hidden" >
152- { linkedHere ? "Unlink from thread" : "Link to thread" }
153- </ span >
154- </ Button >
155- ) : (
156- < Button
157- size = "xs"
158- variant = "outline"
159- onClick = { ( ) => setPickerOpen ( true ) }
160- aria-label = "Link to thread"
161- >
162- < LinkIcon aria-hidden className = "size-3.5" />
163- < span className = "@max-[40rem]/pr-header:hidden" > Link to thread</ span >
164- </ Button >
165- ) }
166- < Dialog open = { pickerOpen } onOpenChange = { setPickerOpen } >
167- < DialogPopup className = "max-w-md" showCloseButton = { false } >
168- < DialogTitle className = "sr-only" > Link pull request to a thread</ DialogTitle >
169- { pickerOpen ? (
157+ { linkedHere
158+ ? "Unlink from this thread"
159+ : currentThreadRef
160+ ? "Link to this thread"
161+ : "Link to thread" }
162+ </ MenuItem >
163+ ) : null }
164+ { display === "picker" ? (
165+ < Dialog open onOpenChange = { onPickerOpenChange } >
166+ < DialogPopup className = "max-w-md" showCloseButton = { false } >
167+ < DialogTitle className = "sr-only" > Link pull request to a thread</ DialogTitle >
170168 < ThreadPicker
171169 environmentId = { environmentId }
172170 url = { url }
173171 pending = { pending }
174172 onSelect = { ( threadId ) => void changeLink ( threadId , false ) }
175173 />
176- ) : null }
177- </ DialogPopup >
178- </ Dialog >
174+ </ DialogPopup >
175+ </ Dialog >
176+ ) : null }
179177 </ >
180178 ) ;
181179}
0 commit comments