1
- import { Region , WorkspaceProxy } from "api/typesGenerated"
1
+ import { Region , Workspace , WorkspaceProxy } from "api/typesGenerated"
2
2
import { AvatarData } from "components/AvatarData/AvatarData"
3
3
import { Avatar } from "components/Avatar/Avatar"
4
4
import TableCell from "@mui/material/TableCell"
5
5
import TableRow from "@mui/material/TableRow"
6
- import { FC } from "react"
6
+ import { FC , useState } from "react"
7
7
import {
8
8
HealthyBadge ,
9
9
NotHealthyBadge ,
@@ -12,22 +12,52 @@ import {
12
12
} from "components/DeploySettingsLayout/Badges"
13
13
import { ProxyLatencyReport } from "contexts/useProxyLatency"
14
14
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"
15
24
16
25
export const ProxyRow : FC < {
17
26
latency ?: ProxyLatencyReport
18
27
proxy : Region
19
28
} > = ( { proxy, latency } ) => {
29
+ const styles = useStyles ( )
20
30
// If we have a more specific proxy status, use that.
21
31
// All users can see healthy/unhealthy, some can see more.
22
32
let statusBadge = < ProxyStatus proxy = { proxy } />
33
+ let shouldShowMessages = false
23
34
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
+ )
25
43
}
26
44
45
+ const [ isMsgsOpen , setIsMsgsOpen ] = useState ( false )
46
+ const toggle = ( ) => {
47
+ if ( shouldShowMessages ) {
48
+ setIsMsgsOpen ( ( v ) => ! v )
49
+ }
50
+ }
27
51
return (
28
52
< >
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 } >
31
61
< AvatarData
32
62
title = {
33
63
proxy . display_name && proxy . display_name . length > 0
@@ -44,6 +74,7 @@ export const ProxyRow: FC<{
44
74
/>
45
75
)
46
76
}
77
+ subtitle = { shouldShowMessages ? "Click to view details" : undefined }
47
78
/>
48
79
</ TableCell >
49
80
@@ -62,10 +93,61 @@ export const ProxyRow: FC<{
62
93
{ latency ? `${ latency . latencyMS . toFixed ( 0 ) } ms` : "Not available" }
63
94
</ TableCell >
64
95
</ 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
+ />
65
122
</ >
66
123
)
67
124
}
68
125
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
+
69
151
// DetailedProxyStatus allows a more precise status to be displayed.
70
152
const DetailedProxyStatus : FC < {
71
153
proxy : WorkspaceProxy
@@ -100,3 +182,13 @@ const ProxyStatus: FC<{
100
182
101
183
return icon
102
184
}
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