From cc3073ea8dc8210beea8f02f38b06963fe06f436 Mon Sep 17 00:00:00 2001 From: engelharddirk Date: Wed, 15 Jan 2025 00:46:07 +0100 Subject: [PATCH 1/3] apply hotfix Signed-off-by: engelharddirk --- .../component/alert-panel/component/alert.component.ts | 4 +++- .../services/alert-service/alert-service.service.ts | 9 ++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/apps/frontend/src/app/backups-overview-page/component/alert-panel/component/alert.component.ts b/apps/frontend/src/app/backups-overview-page/component/alert-panel/component/alert.component.ts index a75212c8..121d8186 100644 --- a/apps/frontend/src/app/backups-overview-page/component/alert-panel/component/alert.component.ts +++ b/apps/frontend/src/app/backups-overview-page/component/alert-panel/component/alert.component.ts @@ -20,6 +20,7 @@ import { SeverityType } from '../../../../shared/enums/severityType'; export class AlertComponent implements OnInit, OnDestroy { protected readonly SeverityType = SeverityType; readonly DAYS = 7; + private readonly fromDate = new Date(Date.now() - this.DAYS * 24 * 60 * 60 * 1000); alerts: Alert[] = []; criticalAlertsCount = 0; @@ -47,9 +48,10 @@ export class AlertComponent implements OnInit, OnDestroy { loadAlerts(): void { this.alertService - .getAllAlerts(this.DAYS) + .getAllAlerts(this.fromDate.toISOString()) .pipe(takeUntil(this.destroy$)) .subscribe((data: Alert[]) => { + console.log("Data: " + data); this.alerts = this.filterAlerts(data); this.criticalAlertsCount = this.alerts.filter( (alert) => alert.alertType.severity === SeverityType.CRITICAL diff --git a/apps/frontend/src/app/shared/services/alert-service/alert-service.service.ts b/apps/frontend/src/app/shared/services/alert-service/alert-service.service.ts index 945b3d2f..5dcf4db2 100644 --- a/apps/frontend/src/app/shared/services/alert-service/alert-service.service.ts +++ b/apps/frontend/src/app/shared/services/alert-service/alert-service.service.ts @@ -2,6 +2,7 @@ import { Inject, Injectable } from '@angular/core'; import { BASE_URL } from '../../types/configuration'; import { HttpClient } from '@angular/common/http'; import { Observable, Subject } from 'rxjs'; +import { map } from 'rxjs/operators'; import { Alert } from '../../types/alert'; @Injectable({ @@ -14,9 +15,11 @@ export class AlertServiceService { private readonly http: HttpClient ) {} - getAllAlerts(days?: number): Observable { - if (days) { - return this.http.get(`${this.baseUrl}/alerting?days=${days}`); + getAllAlerts(fromDate?: string, offset?: number): Observable { + if (fromDate) { + return this.http.get<{ data: Alert[], paginationInfo: any }>(`${this.baseUrl}/alerting?offset=0&limit=10&fromDate=${fromDate}`).pipe( + map(response => response.data) + ); } return this.http.get(`${this.baseUrl}/alerting`); } From 39ef407fd6cca0ec3b272f222ec47face272abb3 Mon Sep 17 00:00:00 2001 From: engelharddirk Date: Wed, 15 Jan 2025 01:00:11 +0100 Subject: [PATCH 2/3] fix test Signed-off-by: engelharddirk --- .../alert-service/alert-service.service.spec.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/apps/frontend/src/app/shared/services/alert-service/alert-service.service.spec.ts b/apps/frontend/src/app/shared/services/alert-service/alert-service.service.spec.ts index e2deb1ea..193012a1 100644 --- a/apps/frontend/src/app/shared/services/alert-service/alert-service.service.spec.ts +++ b/apps/frontend/src/app/shared/services/alert-service/alert-service.service.spec.ts @@ -87,15 +87,15 @@ describe('AlertServiceService', () => { }); it('should fetch alerts with days parameter', () => { - const mockAlerts: Alert[] = [ + const mockAlerts = [ { id: randomUUID().toString(), alertType: { id: randomUUID().toString(), name: 'test', severity: SeverityType.INFO, - user_active: false, - master_active: false, + user_active: true, + master_active: true, }, backup: { id: randomUUID().toString(), @@ -126,13 +126,14 @@ describe('AlertServiceService', () => { }, ]; const days = 7; + const fromDate = new Date(Date.now() - days * 24 * 60 * 60 * 1000).toISOString(); - service.getAllAlerts(days).subscribe((alerts) => { + service.getAllAlerts(fromDate).subscribe((alerts) => { expect(alerts).toEqual(mockAlerts); }); - const req = httpMock.expectOne(`${baseUrl}/alerting?days=${days}`); + const req = httpMock.expectOne(`${baseUrl}/alerting?offset=0&limit=10&fromDate=${fromDate}`); expect(req.request.method).toBe('GET'); - req.flush(mockAlerts); + req.flush({ data: mockAlerts, paginationInfo: {} }); }); }); From b5a7f4fd66d628f9b10c83b6861c11f71afaf7bd Mon Sep 17 00:00:00 2001 From: engelharddirk Date: Wed, 15 Jan 2025 01:37:21 +0100 Subject: [PATCH 3/3] show correct total amount of alerts Signed-off-by: engelharddirk --- .../component/alert.component.html | 2 +- .../component/alert.component.spec.ts | 13 +++++++-- .../alert-panel/component/alert.component.ts | 28 ++++++++++--------- .../alert-service.service.spec.ts | 11 +++++--- .../alert-service/alert-service.service.ts | 16 ++++++++--- 5 files changed, 46 insertions(+), 24 deletions(-) diff --git a/apps/frontend/src/app/backups-overview-page/component/alert-panel/component/alert.component.html b/apps/frontend/src/app/backups-overview-page/component/alert-panel/component/alert.component.html index bf36f6ec..6838c28a 100644 --- a/apps/frontend/src/app/backups-overview-page/component/alert-panel/component/alert.component.html +++ b/apps/frontend/src/app/backups-overview-page/component/alert-panel/component/alert.component.html @@ -61,7 +61,7 @@ diff --git a/apps/frontend/src/app/backups-overview-page/component/alert-panel/component/alert.component.spec.ts b/apps/frontend/src/app/backups-overview-page/component/alert-panel/component/alert.component.spec.ts index 67227727..eea376ab 100644 --- a/apps/frontend/src/app/backups-overview-page/component/alert-panel/component/alert.component.spec.ts +++ b/apps/frontend/src/app/backups-overview-page/component/alert-panel/component/alert.component.spec.ts @@ -93,7 +93,12 @@ describe('AlertComponent', () => { }, ]; - mockAlertService.getAllAlerts.mockReturnValue(of(mockAlerts)); + const mockReturnValue = { + alerts: mockAlerts, + count: 1, + }; + mockAlertService.getAllAlerts.mockReturnValue(of(mockReturnValue)); + component.loadAlerts(); @@ -104,7 +109,11 @@ describe('AlertComponent', () => { }); it('should set status to OK when no alerts', () => { - mockAlertService.getAllAlerts.mockReturnValue(of([])); + const mockReturnValue = { + alerts: [], + count: 0, + }; + mockAlertService.getAllAlerts.mockReturnValue(of(mockReturnValue)); component.loadAlerts(); diff --git a/apps/frontend/src/app/backups-overview-page/component/alert-panel/component/alert.component.ts b/apps/frontend/src/app/backups-overview-page/component/alert-panel/component/alert.component.ts index 121d8186..ad1cebaa 100644 --- a/apps/frontend/src/app/backups-overview-page/component/alert-panel/component/alert.component.ts +++ b/apps/frontend/src/app/backups-overview-page/component/alert-panel/component/alert.component.ts @@ -23,6 +23,7 @@ export class AlertComponent implements OnInit, OnDestroy { private readonly fromDate = new Date(Date.now() - this.DAYS * 24 * 60 * 60 * 1000); alerts: Alert[] = []; + total: number = 0; criticalAlertsCount = 0; warningAlertsCount = 0; infoAlertsCount = 0; @@ -50,19 +51,20 @@ export class AlertComponent implements OnInit, OnDestroy { this.alertService .getAllAlerts(this.fromDate.toISOString()) .pipe(takeUntil(this.destroy$)) - .subscribe((data: Alert[]) => { - console.log("Data: " + data); - this.alerts = this.filterAlerts(data); - this.criticalAlertsCount = this.alerts.filter( - (alert) => alert.alertType.severity === SeverityType.CRITICAL - ).length; - this.warningAlertsCount = this.alerts.filter( - (alert) => alert.alertType.severity === SeverityType.WARNING - ).length; - this.infoAlertsCount = this.alerts.filter( - (alert) => alert.alertType.severity === SeverityType.INFO - ).length; - this.status = this.getStatus(); + .subscribe((data: { alerts: Alert[], total: number }) => { + console.log("Data: ", data); + this.alerts = this.filterAlerts(data.alerts); + this.total = data.total; + this.criticalAlertsCount = this.alerts.filter( + (alert) => alert.alertType.severity === SeverityType.CRITICAL + ).length; + this.warningAlertsCount = this.alerts.filter( + (alert) => alert.alertType.severity === SeverityType.WARNING + ).length; + this.infoAlertsCount = this.alerts.filter( + (alert) => alert.alertType.severity === SeverityType.INFO + ).length; + this.status = this.getStatus(); }); } diff --git a/apps/frontend/src/app/shared/services/alert-service/alert-service.service.spec.ts b/apps/frontend/src/app/shared/services/alert-service/alert-service.service.spec.ts index 193012a1..9ccccd22 100644 --- a/apps/frontend/src/app/shared/services/alert-service/alert-service.service.spec.ts +++ b/apps/frontend/src/app/shared/services/alert-service/alert-service.service.spec.ts @@ -78,12 +78,12 @@ describe('AlertServiceService', () => { ]; service.getAllAlerts().subscribe((alerts) => { - expect(alerts).toEqual(mockAlerts); + expect(alerts).toEqual({ alerts: mockAlerts, total: 2 }); }); const req = httpMock.expectOne(`${baseUrl}/alerting`); expect(req.request.method).toBe('GET'); - req.flush(mockAlerts); + req.flush({ data: mockAlerts, paginationData: { total: 2 } }); }); it('should fetch alerts with days parameter', () => { @@ -129,11 +129,14 @@ describe('AlertServiceService', () => { const fromDate = new Date(Date.now() - days * 24 * 60 * 60 * 1000).toISOString(); service.getAllAlerts(fromDate).subscribe((alerts) => { - expect(alerts).toEqual(mockAlerts); + expect(alerts).toEqual({ + alerts: mockAlerts, + total: 2, + }); }); const req = httpMock.expectOne(`${baseUrl}/alerting?offset=0&limit=10&fromDate=${fromDate}`); expect(req.request.method).toBe('GET'); - req.flush({ data: mockAlerts, paginationInfo: {} }); + req.flush({ data: mockAlerts, paginationData: { total: 2 } }); }); }); diff --git a/apps/frontend/src/app/shared/services/alert-service/alert-service.service.ts b/apps/frontend/src/app/shared/services/alert-service/alert-service.service.ts index 5dcf4db2..57a364d0 100644 --- a/apps/frontend/src/app/shared/services/alert-service/alert-service.service.ts +++ b/apps/frontend/src/app/shared/services/alert-service/alert-service.service.ts @@ -15,13 +15,21 @@ export class AlertServiceService { private readonly http: HttpClient ) {} - getAllAlerts(fromDate?: string, offset?: number): Observable { + getAllAlerts(fromDate?: string, offset?: number): Observable<{ alerts: Alert[], total: number }> { if (fromDate) { - return this.http.get<{ data: Alert[], paginationInfo: any }>(`${this.baseUrl}/alerting?offset=0&limit=10&fromDate=${fromDate}`).pipe( - map(response => response.data) + return this.http.get<{ data: Alert[], paginationData: { total: number } }>(`${this.baseUrl}/alerting?offset=0&limit=10&fromDate=${fromDate}`).pipe( + map(response => ({ + alerts: response.data, + total: response.paginationData.total + })) ); } - return this.http.get(`${this.baseUrl}/alerting`); + return this.http.get<{ data: Alert[], paginationData: { total: number } }>(`${this.baseUrl}/alerting`).pipe( + map(response => ({ + alerts: response.data, + total: response.paginationData.total + })) + ); } refresh() {