admin/monitor: added some meaningful color
Massimo Melina committed
Mar 12, 2022 at 21:40 UTC
c2765d658ebe8319cfc81d2c1a089c0df927de61
1 file changed
+17
-5
admin/src/MonitorPage.ts
+17
-5
@@ -7,7 +7,7 @@ import { Delete, Lock, Block } from '@mui/icons-material'
7
import { Box, Chip, Typography } from '@mui/material'
8
import { DataGrid } from "@mui/x-data-grid"
9
import { Alert } from '@mui/material'
10
-import { prefix, formatBytes, IconBtn, iconTooltip, manipulateConfig } from "./misc"
10
+import { formatBytes, IconBtn, iconTooltip, manipulateConfig } from "./misc"
11
import { Field, SelectField } from './Form'
12
13
export default function MonitorPage() {
@@ -31,26 +31,38 @@ function MoreInfo() {
31
pair('started'),
32
pair('version'),
33
pair('build'),
34
- pair('http', 'HTTP', v => v.listening ? 'port '+v.port : ('off' + prefix(': configured port is used by ',v.busy))),
35
- pair('https', 'HTTPS', v => v.listening ? 'port '+v.port : ('off' + prefix(': configured port is used by ',v.busy))),
34
+ pair('http', "HTTP", port),
35
+ pair('https', "HTTPS", port),
36
)
37
)
38
39
- function pair(k: string, label: string='', render?:(v:any) => string) {
39
+ type Color = Parameters<typeof Chip>[0]['color']
40
+ type Render = (v:any) => [string, Color?]
41
+
42
+ function pair(k: string, label: string='', render?:Render) {
43
let v = _.get(res, k)
44
if (v === undefined)
45
return null
46
if (typeof v === 'string' && isoDateRe.test(v))
47
v = new Date(v).toLocaleString()
48
+ let color: Color = undefined
49
if (render)
46
- v = render(v)
50
+ [v, color] = render(v)
51
if (!label)
52
label = _.capitalize(k.replaceAll('_', ' '))
53
return h(Chip, {
54
variant: 'filled',
55
+ color,
56
label: h(Fragment, {}, h('b',{},label), ': ', v),
57
})
58
}
59
+
60
+ function port(v: any): ReturnType<Render> {
61
+ return v.listening ? ["port " + v.port, 'success']
62
+ : v.error ? [v.error, 'error']
63
+ : ["off"]
64
+ }
65
+
66
}
67
68
function Connections() {