@@ -22,6 +22,7 @@ interface InstalledScript {
2222 installation_date : string ;
2323 status : 'in_progress' | 'success' | 'failed' ;
2424 output_log : string | null ;
25+ container_status ?: 'running' | 'stopped' | 'unknown' ;
2526}
2627
2728export function InstalledScriptsTab ( ) {
@@ -40,6 +41,7 @@ export function InstalledScriptsTab() {
4041 const [ autoDetectStatus , setAutoDetectStatus ] = useState < { type : 'success' | 'error' | null ; message : string } > ( { type : null , message : '' } ) ;
4142 const [ cleanupStatus , setCleanupStatus ] = useState < { type : 'success' | 'error' | null ; message : string } > ( { type : null , message : '' } ) ;
4243 const cleanupRunRef = useRef ( false ) ;
44+ const [ containerStatuses , setContainerStatuses ] = useState < Record < string , 'running' | 'stopped' | 'unknown' > > ( { } ) ;
4345
4446 // Fetch installed scripts
4547 const { data : scriptsData , refetch : refetchScripts , isLoading } = api . installedScripts . getAllInstalledScripts . useQuery ( ) ;
@@ -114,6 +116,18 @@ export function InstalledScriptsTab() {
114116 }
115117 } ) ;
116118
119+ // Get container statuses mutation
120+ const containerStatusMutation = api . installedScripts . getContainerStatuses . useMutation ( {
121+ onSuccess : ( data ) => {
122+ if ( data . success ) {
123+ setContainerStatuses ( data . statusMap ) ;
124+ }
125+ } ,
126+ onError : ( error ) => {
127+ console . error ( 'Error fetching container statuses:' , error ) ;
128+ }
129+ } ) ;
130+
117131 // Cleanup orphaned scripts mutation
118132 const cleanupMutation = api . installedScripts . cleanupOrphanedScripts . useMutation ( {
119133 onSuccess : ( data ) => {
@@ -149,6 +163,28 @@ export function InstalledScriptsTab() {
149163 const scripts : InstalledScript [ ] = ( scriptsData ?. scripts as InstalledScript [ ] ) ?? [ ] ;
150164 const stats = statsData ?. stats ;
151165
166+ // Function to fetch container statuses
167+ const fetchContainerStatuses = ( ) => {
168+ const containersWithIds = scripts
169+ . filter ( script => script . container_id )
170+ . map ( script => ( {
171+ containerId : script . container_id ! ,
172+ serverId : script . server_id ?? undefined ,
173+ server : script . server_id ? {
174+ id : script . server_id ,
175+ name : script . server_name ! ,
176+ ip : script . server_ip ! ,
177+ user : script . server_user ! ,
178+ password : script . server_password ! ,
179+ auth_type : 'password' // Default to password auth
180+ } : undefined
181+ } ) ) ;
182+
183+ if ( containersWithIds . length > 0 ) {
184+ containerStatusMutation . mutate ( { containers : containersWithIds } ) ;
185+ }
186+ } ;
187+
152188 // Run cleanup when component mounts and scripts are loaded (only once)
153189 useEffect ( ( ) => {
154190 if ( scripts . length > 0 && serversData ?. servers && ! cleanupMutation . isPending && ! cleanupRunRef . current ) {
@@ -158,8 +194,23 @@ export function InstalledScriptsTab() {
158194 }
159195 } , [ scripts . length , serversData ?. servers , cleanupMutation ] ) ;
160196
197+ // Auto-refresh container statuses every 60 seconds
198+ useEffect ( ( ) => {
199+ if ( scripts . length > 0 ) {
200+ fetchContainerStatuses ( ) ; // Initial fetch
201+ const interval = setInterval ( fetchContainerStatuses , 60000 ) ; // Every 60 seconds
202+ return ( ) => clearInterval ( interval ) ;
203+ }
204+ } , [ scripts . length ] ) ;
205+
206+ // Update scripts with container statuses
207+ const scriptsWithStatus = scripts . map ( script => ( {
208+ ...script ,
209+ container_status : script . container_id ? containerStatuses [ script . container_id ] || 'unknown' : undefined
210+ } ) ) ;
211+
161212 // Filter and sort scripts
162- const filteredScripts = scripts
213+ const filteredScripts = scriptsWithStatus
163214 . filter ( ( script : InstalledScript ) => {
164215 const matchesSearch = script . script_name . toLowerCase ( ) . includes ( searchTerm . toLowerCase ( ) ) ||
165216 ( script . container_id ?. includes ( searchTerm ) ?? false ) ||
@@ -810,7 +861,27 @@ export function InstalledScriptsTab() {
810861 />
811862 ) : (
812863 script . container_id ? (
813- < span className = "text-sm font-mono text-foreground" > { String ( script . container_id ) } </ span >
864+ < div className = "flex items-center space-x-2" >
865+ < span className = "text-sm font-mono text-foreground" > { String ( script . container_id ) } </ span >
866+ { script . container_status && (
867+ < div className = "flex items-center space-x-1" >
868+ < div className = { `w-2 h-2 rounded-full ${
869+ script . container_status === 'running' ? 'bg-green-500' :
870+ script . container_status === 'stopped' ? 'bg-red-500' :
871+ 'bg-gray-400'
872+ } `} > </ div >
873+ < span className = { `text-xs font-medium ${
874+ script . container_status === 'running' ? 'text-green-700 dark:text-green-300' :
875+ script . container_status === 'stopped' ? 'text-red-700 dark:text-red-300' :
876+ 'text-gray-500 dark:text-gray-400'
877+ } `} >
878+ { script . container_status === 'running' ? 'Running' :
879+ script . container_status === 'stopped' ? 'Stopped' :
880+ 'Unknown' }
881+ </ span >
882+ </ div >
883+ ) }
884+ </ div >
814885 ) : (
815886 < span className = "text-sm text-muted-foreground" > -</ span >
816887 )
0 commit comments