1
1
import makeStyles from "@mui/styles/makeStyles"
2
2
import { watchAgentMetadata } from "api/api"
3
+ import Popover from "@mui/material/Popover"
3
4
import { WorkspaceAgent , WorkspaceAgentMetadata } from "api/typesGenerated"
4
5
import { Stack } from "components/Stack/Stack"
5
6
import dayjs from "dayjs"
6
7
import {
7
8
createContext ,
8
9
FC ,
10
+ Ref ,
9
11
useContext ,
10
12
useEffect ,
11
13
useRef ,
@@ -21,6 +23,42 @@ type ItemStatus = "stale" | "valid" | "loading"
21
23
22
24
export const WatchAgentMetadataContext = createContext ( watchAgentMetadata )
23
25
26
+ const MetadataTerminalPopover : FC < {
27
+ id : string
28
+ body : string
29
+ } > = ( { id, body } ) => {
30
+ const styles = useStyles ( )
31
+
32
+ const ref = useRef < HTMLDivElement > ( null )
33
+ const [ open , setOpen ] = useState ( false )
34
+
35
+ return (
36
+ < >
37
+ < div
38
+ className = { styles . inlineCommand }
39
+ ref = { ref }
40
+ onMouseEnter = { ( ) => setOpen ( true ) }
41
+ onMouseLeave = { ( ) => setOpen ( false ) }
42
+ >
43
+ View Terminal
44
+ </ div >
45
+
46
+ < Popover
47
+ id = { id }
48
+ open = { open }
49
+ anchorEl = { ref . current }
50
+ anchorOrigin = { {
51
+ vertical : "bottom" ,
52
+ horizontal : "left" ,
53
+ } }
54
+ classes = { { paper : styles . popover } }
55
+ >
56
+ < Box p = { 1 } > { body } </ Box >
57
+ </ Popover >
58
+ </ >
59
+ )
60
+ }
61
+
24
62
const MetadataItem : FC < { item : WorkspaceAgentMetadata } > = ( { item } ) => {
25
63
const styles = useStyles ( )
26
64
@@ -31,6 +69,13 @@ const MetadataItem: FC<{ item: WorkspaceAgentMetadata }> = ({ item }) => {
31
69
throw new Error ( "Metadata item description is undefined" )
32
70
}
33
71
72
+ const terminalPrefix = "terminal:"
73
+ const isTerminal = item . description . display_name . startsWith ( terminalPrefix )
74
+
75
+ const displayName = isTerminal
76
+ ? item . description . display_name . slice ( terminalPrefix . length )
77
+ : item . description . display_name
78
+
34
79
const staleThreshold = Math . max (
35
80
item . description . interval + item . description . timeout * 2 ,
36
81
5 ,
@@ -87,10 +132,15 @@ const MetadataItem: FC<{ item: WorkspaceAgentMetadata }> = ({ item }) => {
87
132
88
133
return (
89
134
< div className = { styles . metadata } >
90
- < div className = { styles . metadataLabel } >
91
- { item . description . display_name }
92
- </ div >
93
- < Box > { value } </ Box >
135
+ < div className = { styles . metadataLabel } > { displayName } </ div >
136
+ { isTerminal ? (
137
+ < MetadataTerminalPopover
138
+ id = { `metadata-terminal-${ item . description . key } ` }
139
+ body = { item . description . script }
140
+ />
141
+ ) : (
142
+ < Box > { value } </ Box >
143
+ ) }
94
144
</ div >
95
145
)
96
146
}
@@ -104,6 +154,7 @@ export const AgentMetadataView: FC<AgentMetadataViewProps> = ({ metadata }) => {
104
154
if ( metadata . length === 0 ) {
105
155
return < > </ >
106
156
}
157
+
107
158
return (
108
159
< div className = { styles . root } >
109
160
< Stack alignItems = "baseline" direction = "row" spacing = { 6 } >
@@ -227,6 +278,13 @@ const useStyles = makeStyles((theme) => ({
227
278
scrollPadding : theme . spacing ( 0 , 4 ) ,
228
279
} ,
229
280
281
+ popover : {
282
+ padding : 0 ,
283
+ width : theme . spacing ( 38 ) ,
284
+ color : theme . palette . text . secondary ,
285
+ marginTop : theme . spacing ( 0.5 ) ,
286
+ } ,
287
+
230
288
metadata : {
231
289
fontSize : 12 ,
232
290
lineHeight : "normal" ,
0 commit comments