@@ -25,9 +25,15 @@ import {
2525 formatWorkingDurationLabel ,
2626 resolveThreadWorkingStartedAt ,
2727} from "@t3tools/client-runtime/state/models" ;
28- import { AuthOrchestrationOperateScope , type EnvironmentMachineKind } from "@t3tools/contracts" ;
28+ import {
29+ AuthOrchestrationOperateScope ,
30+ type EnvironmentId ,
31+ type EnvironmentMachineKind ,
32+ } from "@t3tools/contracts" ;
2933import { canSnooze , resolveSnoozePresets } from "@t3tools/client-runtime/state/thread-settled" ;
34+ import { useAtomValue } from "@effect/atom-react" ;
3035import type { MenuAction } from "@react-native-menu/menu" ;
36+ import { Atom } from "effect/reactivity" ;
3137import { memo , useCallback , useEffect , useMemo , useState , type ComponentProps } from "react" ;
3238import { Pressable , useWindowDimensions , View } from "react-native" ;
3339import type { SwipeableMethods } from "react-native-gesture-handler/ReanimatedSwipeable" ;
@@ -42,7 +48,8 @@ import { ProviderIcon, ProviderInstanceIcon } from "../../components/ProviderIco
4248import { cn } from "../../lib/cn" ;
4349import { copyTextWithHaptic } from "../../lib/copyTextWithHaptic" ;
4450import { useUniwindTheme } from "../../lib/useUniwindTheme" ;
45- import { useEnvironmentScope } from "../../state/session" ;
51+ import { environmentPresentations } from "../../state/presentation" ;
52+ import { useEnvironmentScopeAccess } from "../../state/session" ;
4653import type { PendingNewTask } from "../../state/use-pending-new-tasks" ;
4754import {
4855 resolveThreadPrBadgeAction ,
@@ -60,6 +67,9 @@ import {
6067 resolveThreadListV2Status ,
6168 resolveThreadListV2ProviderDrivers ,
6269 resolveThreadListV2SwipeActions ,
70+ resolveThreadListV2ConnectionIssue ,
71+ resolveThreadListV2LockedReason ,
72+ THREAD_LIST_V2_CONNECTION_ISSUE_LABEL ,
6373 type ThreadListV2Status ,
6474} from "./threadListV2" ;
6575import { QueuedMessageIcon } from "./queued-message-icon" ;
@@ -68,6 +78,15 @@ import { ThreadSearchMatchExcerpt } from "./thread-search-match";
6878import { PullRequestGlyph } from "../pull-requests/pullRequestGlyphs" ;
6979import { pullRequestStatus } from "../pull-requests/pullRequestStatus" ;
7080
81+ // A string, so rows re-render only when the issue changes, not on every catalog update.
82+ const environmentConnectionIssueAtom = Atom . family ( ( environmentId : EnvironmentId ) =>
83+ Atom . make ( ( get ) =>
84+ resolveThreadListV2ConnectionIssue (
85+ get ( environmentPresentations . presentationAtom ( environmentId ) ) ?. connection ?? null ,
86+ ) ,
87+ ) ,
88+ ) ;
89+
7190const TITLE_FAVICON_SIZE = 15 ;
7291// Centers the favicon on the first line of the text-base title.
7392const TITLE_FAVICON_OFFSET = 4 ;
@@ -681,7 +700,14 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
681700
682701 const handleDelete = useCallback ( ( ) => onDeleteThread ( thread ) , [ onDeleteThread , thread ] ) ;
683702 const handleRename = useCallback ( ( ) => onRenameThread ( thread ) , [ onRenameThread , thread ] ) ;
684- const canOperateThread = useEnvironmentScope ( thread . environmentId , AuthOrchestrationOperateScope ) ;
703+ const operateAccess = useEnvironmentScopeAccess (
704+ thread . environmentId ,
705+ AuthOrchestrationOperateScope ,
706+ ) ;
707+ const canOperateThread = operateAccess === "granted" ;
708+ const connectionIssue = useAtomValue ( environmentConnectionIssueAtom ( thread . environmentId ) ) ;
709+ const connectionLabel =
710+ connectionIssue === null ? null : THREAD_LIST_V2_CONNECTION_ISSUE_LABEL [ connectionIssue ] ;
685711 const handleRegenerateTitle = useCallback (
686712 ( ) => onRegenerateThreadTitle ( thread ) ,
687713 [ onRegenerateThreadTitle , thread ] ,
@@ -995,8 +1021,16 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
9951021 : null ,
9961022 [ handleMenuAction , snoozePresetActions , swipeActions . secondary , thread . title ] ,
9971023 ) ;
1024+ const lockedMenuTitle =
1025+ operateAccess === "granted"
1026+ ? ""
1027+ : resolveThreadListV2LockedReason ( {
1028+ access : operateAccess ,
1029+ connectionIssue,
1030+ environmentLabel : props . environmentLabel ?? null ,
1031+ } ) ;
9981032 const swipeAccessibilityHint = ! canOperateThread
999- ? " Opens the thread"
1033+ ? ` Opens the thread. ${ lockedMenuTitle } `
10001034 : secondaryAction === null
10011035 ? `Opens the thread. Swipe left to ${ primaryAction . label . toLowerCase ( ) } .`
10021036 : `Opens the thread. Swipe left for ${ primaryAction . label . toLowerCase ( ) } and snooze actions.` ;
@@ -1121,7 +1155,10 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
11211155 </ View >
11221156 ) : null }
11231157 < View className = "mt-1 flex-row items-center gap-2" style = { { paddingLeft : titleTextInset } } >
1124- { ( status === "failed" || status === "limited" ) && thread . runtime ?. lastError ? (
1158+ { ( status === "failed" || status === "limited" ) &&
1159+ thread . runtime ?. lastError &&
1160+ // A host that dropped explains the row better than its last run's error.
1161+ connectionLabel === null ? (
11251162 < Text
11261163 className = { cn (
11271164 "flex-1 text-xs" ,
@@ -1135,9 +1172,9 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
11351172 >
11361173 { thread . runtime . lastError }
11371174 </ Text >
1138- ) : props . environmentLabel ? (
1175+ ) : props . environmentLabel || connectionLabel ? (
11391176 < View className = "min-w-0 flex-1 flex-row items-center gap-1" >
1140- { props . environmentMachine ? (
1177+ { props . environmentLabel && props . environmentMachine ? (
11411178 < EnvironmentMachineSymbol
11421179 kind = { props . environmentMachine }
11431180 size = { 11 }
@@ -1158,6 +1195,19 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
11581195 numberOfLines = { 1 }
11591196 >
11601197 { props . environmentLabel }
1198+ { props . environmentLabel && connectionLabel ? " · " : null }
1199+ { connectionLabel ? (
1200+ < Text
1201+ className = { cn (
1202+ "text-xs" ,
1203+ selected
1204+ ? selectedThreadRowColors . mutedForegroundClassName
1205+ : "text-warning-foreground" ,
1206+ ) }
1207+ >
1208+ { connectionLabel }
1209+ </ Text >
1210+ ) : null }
11611211 </ Text >
11621212 </ View >
11631213 ) : (
@@ -1328,6 +1378,19 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
13281378 />
13291379 ) : null }
13301380 </ View >
1381+ { connectionLabel ? (
1382+ < Text
1383+ className = { cn (
1384+ "text-xs" ,
1385+ selected
1386+ ? selectedThreadRowColors . mutedForegroundClassName
1387+ : "text-warning-foreground" ,
1388+ ) }
1389+ numberOfLines = { 1 }
1390+ >
1391+ { connectionLabel }
1392+ </ Text >
1393+ ) : null }
13311394 { props . hasQueuedMessages ? < QueuedMessageIcon selected = { selected } /> : null }
13321395 < Text
13331396 className = { cn (
@@ -1349,7 +1412,18 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
13491412 ) ;
13501413
13511414 if ( ! canOperateThread )
1352- return < View style = { rowAppearance . swipeContainerStyle } > { rowContent ( ( ) => { } ) } </ View > ;
1415+ return (
1416+ < View style = { rowAppearance . swipeContainerStyle } >
1417+ < Menu
1418+ title = { lockedMenuTitle }
1419+ actions = { [ { id : "copy-thread-id" , title : "Copy thread ID" , image : "doc.on.doc" } ] }
1420+ onPressAction = { handleMenuAction }
1421+ shouldOpenOnLongPress
1422+ >
1423+ { rowContent ( ( ) => { } ) }
1424+ </ Menu >
1425+ </ View >
1426+ ) ;
13531427
13541428 return (
13551429 < View collapsable = { false } >
0 commit comments