@@ -6,120 +6,123 @@ import Uptime from '@components/uptime'
6
6
7
7
import './representative-uptime.styl'
8
8
9
- export default class RepresentativeUptime extends React . Component {
10
- render ( ) {
11
- const { uptime } = this . props . account . toJS ( )
9
+ export default function RepresentativeUptime ( { account } ) {
10
+ const { uptime } = account . toJS ( )
12
11
13
- const lastOnline = this . props . account . get ( 'last_online' )
14
- const lastOffline = this . props . account . get ( 'last_offline' )
12
+ const last_online = account . get ( 'last_online' )
13
+ const last_offline = account . get ( 'last_offline' )
15
14
16
- const onlineCount = uptime . filter ( ( i ) => i . online ) . length
17
- const last60 = this . props . account . getIn ( [ 'uptime_summary' , 'days_60' ] , { } )
18
- const last60Pct =
19
- Math . round (
20
- ( last60 . online_count / ( last60 . online_count + last60 . offline_count ) ) *
21
- 10000
22
- ) / 100
23
- const last60Class =
24
- last60Pct > 95
25
- ? 'online'
26
- : last60Pct < 70
27
- ? 'offline'
28
- : last60Pct < 80
29
- ? 'warning'
30
- : ''
15
+ const online_count = uptime . filter ( ( i ) => i . online ) . length
16
+ const last_60 = account . getIn ( [ 'uptime_summary' , 'days_60' ] , { } )
17
+ const last_60_pct =
18
+ Math . round (
19
+ ( last_60 . online_count / ( last_60 . online_count + last_60 . offline_count ) ) *
20
+ 10000
21
+ ) / 100
22
+ const last_60_class =
23
+ last_60_pct > 95
24
+ ? 'online'
25
+ : last_60_pct < 70
26
+ ? 'offline'
27
+ : last_60_pct < 80
28
+ ? 'warning'
29
+ : ''
31
30
32
- const last90 = this . props . account . getIn ( [ 'uptime_summary' , 'days_90' ] , { } )
33
- const last90Pct =
34
- Math . round (
35
- ( last90 . online_count / ( last90 . online_count + last90 . offline_count ) ) *
36
- 10000
37
- ) / 100
38
- const last90Class =
39
- last90Pct > 95 ? 'online' : last90Pct < 80 ? 'offline' : ''
31
+ const last_90 = account . getIn ( [ 'uptime_summary' , 'days_90' ] , { } )
32
+ const last_90_pct =
33
+ Math . round (
34
+ ( last_90 . online_count / ( last_90 . online_count + last_90 . offline_count ) ) *
35
+ 10000
36
+ ) / 100
37
+ const last_90_class =
38
+ last_90_pct > 95 ? 'online' : last_90_pct < 80 ? 'offline' : ''
40
39
41
- let text
42
- let online = true
43
- if ( ! lastOffline ) {
44
- // missing both
45
- if ( ! lastOnline ) {
46
- text = 'Operational'
47
- } else {
48
- // missing offline, has online
49
- text = 'Operational'
50
- }
51
- } else if ( ! lastOnline ) {
52
- // missing online, has offline
53
- text = 'Down'
54
- online = false
40
+ let text
41
+ let online = true
42
+ if ( ! last_offline ) {
43
+ // missing both
44
+ if ( ! last_online ) {
45
+ text = 'Operational'
55
46
} else {
56
- // has both
57
- if ( lastOnline > lastOffline ) {
58
- text = `Up for ${ timeago . format ( lastOffline * 1000 , 'nano_short' ) } `
59
- } else {
60
- text = `Down for ${ timeago . format ( lastOnline * 1000 , 'nano_short' ) } `
61
- online = false
62
- }
47
+ // missing offline, has online
48
+ text = 'Operational'
63
49
}
50
+ } else if ( ! last_online ) {
51
+ // missing online, has offline
52
+ text = 'Down'
53
+ online = false
54
+ } else {
55
+ // has both
56
+ if ( last_online > last_offline ) {
57
+ text = `Up for ${ timeago . format ( last_offline * 1000 , 'nano_short' ) } `
58
+ } else {
59
+ text = `Down for ${ timeago . format ( last_online * 1000 , 'nano_short' ) } `
60
+ online = false
61
+ }
62
+ }
64
63
65
- const uptimePct = Math . round ( ( onlineCount / uptime . length ) * 10000 ) / 100
66
- const uptimeClass =
67
- uptimePct > 90
64
+ let uptime_pct
65
+ let uptime_class = ''
66
+ if ( uptime . length === 0 ) {
67
+ uptime_pct = 0
68
+ uptime_class = 'offline' // Assuming offline or another class when no uptime data is available
69
+ } else {
70
+ uptime_pct = Math . round ( ( online_count / uptime . length ) * 10000 ) / 100
71
+ uptime_class =
72
+ uptime_pct > 90
68
73
? 'online'
69
- : uptimePct < 50
74
+ : uptime_pct < 50
70
75
? 'offline'
71
- : uptimePct < 75
76
+ : uptime_pct < 75
72
77
? 'warning'
73
78
: ''
74
-
75
- return (
76
- < div className = 'representative__section representative__uptime' >
77
- < div className = 'representative__uptime-metrics' >
78
- < div className = 'representative__uptime-metrics-metric' >
79
- < div className = 'representative__uptime-metric-header section__label' >
80
- Current Status
81
- </ div >
82
- < div
83
- className = { `representative__uptime-metric-body ${
84
- online ? 'online' : 'offline'
85
- } `} >
86
- { text }
87
- </ div >
79
+ }
80
+ return (
81
+ < div className = 'representative__section representative__uptime' >
82
+ < div className = 'representative__uptime-metrics' >
83
+ < div className = 'representative__uptime-metrics-metric' >
84
+ < div className = 'representative__uptime-metric-header section__label' >
85
+ Current Status
88
86
</ div >
89
- < div className = 'representative__uptime-metrics-metric' >
90
- < div className = 'representative__uptime-metric-header section__label' >
91
- 2W Uptime
92
- </ div >
93
- < div
94
- className = { `representative__uptime-metric-body ${ uptimeClass } ` } >
95
- { uptimePct } %
96
- </ div >
87
+ < div
88
+ className = { `representative__uptime-metric-body ${
89
+ online ? 'online' : 'offline'
90
+ } `} >
91
+ { text }
97
92
</ div >
98
- < div className = 'representative__uptime-metrics-metric' >
99
- < div className = 'representative__uptime-metric-header section__label' >
100
- 2M Uptime
101
- </ div >
102
- < div
103
- className = { `representative__uptime-metric-body ${ last60Class } ` } >
104
- { last60Pct ? `${ last60Pct } %` : '-' }
105
- </ div >
93
+ </ div >
94
+ < div className = 'representative__uptime-metrics-metric' >
95
+ < div className = 'representative__uptime-metric-header section__label' >
96
+ 2W Uptime
106
97
</ div >
107
- < div className = 'representative__uptime-metrics-metric' >
108
- < div className = 'representative__uptime-metric-header section__label' >
109
- 3M Uptime
110
- </ div >
111
- < div
112
- className = { `representative__uptime-metric-body ${ last90Class } ` } >
113
- { last90Pct ? `${ last90Pct } %` : '-' }
114
- </ div >
98
+ < div className = { `representative__uptime-metric-body ${ uptime_class } ` } >
99
+ { uptime_pct } %
115
100
</ div >
116
101
</ div >
117
- < div className = 'representative__uptime-bar' >
118
- < Uptime data = { uptime } expanded />
102
+ < div className = 'representative__uptime-metrics-metric' >
103
+ < div className = 'representative__uptime-metric-header section__label' >
104
+ 2M Uptime
105
+ </ div >
106
+ < div
107
+ className = { `representative__uptime-metric-body ${ last_60_class } ` } >
108
+ { last_60_pct ? `${ last_60_pct } %` : '-' }
109
+ </ div >
110
+ </ div >
111
+ < div className = 'representative__uptime-metrics-metric' >
112
+ < div className = 'representative__uptime-metric-header section__label' >
113
+ 3M Uptime
114
+ </ div >
115
+ < div
116
+ className = { `representative__uptime-metric-body ${ last_90_class } ` } >
117
+ { last_90_pct ? `${ last_90_pct } %` : '-' }
118
+ </ div >
119
119
</ div >
120
120
</ div >
121
- )
122
- }
121
+ < div className = 'representative__uptime-bar' >
122
+ < Uptime data = { uptime } expanded />
123
+ </ div >
124
+ </ div >
125
+ )
123
126
}
124
127
125
128
RepresentativeUptime . propTypes = {
0 commit comments