Skip to content

Commit a1b1f7f

Browse files
committed
Improve agent status
1 parent c78e419 commit a1b1f7f

File tree

2 files changed

+97
-41
lines changed

2 files changed

+97
-41
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import Tooltip from "@material-ui/core/Tooltip"
2+
import { makeStyles } from "@material-ui/core/styles"
3+
import { combineClasses } from "util/combineClasses"
4+
import { WorkspaceAgent } from "api/typesGenerated"
5+
import { ChooseOne, Cond } from "components/Conditionals/ChooseOne"
6+
7+
const ConnectedStatus: React.FC = () => {
8+
const styles = useStyles()
9+
10+
return (
11+
<Tooltip title="Connected">
12+
<div
13+
role="status"
14+
className={combineClasses([styles.status, styles.connected])}
15+
/>
16+
</Tooltip>
17+
)
18+
}
19+
20+
const DisconnectedStatus: React.FC = () => {
21+
const styles = useStyles()
22+
23+
return (
24+
<Tooltip title="Disconnected">
25+
<div
26+
role="status"
27+
className={combineClasses([styles.status, styles.disconnected])}
28+
/>
29+
</Tooltip>
30+
)
31+
}
32+
33+
const ConnectingStatus: React.FC = () => {
34+
const styles = useStyles()
35+
36+
return (
37+
<Tooltip title="Connecting...">
38+
<div
39+
role="status"
40+
className={combineClasses([styles.status, styles.connecting])}
41+
/>
42+
</Tooltip>
43+
)
44+
}
45+
46+
export const AgentStatus: React.FC<{ agent: WorkspaceAgent }> = ({ agent }) => {
47+
return (
48+
<ChooseOne>
49+
<Cond condition={agent.status === "connected"}>
50+
<ConnectedStatus />
51+
</Cond>
52+
<Cond condition={agent.status === "disconnected"}>
53+
<DisconnectedStatus />
54+
</Cond>
55+
<Cond>
56+
<ConnectingStatus />
57+
</Cond>
58+
</ChooseOne>
59+
)
60+
}
61+
62+
const useStyles = makeStyles((theme) => ({
63+
status: {
64+
width: theme.spacing(1),
65+
height: theme.spacing(1),
66+
borderRadius: "100%",
67+
},
68+
69+
connected: {
70+
backgroundColor: theme.palette.success.light,
71+
},
72+
73+
disconnected: {
74+
backgroundColor: theme.palette.text.secondary,
75+
},
76+
77+
"@keyframes pulse": {
78+
"0%": {
79+
opacity: 0.25,
80+
},
81+
"50%": {
82+
opacity: 1,
83+
},
84+
"100%": {
85+
opacity: 0.25,
86+
},
87+
},
88+
89+
connecting: {
90+
backgroundColor: theme.palette.info.light,
91+
animation: "$pulse 1s ease-in-out forwards infinite",
92+
},
93+
}))

site/src/components/Resources/ResourceCard.tsx

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
import { makeStyles, Theme, useTheme } from "@material-ui/core/styles"
1+
import { makeStyles } from "@material-ui/core/styles"
22
import { Skeleton } from "@material-ui/lab"
33
import { PortForwardButton } from "components/PortForwardButton/PortForwardButton"
44
import { FC, useState } from "react"
5-
import {
6-
Workspace,
7-
WorkspaceAgent,
8-
WorkspaceAgentStatus,
9-
WorkspaceResource,
10-
} from "../../api/typesGenerated"
5+
import { Workspace, WorkspaceResource } from "../../api/typesGenerated"
116
import { AppLink } from "../AppLink/AppLink"
127
import { SSHButton } from "../SSHButton/SSHButton"
138
import { Stack } from "../Stack/Stack"
@@ -24,23 +19,7 @@ import IconButton from "@material-ui/core/IconButton"
2419
import Tooltip from "@material-ui/core/Tooltip"
2520
import { Maybe } from "components/Conditionals/Maybe"
2621
import { CopyableValue } from "components/CopyableValue/CopyableValue"
27-
28-
const getAgentStatusColor = (theme: Theme, agent: WorkspaceAgent) => {
29-
switch (agent.status) {
30-
case "connected":
31-
return theme.palette.success.light
32-
case "connecting":
33-
return theme.palette.info.light
34-
case "disconnected":
35-
return theme.palette.text.secondary
36-
}
37-
}
38-
39-
const agentStatusLabels: Record<WorkspaceAgentStatus, string> = {
40-
connected: "Connected",
41-
connecting: "Connecting...",
42-
disconnected: "Disconnected",
43-
}
22+
import { AgentStatus } from "./AgentStatus"
4423

4524
export interface ResourceCardProps {
4625
resource: WorkspaceResource
@@ -59,7 +38,6 @@ export const ResourceCard: FC<ResourceCardProps> = ({
5938
hideSSHButton,
6039
serverVersion,
6140
}) => {
62-
const theme = useTheme<Theme>()
6341
const [shouldDisplayAllMetadata, setShouldDisplayAllMetadata] =
6442
useState(false)
6543
const styles = useStyles()
@@ -136,9 +114,6 @@ export const ResourceCard: FC<ResourceCardProps> = ({
136114

137115
<div>
138116
{resource.agents?.map((agent) => {
139-
const statusColor = getAgentStatusColor(theme, agent)
140-
const statusLabel = agentStatusLabels[agent.status]
141-
142117
return (
143118
<Stack
144119
key={agent.id}
@@ -148,13 +123,7 @@ export const ResourceCard: FC<ResourceCardProps> = ({
148123
className={styles.agentRow}
149124
>
150125
<Stack direction="row" alignItems="baseline">
151-
<Tooltip title={statusLabel}>
152-
<div
153-
role="status"
154-
className={styles.agentStatus}
155-
style={{ backgroundColor: statusColor }}
156-
/>
157-
</Tooltip>
126+
<AgentStatus agent={agent} />
158127
<div>
159128
<div className={styles.agentName}>{agent.name}</div>
160129
<Stack
@@ -279,12 +248,6 @@ const useStyles = makeStyles((theme) => ({
279248
},
280249
},
281250

282-
agentStatus: {
283-
width: theme.spacing(1),
284-
height: theme.spacing(1),
285-
borderRadius: "100%",
286-
},
287-
288251
agentName: {
289252
fontWeight: 600,
290253
},

0 commit comments

Comments
 (0)