1
- import { makeStyles } from "@material-ui/core/styles"
1
+ import { makeStyles , Theme , useTheme } from "@material-ui/core/styles"
2
2
import { Skeleton } from "@material-ui/lab"
3
3
import { PortForwardButton } from "components/PortForwardButton/PortForwardButton"
4
4
import { FC , useState } from "react"
5
- import { Workspace , WorkspaceResource } from "../../api/typesGenerated"
5
+ import {
6
+ Workspace ,
7
+ WorkspaceAgent ,
8
+ WorkspaceAgentStatus ,
9
+ WorkspaceResource ,
10
+ } from "../../api/typesGenerated"
6
11
import { AppLink } from "../AppLink/AppLink"
7
12
import { SSHButton } from "../SSHButton/SSHButton"
8
13
import { Stack } from "../Stack/Stack"
@@ -19,6 +24,23 @@ import IconButton from "@material-ui/core/IconButton"
19
24
import Tooltip from "@material-ui/core/Tooltip"
20
25
import { Maybe } from "components/Conditionals/Maybe"
21
26
27
+ const getAgentStatusColor = ( theme : Theme , agent : WorkspaceAgent ) => {
28
+ switch ( agent . status ) {
29
+ case "connected" :
30
+ return theme . palette . success . light
31
+ case "connecting" :
32
+ return theme . palette . info . light
33
+ case "disconnected" :
34
+ return theme . palette . text . secondary
35
+ }
36
+ }
37
+
38
+ const agentStatusLabels : Record < WorkspaceAgentStatus , string > = {
39
+ connected : "Connected" ,
40
+ connecting : "Connecting..." ,
41
+ disconnected : "Disconnected" ,
42
+ }
43
+
22
44
export interface ResourceCardProps {
23
45
resource : WorkspaceResource
24
46
workspace : Workspace
@@ -36,6 +58,7 @@ export const ResourceCard: FC<ResourceCardProps> = ({
36
58
hideSSHButton,
37
59
serverVersion,
38
60
} ) => {
61
+ const theme = useTheme < Theme > ( )
39
62
const [ shouldDisplayAllMetadata , setShouldDisplayAllMetadata ] =
40
63
useState ( false )
41
64
const styles = useStyles ( )
@@ -110,6 +133,9 @@ export const ResourceCard: FC<ResourceCardProps> = ({
110
133
111
134
< div >
112
135
{ resource . agents ?. map ( ( agent ) => {
136
+ const statusColor = getAgentStatusColor ( theme , agent )
137
+ const statusLabel = agentStatusLabels [ agent . status ]
138
+
113
139
return (
114
140
< Stack
115
141
key = { agent . id }
@@ -119,7 +145,13 @@ export const ResourceCard: FC<ResourceCardProps> = ({
119
145
className = { styles . agentRow }
120
146
>
121
147
< Stack direction = "row" alignItems = "baseline" >
122
- < div role = "status" className = { styles . agentStatus } />
148
+ < Tooltip title = { statusLabel } >
149
+ < div
150
+ role = "status"
151
+ className = { styles . agentStatus }
152
+ style = { { backgroundColor : statusColor } }
153
+ />
154
+ </ Tooltip >
123
155
< div >
124
156
< div className = { styles . agentName } > { agent . name } </ div >
125
157
< Stack
@@ -248,7 +280,6 @@ const useStyles = makeStyles((theme) => ({
248
280
agentStatus : {
249
281
width : theme . spacing ( 1 ) ,
250
282
height : theme . spacing ( 1 ) ,
251
- backgroundColor : theme . palette . success . light ,
252
283
borderRadius : "100%" ,
253
284
} ,
254
285
0 commit comments