File tree Expand file tree Collapse file tree 1 file changed +32
-28
lines changed
Expand file tree Collapse file tree 1 file changed +32
-28
lines changed Original file line number Diff line number Diff line change @@ -345,41 +345,45 @@ export function getSegments({
345345 }
346346
347347 // Use pointsWatchdog as the primary driver since it indicates if alerting service is available
348- return pointsWatchdog . reduce ( ( agg , [ timestamp , watchdogValue ] , index ) => {
349- const atRiskValue = pointsAtRisk [ index ] ?. [ 1 ] || 0 ;
350- const degradedValue = pointsDegraded [ index ] ?. [ 1 ] || 0 ;
351- const currentType =
352- watchdogValue !== '1'
353- ? NAN_STRING
354- : atRiskValue > 0
355- ? STATUS_CRITICAL
356- : degradedValue > 0
357- ? STATUS_WARNING
358- : STATUS_HEALTH ;
359-
360- if ( agg . length > 0 ) {
361- const lastValue = agg [ agg . length - 1 ] ;
362-
363- // Only create new segment if status changes
364- if ( lastValue . type !== currentType ) {
365- lastValue . endsAt = timestamp ;
348+ const segments = pointsWatchdog . reduce (
349+ ( agg , [ timestamp , watchdogValue ] , index ) => {
350+ const atRiskValue = pointsAtRisk [ index ] ?. [ 1 ] || 0 ;
351+ const degradedValue = pointsDegraded [ index ] ?. [ 1 ] || 0 ;
352+ const currentType =
353+ watchdogValue !== '1'
354+ ? NAN_STRING
355+ : atRiskValue > 0
356+ ? STATUS_CRITICAL
357+ : degradedValue > 0
358+ ? STATUS_WARNING
359+ : STATUS_HEALTH ;
360+
361+ if ( agg . length > 0 ) {
362+ const lastValue = agg [ agg . length - 1 ] ;
363+
364+ // Only create new segment if status changes
365+ if ( lastValue . type !== currentType ) {
366+ lastValue . endsAt = timestamp ;
367+ agg . push ( {
368+ startsAt : timestamp ,
369+ endsAt : null ,
370+ type : currentType ,
371+ } ) ;
372+ }
373+ } else {
374+ // First segment
366375 agg . push ( {
367376 startsAt : timestamp ,
368377 endsAt : null ,
369378 type : currentType ,
370379 } ) ;
371380 }
372- } else {
373- // First segment
374- agg . push ( {
375- startsAt : timestamp ,
376- endsAt : null ,
377- type : currentType ,
378- } ) ;
379- }
380381
381- return agg ;
382- } , [ ] ) ;
382+ return agg ;
383+ } ,
384+ [ ] ,
385+ ) ;
386+ return segments . filter ( ( segment ) => segment . type !== STATUS_HEALTH ) ;
383387}
384388
385389// A custom hook that builds on useLocation to parse the query string.
You can’t perform that action at this time.
0 commit comments