Skip to content

Commit 7d862ad

Browse files
author
ci bot
committed
Merge branch 'event-daterange' into 'enterprise'
feat(events): add date range filter to All Events tab See merge request dkinternal/observability/dataops-observability!29
2 parents 2cd0aa1 + 4aa02ab commit 7d862ad

3 files changed

Lines changed: 43 additions & 12 deletions

File tree

observability_ui/apps/shell/src/app/projects/events/event-list/event-list.component.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
11
<div class="toolbar">
2+
<mat-form-field>
3+
<mat-label>Date range</mat-label>
4+
<mat-date-range-input [rangePicker]="picker">
5+
<input matStartDate
6+
[formControl]="$any(search.controls.date_range_start)"
7+
placeholder="Start date">
8+
<input matEndDate
9+
[formControl]="$any(search.controls.date_range_end)"
10+
placeholder="End date">
11+
</mat-date-range-input>
12+
13+
<mat-datepicker-toggle matSuffix
14+
[for]="picker"></mat-datepicker-toggle>
15+
<mat-date-range-picker #picker></mat-date-range-picker>
16+
</mat-form-field>
17+
218
<filter-field [label]="'eventTypes' | translate | titlecase"
319
[multiple]="true"
420
[noneSelectedLabel]="'eventTypes' | translate | titlecase"

observability_ui/apps/shell/src/app/projects/events/event-list/event-list.component.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,16 @@ describe('event-list', () => {
5959

6060
describe('onTableChange()', () => {
6161
it('should pass the filters to the store', () => {
62-
component.onTableChange({ pageIndex: 0, pageSize: 10, search: { event_type: 'A,B', component_id: '1,2' } });
62+
component.onTableChange({ pageIndex: 0, pageSize: 10, search: { event_type: 'A,B', component_id: '1,2', date_range_start: '2022-11-15T00:00:00.000-04:00', date_range_end: '2022-11-24T00:00:00.000-04:00' } });
6363
expect(store.dispatch).toBeCalledWith('getEventsByPage', expect.objectContaining({
6464
parentId: 'project_id',
6565
count: 10,
6666
page: 0,
6767
filters: {
6868
event_type: [ 'A', 'B' ],
6969
component_id: [ '1', '2' ],
70+
date_range_start: expect.stringMatching(/^2022\-11\-15T00:00:00\.000[\+\-]\d{2}:\d{2}$/),
71+
date_range_end: expect.stringMatching(/^2022\-11\-24T23:59:59\.999[\+\-]\d{2}:\d{2}$/),
7072
}
7173
}));
7274
});

observability_ui/apps/shell/src/app/projects/events/event-list/event-list.component.ts

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { 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';
33
import { BindToQueryParams, CoreComponent, HasSearchForm, ParameterService, PersistOnLocalStorage, Prop, StorageService, TypedFormControl, TypedFormGroup } from '@datakitchen/ngx-toolkit';
44
import { ComponentStore } from '../../components/components.store';
55
import { 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

Comments
 (0)