11import { SymbolView } from "../../components/AppSymbol" ;
22import { connectionStatusText } from "@t3tools/client-runtime/connection" ;
33import type { AtomCommandResult } from "@t3tools/client-runtime/state/runtime" ;
4- import type { EnvironmentId } from "@t3tools/contracts" ;
4+ import { AuthOrchestrationOperateScope , type EnvironmentId } from "@t3tools/contracts" ;
55import * as Cause from "effect/Cause" ;
66import { AsyncResult } from "effect/unstable/reactivity" ;
77import { useCallback , useState } from "react" ;
@@ -14,6 +14,7 @@ import { cn } from "../../lib/cn";
1414import { copyTextWithHaptic } from "../../lib/copyTextWithHaptic" ;
1515import type { ConnectedEnvironmentSummary } from "../../state/remote-runtime-types" ;
1616import { ConnectionStatusDot } from "./ConnectionStatusDot" ;
17+ import { useEnvironmentSessionState } from "../../state/session" ;
1718
1819function connectionStatusLabel ( environment : ConnectedEnvironmentSummary ) : string | null {
1920 return connectionStatusText ( {
@@ -29,12 +30,12 @@ export function ConnectionEnvironmentRow(props: {
2930 readonly onToggle : ( ) => void ;
3031 readonly onReconnect : ( environmentId : EnvironmentId ) => void ;
3132 readonly onRemove : ( environmentId : EnvironmentId ) => void ;
33+ readonly onRename : ( environmentId : EnvironmentId ) => void ;
3234 readonly onUpdate : (
3335 environmentId : EnvironmentId ,
3436 updates : { readonly label : string ; readonly displayUrl : string } ,
3537 ) => Promise < AtomCommandResult < unknown , unknown > > ;
3638} ) {
37- const [ label , setLabel ] = useState ( props . environment . environmentLabel ) ;
3839 const [ url , setUrl ] = useState ( props . environment . displayUrl ) ;
3940
4041 const mutedColor = useThemeColor ( "--color-icon-subtle" ) ;
@@ -46,9 +47,16 @@ export function ConnectionEnvironmentRow(props: {
4647 const isRetrying =
4748 props . environment . connectionState === "connecting" ||
4849 props . environment . connectionState === "reconnecting" ;
50+ const sessionState = useEnvironmentSessionState ( props . environment . environmentId ) ;
51+ const canRename =
52+ props . environment . connectionState === "connected" &&
53+ Boolean (
54+ sessionState . data ?. authenticated &&
55+ sessionState . data . scopes ?. includes ( AuthOrchestrationOperateScope ) ,
56+ ) ;
4957 const handleSave = useCallback ( async ( ) => {
5058 const result = await props . onUpdate ( props . environment . environmentId , {
51- label : label . trim ( ) ,
59+ label : "" ,
5260 displayUrl : url . trim ( ) ,
5361 } ) ;
5462 if ( AsyncResult . isSuccess ( result ) ) {
@@ -60,7 +68,7 @@ export function ConnectionEnvironmentRow(props: {
6068 "Could not update environment" ,
6169 error instanceof Error ? error . message : "The environment could not be updated." ,
6270 ) ;
63- } , [ label , url , props ] ) ;
71+ } , [ url , props ] ) ;
6472
6573 return (
6674 < Animated . View layout = { LinearTransition . duration ( 250 ) } className = "bg-card" >
@@ -114,15 +122,30 @@ export function ConnectionEnvironmentRow(props: {
114122 ) : null }
115123 </ View >
116124
117- < SymbolView
118- name = "chevron.down"
119- size = { 12 }
120- tintColor = { mutedColor }
121- type = "monochrome"
122- style = { {
123- transform : [ { rotate : props . expanded ? "180deg" : "0deg" } ] ,
124- } }
125- />
125+ < View className = "flex-row items-center gap-2" >
126+ { canRename ? (
127+ < Pressable
128+ accessibilityLabel = { `Rename ${ props . environment . environmentLabel } ` }
129+ accessibilityRole = "button"
130+ className = "h-8 w-8 items-center justify-center rounded-full active:bg-subtle"
131+ onPress = { ( event ) => {
132+ event . stopPropagation ( ) ;
133+ props . onRename ( props . environment . environmentId ) ;
134+ } }
135+ >
136+ < SymbolView name = "pencil" size = { 13 } tintColor = { mutedColor } type = "monochrome" />
137+ </ Pressable >
138+ ) : null }
139+ < SymbolView
140+ name = "chevron.down"
141+ size = { 12 }
142+ tintColor = { mutedColor }
143+ type = "monochrome"
144+ style = { {
145+ transform : [ { rotate : props . expanded ? "180deg" : "0deg" } ] ,
146+ } }
147+ />
148+ </ View >
126149 </ Pressable >
127150
128151 { props . expanded ? (
@@ -137,20 +160,6 @@ export function ConnectionEnvironmentRow(props: {
137160 </ Text >
138161 ) : (
139162 < >
140- < View className = "gap-1.5" >
141- < Text className = "text-2xs font-t3-bold tracking-[0.8px] uppercase text-foreground-muted" >
142- Label
143- </ Text >
144- < TextInput
145- autoCapitalize = "words"
146- autoCorrect = { false }
147- placeholder = "My MacBook"
148- value = { label }
149- onChangeText = { setLabel }
150- className = "rounded-[14px] border border-input-border bg-input px-4 py-3 text-base text-foreground"
151- />
152- </ View >
153-
154163 < View className = "gap-1.5" >
155164 < Text className = "text-2xs font-t3-bold tracking-[0.8px] uppercase text-foreground-muted" >
156165 URL
0 commit comments