@@ -38,6 +38,7 @@ import * as DateTime from "effect/DateTime";
3838import * as Option from "effect/Option" ;
3939
4040import { useCopyToClipboard } from "../../hooks/useCopyToClipboard" ;
41+ import { useClientSettings , useUpdateClientSettings } from "../../hooks/useSettings" ;
4142import { cn } from "../../lib/utils" ;
4243import { formatElapsedDurationLabel , formatExpiresInLabel } from "../../timestampFormat" ;
4344import { resolveDesktopPairingUrl , resolveHostedPairingUrl } from "./pairingUrls" ;
@@ -1340,13 +1341,15 @@ type SavedBackendListRowProps = {
13401341 environment : EnvironmentPresentation ;
13411342 removingEnvironmentId : EnvironmentId | null ;
13421343 onConnect : ( environmentId : EnvironmentId ) => void ;
1344+ onRename : ( environment : EnvironmentPresentation ) => void ;
13431345 onRemove : ( environmentId : EnvironmentId ) => void ;
13441346} ;
13451347
13461348function SavedBackendListRow ( {
13471349 environment,
13481350 removingEnvironmentId,
13491351 onConnect,
1352+ onRename,
13501353 onRemove,
13511354} : SavedBackendListRowProps ) {
13521355 const environmentId = environment . environmentId ;
@@ -1389,14 +1392,12 @@ function SavedBackendListRow({
13891392 [ copyTraceIdToClipboard ] ,
13901393 ) ;
13911394 const versionMismatch = resolveServerConfigVersionMismatch ( environment . serverConfig ) ;
1392- const sshTarget =
1393- environment . entry . target . _tag === "SshConnectionTarget" &&
1394- Option . isSome ( environment . entry . profile ) &&
1395- environment . entry . profile . value . _tag === "SshConnectionProfile"
1396- ? environment . entry . profile . value . target
1397- : null ;
13981395 const metadataBits = [
1399- sshTarget ? `SSH ${ formatDesktopSshTarget ( sshTarget ) } ` : null ,
1396+ environment . displayUrl
1397+ ? environment . entry . target . _tag === "SshConnectionTarget"
1398+ ? `SSH ${ environment . displayUrl } `
1399+ : environment . displayUrl
1400+ : null ,
14001401 environment . relayManaged ? "T3 Connect" : null ,
14011402 ] . filter ( ( value ) : value is string => value !== null ) ;
14021403
@@ -1456,6 +1457,9 @@ function SavedBackendListRow({
14561457 ) : null }
14571458 </ div >
14581459 < div className = "flex w-full shrink-0 items-center gap-2 sm:w-auto sm:justify-end" >
1460+ < Button size = "xs" variant = "outline" onClick = { ( ) => onRename ( environment ) } >
1461+ Rename
1462+ </ Button >
14591463 { isWslEnvironment ? (
14601464 < Tooltip >
14611465 < TooltipTrigger
@@ -1713,6 +1717,8 @@ export function ConnectionsSettings() {
17131717 const desktopBridge = window . desktopBridge ;
17141718 const { environments } = useEnvironments ( ) ;
17151719 const primaryEnvironment = usePrimaryEnvironment ( ) ;
1720+ const environmentDisplayNames = useClientSettings ( ( settings ) => settings . environmentDisplayNames ) ;
1721+ const updateClientSettings = useUpdateClientSettings ( ) ;
17161722 const connectPairing = useAtomCommand ( connectPairingAtom , { reportFailure : false } ) ;
17171723 const connectSshEnvironment = useAtomCommand ( connectSshEnvironmentAtom , {
17181724 reportFailure : false ,
@@ -1796,6 +1802,9 @@ export function ConnectionsSettings() {
17961802 const [ isAddingSavedBackend , setIsAddingSavedBackend ] = useState ( false ) ;
17971803 const [ removingSavedEnvironmentId , setRemovingSavedEnvironmentId ] =
17981804 useState < EnvironmentId | null > ( null ) ;
1805+ const [ renameEnvironmentTarget , setRenameEnvironmentTarget ] =
1806+ useState < EnvironmentPresentation | null > ( null ) ;
1807+ const [ renameEnvironmentValue , setRenameEnvironmentValue ] = useState ( "" ) ;
17991808 const [ isUpdatingDesktopServerExposure , setIsUpdatingDesktopServerExposure ] = useState ( false ) ;
18001809 const [ isDesktopServerExposureDialogOpen , setIsDesktopServerExposureDialogOpen ] = useState ( false ) ;
18011810 const [ isUpdatingTailscaleServe , setIsUpdatingTailscaleServe ] = useState ( false ) ;
@@ -2121,7 +2130,7 @@ export function ConnectionsSettings() {
21212130 return ;
21222131 }
21232132
2124- const result = await connectSshEnvironment ( { target, label : "" } ) ;
2133+ const result = await connectSshEnvironment ( { target, label : target . alias } ) ;
21252134 if ( result . _tag === "Failure" ) {
21262135 if ( ! isAtomCommandInterrupted ( result ) ) {
21272136 setSavedBackendError ( formatDesktopSshConnectionError ( squashAtomCommandFailure ( result ) ) ) ;
@@ -2228,6 +2237,41 @@ export function ConnectionsSettings() {
22282237 [ retryEnvironment ] ,
22292238 ) ;
22302239
2240+ const handleStartRenameEnvironment = useCallback (
2241+ ( environment : EnvironmentPresentation ) => {
2242+ setRenameEnvironmentTarget ( environment ) ;
2243+ setRenameEnvironmentValue ( environmentDisplayNames [ environment . environmentId ] ?? "" ) ;
2244+ } ,
2245+ [ environmentDisplayNames ] ,
2246+ ) ;
2247+
2248+ const handleCloseRenameEnvironment = useCallback ( ( ) => {
2249+ setRenameEnvironmentTarget ( null ) ;
2250+ setRenameEnvironmentValue ( "" ) ;
2251+ } , [ ] ) ;
2252+
2253+ const handleSaveRenameEnvironment = useCallback ( ( ) => {
2254+ if ( ! renameEnvironmentTarget ) {
2255+ return ;
2256+ }
2257+ const environmentId = renameEnvironmentTarget . environmentId ;
2258+ const displayName = renameEnvironmentValue . trim ( ) ;
2259+ const nextDisplayNames = { ...environmentDisplayNames } ;
2260+ if ( displayName === "" ) {
2261+ delete nextDisplayNames [ environmentId ] ;
2262+ } else {
2263+ nextDisplayNames [ environmentId ] = displayName ;
2264+ }
2265+ updateClientSettings ( { environmentDisplayNames : nextDisplayNames } ) ;
2266+ handleCloseRenameEnvironment ( ) ;
2267+ } , [
2268+ environmentDisplayNames ,
2269+ handleCloseRenameEnvironment ,
2270+ renameEnvironmentTarget ,
2271+ renameEnvironmentValue ,
2272+ updateClientSettings ,
2273+ ] ) ;
2274+
22312275 const handleRemoveSavedBackend = useCallback (
22322276 async ( environmentId : EnvironmentId ) => {
22332277 setRemovingSavedEnvironmentId ( environmentId ) ;
@@ -3385,6 +3429,7 @@ export function ConnectionsSettings() {
33853429 environment = { environment }
33863430 removingEnvironmentId = { removingSavedEnvironmentId }
33873431 onConnect = { handleConnectSavedBackend }
3432+ onRename = { handleStartRenameEnvironment }
33883433 onRemove = { handleRemoveSavedBackend }
33893434 />
33903435 ) ) }
@@ -3393,6 +3438,52 @@ export function ConnectionsSettings() {
33933438 savedEnvironments = { savedEnvironments }
33943439 />
33953440 </ SettingsSection >
3441+ < Dialog
3442+ open = { renameEnvironmentTarget !== null }
3443+ onOpenChange = { ( open ) => {
3444+ if ( ! open ) {
3445+ handleCloseRenameEnvironment ( ) ;
3446+ }
3447+ } }
3448+ >
3449+ < DialogPopup className = "max-w-md" >
3450+ < DialogHeader >
3451+ < DialogTitle > Rename environment</ DialogTitle >
3452+ < DialogDescription >
3453+ Set an optional name for this client. Leave it empty to use the environment’s default
3454+ name.
3455+ </ DialogDescription >
3456+ </ DialogHeader >
3457+ < DialogPanel className = "space-y-4" >
3458+ < label className = "grid gap-1.5" >
3459+ < span className = "text-xs font-medium text-foreground" > Display name</ span >
3460+ < Input
3461+ autoFocus
3462+ value = { renameEnvironmentValue }
3463+ placeholder = { renameEnvironmentTarget ?. defaultLabel }
3464+ onChange = { ( event ) => setRenameEnvironmentValue ( event . target . value ) }
3465+ onKeyDown = { ( event ) => {
3466+ if ( event . key === "Enter" ) {
3467+ event . preventDefault ( ) ;
3468+ handleSaveRenameEnvironment ( ) ;
3469+ }
3470+ } }
3471+ />
3472+ </ label >
3473+ { renameEnvironmentTarget ?. displayUrl ? (
3474+ < p className = "truncate text-xs text-muted-foreground" >
3475+ { renameEnvironmentTarget . displayUrl }
3476+ </ p >
3477+ ) : null }
3478+ </ DialogPanel >
3479+ < DialogFooter >
3480+ < Button variant = "outline" onClick = { handleCloseRenameEnvironment } >
3481+ Cancel
3482+ </ Button >
3483+ < Button onClick = { handleSaveRenameEnvironment } > Save</ Button >
3484+ </ DialogFooter >
3485+ </ DialogPopup >
3486+ </ Dialog >
33963487 </ SettingsPageContainer >
33973488 ) ;
33983489}
0 commit comments