File tree 1 file changed +18
-15
lines changed
1 file changed +18
-15
lines changed Original file line number Diff line number Diff line change @@ -21,24 +21,27 @@ import { AlertConversation } from "@/api/generated/types.gen";
21
21
const aggregateAlertsByDate = ( alerts : { timestamp : string } [ ] ) => {
22
22
const dateMap : Record < string , { date : string ; alerts : number } > = { } ;
23
23
24
- alerts . reduce ( ( acc , alert ) => {
25
- const timestamp = new Date ( alert . timestamp ) ;
26
- const formattedDate = timestamp . toLocaleDateString ( "en-US" , {
27
- month : "short" ,
28
- day : "2-digit" ,
29
- } ) ;
24
+ alerts
25
+ . sort (
26
+ ( a , b ) =>
27
+ new Date ( a . timestamp ) . getTime ( ) - new Date ( b . timestamp ) . getTime ( ) ,
28
+ )
29
+ . reduce ( ( acc , alert ) => {
30
+ const timestamp = new Date ( alert . timestamp ) ;
31
+ const formattedDate = timestamp . toLocaleDateString ( "en-US" , {
32
+ month : "short" ,
33
+ day : "2-digit" ,
34
+ } ) ;
30
35
31
- if ( ! acc [ formattedDate ] ) {
32
- acc [ formattedDate ] = { date : formattedDate , alerts : 0 } ;
33
- }
34
- ( acc [ formattedDate ] as { alerts : number } ) . alerts += 1 ;
36
+ if ( ! acc [ formattedDate ] ) {
37
+ acc [ formattedDate ] = { date : formattedDate , alerts : 0 } ;
38
+ }
39
+ ( acc [ formattedDate ] as { alerts : number } ) . alerts += 1 ;
35
40
36
- return acc ;
37
- } , dateMap ) ;
41
+ return acc ;
42
+ } , dateMap ) ;
38
43
39
- return Object . values ( dateMap ) . sort (
40
- ( a , b ) => new Date ( a . date ) . getTime ( ) - new Date ( b . date ) . getTime ( ) ,
41
- ) ;
44
+ return Object . values ( dateMap ) ;
42
45
} ;
43
46
44
47
const chartConfig = {
You can’t perform that action at this time.
0 commit comments