11import { Component , OnInit } from '@angular/core' ;
2- import { EventSearchFields , EventType , EventTypes , ProjectStore } from '@observability-ui/core' ;
2+ import { beginningOfDay , endOfDay , EventSearchFields , EventType , EventTypes , ProjectStore , toTimezoneAwareISOString } from '@observability-ui/core' ;
33import { BindToQueryParams , CoreComponent , HasSearchForm , ParameterService , PersistOnLocalStorage , Prop , StorageService , TypedFormControl , TypedFormGroup } from '@datakitchen/ngx-toolkit' ;
44import { ComponentStore } from '../../components/components.store' ;
55import { BehaviorSubject , combineLatest , defer , map , merge , Observable , Subject , takeUntil , tap } from 'rxjs' ;
@@ -20,11 +20,15 @@ export class EventListComponent extends CoreComponent implements OnInit, HasSear
2020 search = new TypedFormGroup < EventSearchFields > ( {
2121 component_id : new TypedFormControl < string > ( ) ,
2222 event_type : new TypedFormControl < string > ( ) ,
23+ date_range_start : new TypedFormControl < string > ( ) ,
24+ date_range_end : new TypedFormControl < string > ( ) ,
2325 } ) ;
2426
2527 search$ : BehaviorSubject < EventSearchFields > = new BehaviorSubject < EventSearchFields > ( {
2628 component_id : '' ,
27- event_type : ''
29+ event_type : '' ,
30+ date_range_start : '' ,
31+ date_range_end : '' ,
2832 } ) ;
2933
3034 readonly events = EventTypes ;
@@ -40,7 +44,7 @@ export class EventListComponent extends CoreComponent implements OnInit, HasSear
4044 componentsLoading = toSignal ( this . componentStore . getLoadingFor ( 'searchPage' ) ) ;
4145
4246 filtersApplied$ = this . search$ . pipe (
43- map ( ( { component_id, event_type } ) => ! ! component_id || ! ! event_type ) ,
47+ map ( ( { component_id, event_type, date_range_start , date_range_end } ) => ! ! component_id || ! ! event_type || ! ! date_range_start || ! ! date_range_end ) ,
4448 ) ;
4549 antiFlickerLoading$ = new BehaviorSubject ( true ) ;
4650
@@ -74,20 +78,29 @@ export class EventListComponent extends CoreComponent implements OnInit, HasSear
7478 this . tableChanged$ ,
7579 ] ) . pipe (
7680 takeUntil ( this . destroyed$ )
77- ) . subscribe ( ( [ { id } , { search : { event_type, component_id } , ...pagination } ] ) => {
78-
79- const eventTypes = event_type ?. split ( ',' ) . filter ( e => e ) ?? [ ] ;
80- const components = component_id ?. split ( ',' ) . filter ( e => e ) ?? [ ] ;
81+ ) . subscribe ( ( [ { id } , { search : { event_type, component_id, date_range_start, date_range_end } , ...pagination } ] ) => {
82+
83+ const filters : EventSearchFields = {
84+ event_type : event_type ?. split ( ',' ) . filter ( e => e ) ?? [ ] as any ,
85+ component_id : component_id ?. split ( ',' ) . filter ( e => e ) ?? [ ] as any ,
86+ }
87+
88+ if ( date_range_start ) {
89+ const startDate = beginningOfDay ( new Date ( date_range_start ) ) ;
90+ filters . date_range_start = toTimezoneAwareISOString ( startDate ) ;
91+ }
92+
93+ if ( date_range_end ) {
94+ const endDate = endOfDay ( new Date ( date_range_end ) ) ;
95+ filters . date_range_end = toTimezoneAwareISOString ( endDate ) ;
96+ }
8197
8298 this . projectStore . dispatch ( 'getEventsByPage' , {
8399 parentId : id ,
84100 count : pagination . pageSize ,
85101 page : pagination . pageIndex ,
86102 sort : 'desc' ,
87- filters : {
88- event_type : eventTypes as any ,
89- component_id : components as any ,
90- } ,
103+ filters,
91104 } ) ;
92105
93106 this . search$ . pipe (
0 commit comments