Skip to content

Commit ec2cfb3

Browse files
committed
chore: add errors + warnings to workspace proxy table
1 parent 7a073e8 commit ec2cfb3

File tree

1 file changed

+97
-5
lines changed

1 file changed

+97
-5
lines changed

site/src/pages/UserSettingsPage/WorkspaceProxyPage/WorkspaceProxyRow.tsx

Lines changed: 97 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { Region, WorkspaceProxy } from "api/typesGenerated"
1+
import { Region, Workspace, WorkspaceProxy } from "api/typesGenerated"
22
import { AvatarData } from "components/AvatarData/AvatarData"
33
import { Avatar } from "components/Avatar/Avatar"
44
import TableCell from "@mui/material/TableCell"
55
import TableRow from "@mui/material/TableRow"
6-
import { FC } from "react"
6+
import { FC, useState } from "react"
77
import {
88
HealthyBadge,
99
NotHealthyBadge,
@@ -12,22 +12,52 @@ import {
1212
} from "components/DeploySettingsLayout/Badges"
1313
import { ProxyLatencyReport } from "contexts/useProxyLatency"
1414
import { getLatencyColor } from "utils/latency"
15+
import Collapse from "@mui/material/Collapse"
16+
import { makeStyles } from "@mui/styles"
17+
import { combineClasses } from "utils/combineClasses"
18+
import ListItem from "@mui/material/ListItem"
19+
import List from "@mui/material/List"
20+
import { Box, ListSubheader } from "@mui/material"
21+
import { Maybe } from "components/Conditionals/Maybe"
22+
import { CodeBlock } from "components/CodeBlock/CodeBlock"
23+
import { CodeExample } from "components/CodeExample/CodeExample"
1524

1625
export const ProxyRow: FC<{
1726
latency?: ProxyLatencyReport
1827
proxy: Region
1928
}> = ({ proxy, latency }) => {
29+
const styles = useStyles()
2030
// If we have a more specific proxy status, use that.
2131
// All users can see healthy/unhealthy, some can see more.
2232
let statusBadge = <ProxyStatus proxy={proxy} />
33+
let shouldShowMessages = false
2334
if ("status" in proxy) {
24-
statusBadge = <DetailedProxyStatus proxy={proxy as WorkspaceProxy} />
35+
const wsproxy = proxy as WorkspaceProxy
36+
statusBadge = <DetailedProxyStatus proxy={wsproxy} />
37+
shouldShowMessages = Boolean(
38+
(wsproxy.status?.report?.warnings &&
39+
wsproxy.status?.report?.warnings.length > 0) ||
40+
(wsproxy.status?.report?.errors &&
41+
wsproxy.status?.report?.errors.length > 0),
42+
)
2543
}
2644

45+
const [isMsgsOpen, setIsMsgsOpen] = useState(false)
46+
const toggle = () => {
47+
if (shouldShowMessages) {
48+
setIsMsgsOpen((v) => !v)
49+
}
50+
}
2751
return (
2852
<>
29-
<TableRow key={proxy.name} data-testid={`${proxy.name}`}>
30-
<TableCell>
53+
<TableRow
54+
className={combineClasses({
55+
[styles.clickable]: shouldShowMessages,
56+
})}
57+
key={proxy.name}
58+
data-testid={`${proxy.name}`}
59+
>
60+
<TableCell onClick={toggle}>
3161
<AvatarData
3262
title={
3363
proxy.display_name && proxy.display_name.length > 0
@@ -44,6 +74,7 @@ export const ProxyRow: FC<{
4474
/>
4575
)
4676
}
77+
subtitle={shouldShowMessages ? "Click to view details" : undefined}
4778
/>
4879
</TableCell>
4980

@@ -62,10 +93,61 @@ export const ProxyRow: FC<{
6293
{latency ? `${latency.latencyMS.toFixed(0)} ms` : "Not available"}
6394
</TableCell>
6495
</TableRow>
96+
<Maybe condition={shouldShowMessages}>
97+
<TableRow>
98+
<TableCell colSpan={4} sx={{ padding: "0px !important" }}>
99+
<Collapse in={isMsgsOpen}>
100+
<ProxyMessagesRow proxy={proxy as WorkspaceProxy} />
101+
</Collapse>
102+
</TableCell>
103+
</TableRow>
104+
</Maybe>
105+
</>
106+
)
107+
}
108+
109+
const ProxyMessagesRow: FC<{
110+
proxy: WorkspaceProxy
111+
}> = ({ proxy }) => {
112+
return (
113+
<>
114+
<ProxyMessagesList
115+
title="Errors"
116+
messages={proxy.status?.report?.errors}
117+
/>
118+
<ProxyMessagesList
119+
title="Warnings"
120+
messages={proxy.status?.report?.warnings}
121+
/>
65122
</>
66123
)
67124
}
68125

126+
const ProxyMessagesList: FC<{
127+
title: string
128+
messages?: string[]
129+
}> = ({ title, messages }) => {
130+
if (!messages) {
131+
return <></>
132+
}
133+
return (
134+
<List
135+
subheader={
136+
<ListSubheader component="div" id="nested-list-subheader">
137+
{title}
138+
</ListSubheader>
139+
}
140+
>
141+
{messages.map((error, index) => (
142+
<ListItem key={"warning" + index}>
143+
<CodeExample code={error} />
144+
{/* <CodeBlock lines={[error]} /> */}
145+
</ListItem>
146+
))}
147+
</List>
148+
)
149+
}
150+
69151
// DetailedProxyStatus allows a more precise status to be displayed.
70152
const DetailedProxyStatus: FC<{
71153
proxy: WorkspaceProxy
@@ -100,3 +182,13 @@ const ProxyStatus: FC<{
100182

101183
return icon
102184
}
185+
186+
const useStyles = makeStyles((theme) => ({
187+
clickable: {
188+
cursor: "pointer",
189+
190+
"&:hover": {
191+
backgroundColor: theme.palette.action.hover,
192+
},
193+
},
194+
}))

0 commit comments

Comments
 (0)