@@ -8,6 +8,7 @@ import UpBarChart from "../Charts/UpBarChart";
8
8
import DownBarChart from "../Charts/DownBarChart" ;
9
9
import ResponseGaugeChart from "../Charts/ResponseGaugeChart" ;
10
10
import SkeletonLayout from "./skeleton" ;
11
+ import EmptyView from "./EmptyView" ;
11
12
// Utils
12
13
import { formatDateWithTz } from "../../../../../Utils/timeUtils" ;
13
14
import PropTypes from "prop-types" ;
@@ -36,6 +37,83 @@ const ChartBoxes = ({
36
37
totalUpChecks + totalDownChecks > 0 ? totalUpChecks + totalDownChecks : 1 ;
37
38
const groupedUptimePercentage = ( totalUpChecks / denominator ) * 100 ;
38
39
40
+ const renderUptime = ( ) => {
41
+ const upCheck = monitor ?. groupedUpChecks ?. reduce ( ( count , checkGroup ) => count + checkGroup . totalChecks , 0 ) ;
42
+ if ( ! hoveredUptimeData && ! upCheck ) {
43
+ return < EmptyView /> ;
44
+ }
45
+ return (
46
+ < >
47
+ < Box position = "relative" >
48
+ < Typography > Total Checks</ Typography >
49
+ < Typography component = "span" >
50
+ { hoveredUptimeData !== null
51
+ ? hoveredUptimeData . totalChecks
52
+ : upCheck }
53
+ </ Typography >
54
+ { hoveredUptimeData !== null && hoveredUptimeData . time !== null && (
55
+ < Typography
56
+ component = "h5"
57
+ position = "absolute"
58
+ top = "100%"
59
+ fontSize = { 11 }
60
+ color = { theme . palette . primary . contrastTextTertiary }
61
+ >
62
+ { formatDateWithTz ( hoveredUptimeData . _id , dateFormat , uiTimezone ) }
63
+ </ Typography >
64
+ ) }
65
+ </ Box >
66
+ < Box >
67
+ < Typography >
68
+ { hoveredUptimeData !== null ? "Avg Response Time" : "Uptime Percentage" }
69
+ </ Typography >
70
+ < Typography component = "span" >
71
+ { hoveredUptimeData !== null
72
+ ? Math . floor ( hoveredUptimeData ?. avgResponseTime ?? 0 )
73
+ : Math . floor ( groupedUptimePercentage ) }
74
+ < Typography component = "span" >
75
+ { hoveredUptimeData !== null ? " ms" : " %" }
76
+ </ Typography >
77
+ </ Typography >
78
+ </ Box >
79
+ </ >
80
+ ) ;
81
+ } ;
82
+
83
+ const renderIncidents = ( ) => {
84
+ const downChecks = monitor ?. groupedDownChecks ?. reduce ( ( count , checkGroup ) => count + checkGroup . totalChecks , 0 ) ;
85
+ if ( ! downChecks && ! hoveredIncidentsData ) {
86
+ return < EmptyView message = "Great. No incidents, yet!" /> ;
87
+ }
88
+ return (
89
+ < Box position = "relative" >
90
+ < Typography component = "span" >
91
+ { hoveredIncidentsData !== null
92
+ ? hoveredIncidentsData . totalChecks
93
+ : downChecks }
94
+ </ Typography >
95
+ { hoveredIncidentsData !== null && hoveredIncidentsData . time !== null && (
96
+ < Typography
97
+ component = "h5"
98
+ position = "absolute"
99
+ top = "100%"
100
+ fontSize = { 11 }
101
+ color = { theme . palette . primary . contrastTextTertiary }
102
+ >
103
+ { formatDateWithTz ( hoveredIncidentsData . _id , dateFormat , uiTimezone ) }
104
+ </ Typography >
105
+ ) }
106
+ </ Box >
107
+ ) ;
108
+ }
109
+
110
+ const renderResponseTime = ( ) => {
111
+ if ( ! monitor ?. avgResponseTime ) {
112
+ return < EmptyView /> ;
113
+ }
114
+ return < ResponseGaugeChart avgResponseTime = { monitor . avgResponseTime } /> ;
115
+ } ;
116
+
39
117
return (
40
118
< Stack
41
119
direction = "row"
@@ -51,40 +129,7 @@ const ChartBoxes = ({
51
129
justifyContent = "space-between"
52
130
direction = "row"
53
131
>
54
- < Box position = "relative" >
55
- < Typography > Total Checks</ Typography >
56
- < Typography component = "span" >
57
- { hoveredUptimeData !== null
58
- ? hoveredUptimeData . totalChecks
59
- : ( monitor ?. groupedUpChecks ?. reduce ( ( count , checkGroup ) => {
60
- return count + checkGroup . totalChecks ;
61
- } , 0 ) ?? 0 ) }
62
- </ Typography >
63
- { hoveredUptimeData !== null && hoveredUptimeData . time !== null && (
64
- < Typography
65
- component = "h5"
66
- position = "absolute"
67
- top = "100%"
68
- fontSize = { 11 }
69
- color = { theme . palette . primary . contrastTextTertiary }
70
- >
71
- { formatDateWithTz ( hoveredUptimeData . _id , dateFormat , uiTimezone ) }
72
- </ Typography >
73
- ) }
74
- </ Box >
75
- < Box >
76
- < Typography >
77
- { hoveredUptimeData !== null ? "Avg Response Time" : "Uptime Percentage" }
78
- </ Typography >
79
- < Typography component = "span" >
80
- { hoveredUptimeData !== null
81
- ? Math . floor ( hoveredUptimeData ?. avgResponseTime ?? 0 )
82
- : Math . floor ( groupedUptimePercentage ) }
83
- < Typography component = "span" >
84
- { hoveredUptimeData !== null ? " ms" : " %" }
85
- </ Typography >
86
- </ Typography >
87
- </ Box >
132
+ { renderUptime ( ) }
88
133
</ Stack >
89
134
< UpBarChart
90
135
monitor = { monitor }
@@ -96,27 +141,8 @@ const ChartBoxes = ({
96
141
icon = { < IncidentsIcon /> }
97
142
header = "Incidents"
98
143
>
99
- < Stack width = { "100%" } >
100
- < Box position = "relative" >
101
- < Typography component = "span" >
102
- { hoveredIncidentsData !== null
103
- ? hoveredIncidentsData . totalChecks
104
- : ( monitor ?. groupedDownChecks ?. reduce ( ( count , checkGroup ) => {
105
- return count + checkGroup . totalChecks ;
106
- } , 0 ) ?? 0 ) }
107
- </ Typography >
108
- { hoveredIncidentsData !== null && hoveredIncidentsData . time !== null && (
109
- < Typography
110
- component = "h5"
111
- position = "absolute"
112
- top = "100%"
113
- fontSize = { 11 }
114
- color = { theme . palette . primary . contrastTextTertiary }
115
- >
116
- { formatDateWithTz ( hoveredIncidentsData . _id , dateFormat , uiTimezone ) }
117
- </ Typography >
118
- ) }
119
- </ Box >
144
+ < Stack width = "100%" >
145
+ { renderIncidents ( ) }
120
146
</ Stack >
121
147
< DownBarChart
122
148
monitor = { monitor }
@@ -128,7 +154,7 @@ const ChartBoxes = ({
128
154
icon = { < AverageResponseIcon /> }
129
155
header = "Average Response Time"
130
156
>
131
- < ResponseGaugeChart avgResponseTime = { monitor ?. avgResponseTime ?? 0 } />
157
+ { renderResponseTime ( ) }
132
158
</ ChartBox >
133
159
</ Stack >
134
160
) ;
0 commit comments