1
- import { Box , CircularProgress , Divider } from '@mui/material' ;
1
+ import { Box , CircularProgress , Divider , useTheme } from '@mui/material' ;
2
2
import { FC , useEffect } from 'react' ;
3
+ import { alpha } from '@mui/material/styles' ;
3
4
4
5
import { ServiceNames } from '@/constants/service' ;
5
6
import { StreamEventType } from '@/constants/stream' ;
6
7
import { CardRoot } from '@/content/DoraMetrics/DoraCards/sharedComponents' ;
7
- import { serviceSlice , ServiceStatusState } from '@/slices/service' ;
8
+ import { serviceSlice } from '@/slices/service' ;
8
9
import { useDispatch , useSelector } from '@/store' ;
9
10
10
11
import { FlexBox } from '../FlexBox' ;
@@ -14,13 +15,13 @@ import { Line } from '../Text';
14
15
export const SystemStatus : FC = ( ) => {
15
16
const dispatch = useDispatch ( ) ;
16
17
const loading = useSelector ( ( state ) => state . service . loading ) ;
17
- const services = useSelector (
18
- ( state : { service : { services : ServiceStatusState } } ) =>
19
- state . service . services
20
- ) ;
18
+ const services = useSelector ( ( state ) => state . service . services ) ;
19
+
21
20
console . log ( 'Status Page render' ) ;
21
+ const theme = useTheme ( ) ;
22
22
useEffect ( ( ) => {
23
23
const eventSource = new EventSource ( `/api/stream` ) ;
24
+
24
25
eventSource . onmessage = ( event ) => {
25
26
const data = JSON . parse ( event . data ) ;
26
27
@@ -56,12 +57,13 @@ export const SystemStatus: FC = () => {
56
57
57
58
const { addPage } = useOverlayPage ( ) ;
58
59
59
- const ServiceTitle : { [ key : string ] : string } = {
60
+ const ServiceTitle : Record < ServiceNames , string > = {
60
61
[ ServiceNames . API_SERVER ] : 'Backend Server' ,
61
62
[ ServiceNames . REDIS ] : 'Redis Database' ,
62
63
[ ServiceNames . POSTGRES ] : 'Postgres Database' ,
63
64
[ ServiceNames . SYNC_SERVER ] : 'Sync Server'
64
65
} ;
66
+
65
67
return (
66
68
< FlexBox col gap = { 2 } sx = { { padding : '16px' } } >
67
69
< Line bold white fontSize = "24px" sx = { { mb : 2 } } >
@@ -84,17 +86,16 @@ export const SystemStatus: FC = () => {
84
86
{ Object . keys ( services ) . map ( ( serviceName ) => {
85
87
const serviceKey = serviceName as ServiceNames ;
86
88
const { isUp } = services [ serviceKey ] ;
89
+
87
90
return (
88
91
< CardRoot
89
92
key = { serviceName }
90
93
onClick = { ( ) => {
91
94
addPage ( {
92
95
page : {
93
96
ui : 'system_logs' ,
94
- title : `${ ServiceTitle [ serviceName ] } Logs` ,
95
- props : {
96
- serviceName : serviceName
97
- }
97
+ title : `${ ServiceTitle [ serviceKey ] } Logs` ,
98
+ props : { serviceName }
98
99
}
99
100
} ) ;
100
101
} }
@@ -106,7 +107,9 @@ export const SystemStatus: FC = () => {
106
107
backgroundColor : 'rgba(255, 255, 255, 0.05)' ,
107
108
borderRadius : '12px' ,
108
109
border : `1px solid ${
109
- isUp ? 'rgba(0, 255, 0, 0.3)' : 'rgba(255, 0, 0, 0.3)'
110
+ isUp
111
+ ? alpha ( theme . colors . success . main , 0.3 )
112
+ : alpha ( theme . colors . error . main , 0.3 )
110
113
} `,
111
114
padding : '16px' ,
112
115
cursor : 'pointer' ,
@@ -125,7 +128,7 @@ export const SystemStatus: FC = () => {
125
128
alignItems : 'center'
126
129
} }
127
130
>
128
- { ServiceTitle [ serviceName ] }
131
+ { ServiceTitle [ serviceKey ] }
129
132
< Box
130
133
component = "span"
131
134
sx = { {
@@ -134,9 +137,11 @@ export const SystemStatus: FC = () => {
134
137
width : '10px' ,
135
138
height : '10px' ,
136
139
borderRadius : '50%' ,
137
- backgroundColor : isUp ? '#28a745' : '#dc3545'
140
+ backgroundColor : isUp
141
+ ? theme . colors . success . main
142
+ : theme . colors . error . main
138
143
} }
139
- > </ Box >
144
+ / >
140
145
</ Line >
141
146
</ FlexBox >
142
147
0 commit comments