@@ -18,6 +18,7 @@ import { ConnectionStatusDot } from "../ConnectionStatusDot";
1818import { Button } from "../ui/button" ;
1919import {
2020 Dialog ,
21+ DialogClose ,
2122 DialogDescription ,
2223 DialogFooter ,
2324 DialogHeader ,
@@ -30,19 +31,13 @@ import { Input } from "../ui/input";
3031import { RadioGroup } from "../ui/radio-group" ;
3132import { stackedThreadToast , toastManager } from "../ui/toast" ;
3233import { ITEM_ROW_CLASSNAME , ITEM_ROW_INNER_CLASSNAME } from "./itemRows" ;
33- import { SettingsRow , SettingsSection , useRelativeTimeTick } from "./settingsLayout" ;
34+ import { SettingsRow , SettingsSection } from "./settingsLayout" ;
35+ import { useNowMinute } from "../../hooks/useNowMinute" ;
3436import { searchableSetting } from "./settingsSearch" ;
3537
3638const failureToast = ( title : string , description : string ) =>
3739 toastManager . add ( stackedThreadToast ( { type : "error" , title, description } ) ) ;
3840
39- /**
40- * Other environments this one links to, so its agents can work there. Each
41- * link is an outside agent session on the other environment, revoked from
42- * that environment's own Connections. `environmentLabel` names the linking
43- * environment when several are listed; only the first section is the search
44- * target.
45- */
4641export function LinkedEnvironmentsSettings ( {
4742 environmentId,
4843 environmentLabel,
@@ -90,8 +85,8 @@ function LinkedEnvironmentRow({
9085 readonly environmentId : EnvironmentId ;
9186 readonly link : PeerLinkSummary ;
9287} ) {
93- const nowMs = useRelativeTimeTick ( 60_000 ) ;
94- const health = peerLinkHealth ( link , DateTime . makeUnsafe ( nowMs ) ) ;
88+ const nowMinute = useNowMinute ( ) ;
89+ const health = peerLinkHealth ( link , DateTime . makeUnsafe ( nowMinute ) ) ;
9590 const unlink = useAtomCommand ( peerLinkEnvironment . unlink , { label : "unlink environment" } ) ;
9691 const canUnlink = useAtomValue ( peerLinkEnvironment . unlink . permissionAtom ( environmentId ) ) ;
9792 const [ busy , setBusy ] = useState ( false ) ;
@@ -169,10 +164,13 @@ function LinkEnvironmentAction({ environmentId }: { readonly environmentId: Envi
169164 const formId = useId ( ) ;
170165 const accessLabelId = `${ formId } -access` ;
171166 const link = useAtomCommand ( peerLinkEnvironment . link , { label : "link environment" } ) ;
172- const reset = ( ) => {
173- setUrl ( "" ) ;
174- setPairingCode ( "" ) ;
175- setAccess ( "approval-required" ) ;
167+ const handleOpenChange = ( next : boolean ) => {
168+ setOpen ( next ) ;
169+ if ( ! next ) {
170+ setUrl ( "" ) ;
171+ setPairingCode ( "" ) ;
172+ setAccess ( "approval-required" ) ;
173+ }
176174 } ;
177175 const submit = async ( ) => {
178176 setBusy ( true ) ;
@@ -183,8 +181,7 @@ function LinkEnvironmentAction({ environmentId }: { readonly environmentId: Envi
183181 setBusy ( false ) ;
184182 if ( result . _tag === "Success" ) {
185183 toastManager . add ( { type : "success" , title : `Linked ${ result . value . label } ` } ) ;
186- reset ( ) ;
187- setOpen ( false ) ;
184+ handleOpenChange ( false ) ;
188185 } else if ( ! isAtomCommandInterrupted ( result ) ) {
189186 failureToast ( "Could not link the environment" , String ( squashAtomCommandFailure ( result ) ) ) ;
190187 }
@@ -193,10 +190,8 @@ function LinkEnvironmentAction({ environmentId }: { readonly environmentId: Envi
193190 < Dialog
194191 open = { open }
195192 onOpenChange = { ( next ) => {
196- // A link that finishes after a close would still be made, and would close a reopened form.
197193 if ( ! next && busy ) return ;
198- setOpen ( next ) ;
199- if ( ! next ) reset ( ) ;
194+ handleOpenChange ( next ) ;
200195 } }
201196 >
202197 < DialogTrigger
@@ -254,6 +249,7 @@ function LinkEnvironmentAction({ environmentId }: { readonly environmentId: Envi
254249 </ span >
255250 < RadioGroup
256251 aria-labelledby = { accessLabelId }
252+ disabled = { busy }
257253 value = { access }
258254 onValueChange = { ( value ) => setAccess ( value as AuthMcpClientAccess ) }
259255 >
@@ -262,16 +258,17 @@ function LinkEnvironmentAction({ environmentId }: { readonly environmentId: Envi
262258 ) ) }
263259 </ RadioGroup >
264260 < p className = "text-xs text-muted-foreground" >
265- An agent here never gets more there than its own mode here either. Threads it starts
266- there cannot change that environment's own threads, projects or settings.
261+ An agent never gets more access there than its own mode here. Below full access, it
262+ can change only threads this link started, not that environment's own threads,
263+ projects or settings.
267264 </ p >
268265 </ div >
269266 </ form >
270267 </ DialogPanel >
271268 < DialogFooter variant = "bare" >
272- < Button variant = "outline" type = "button" disabled = { busy } onClick = { ( ) => setOpen ( false ) } >
269+ < DialogClose disabled = { busy } render = { < Button variant = "outline" type = "button" /> } >
273270 Cancel
274- </ Button >
271+ </ DialogClose >
275272 < Button
276273 form = { formId }
277274 type = "submit"
0 commit comments