Skip to content

Commit afed768

Browse files
committed
feat(alert-detail): enhance alert detail component with improved layout and event handling
Signed-off-by: Manuel Abascal <mjabascal10@gmail.com>
1 parent 110ca6f commit afed768

File tree

1 file changed

+36
-20
lines changed

1 file changed

+36
-20
lines changed

frontend/src/app/data-management/alert-management/alert-full-detail/alert-full-detail.component.ts

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {HttpResponse} from '@angular/common/http';
2-
import {Component, OnInit} from '@angular/core';
2+
import {ChangeDetectorRef, Component, OnInit} from '@angular/core';
33
import {DomSanitizer} from '@angular/platform-browser';
44
import {ActivatedRoute, Router} from '@angular/router';
55
import * as moment from 'moment';
@@ -37,6 +37,7 @@ import {AlertDetailTabEnum} from '../shared/components/alert-view-detail/alert-v
3737
import {AlertHistoryActionEnum} from '../shared/enums/alert-history-action.enum';
3838
import {EventDataTypeEnum} from '../shared/enums/event-data-type.enum';
3939
import {AlertTagService} from '../shared/services/alert-tag.service';
40+
import {finalize} from "rxjs/operators";
4041

4142
@Component({
4243
selector: 'app-alert-full-detail',
@@ -100,7 +101,8 @@ export class AlertFullDetailComponent implements OnInit {
100101
private accountService: AccountService,
101102
private alertTagService: AlertTagService,
102103
private themeChangeBehavior: ThemeChangeBehavior,
103-
private activatedRoute: ActivatedRoute) {
104+
private activatedRoute: ActivatedRoute,
105+
private cdr: ChangeDetectorRef) {
104106
}
105107

106108
ngOnInit() {
@@ -137,35 +139,43 @@ export class AlertFullDetailComponent implements OnInit {
137139
}
138140

139141
searchAlert() {
140-
// this.spinner.show('alertDetail');
141142
this.elasticDataService.search(1, 1, 1, DataNatureTypeEnum.ALERT, this.filterAlert)
142-
.subscribe(response => {
143-
this.alert = response.body[0];
144-
this.loadingAlert = false;
145-
if (this.alert) {
146-
this.logs = this.alert.events;
143+
.pipe(finalize(() => this.loadingAlert = false))
144+
.subscribe({
145+
next: response => {
146+
this.alert = response.body[0];
147+
148+
if (!this.alert) {
149+
this.noAlertFound = true;
150+
return;
151+
}
152+
153+
this.logs = this.alert.events || [];
147154
this.log = this.alert.lastEvent || null;
148155
this.countRelatedEvents = this.logs.length;
156+
149157
const ref = this.alert.reference;
150-
this.reference = (ref && typeof ref !== 'string') ? ref : [];
158+
this.reference = Array.isArray(ref) ? ref : [];
159+
151160
this.relatedTagsRules = this.alert.tagRulesApplied;
161+
152162
this.filterEvent = [{
153163
field: 'id',
154164
operator: ElasticOperatorsEnum.IS_ONE_OF,
155-
value: this.alert.events.reverse().slice(0, 100)
165+
value: [...this.alert.events].reverse().slice(0, 100)
156166
}];
157-
this.resolveDataType().then(type => {
158-
this.dataType = type;
159-
});
160-
// this.searchLastLog();
167+
168+
this.resolveDataType().then(type => this.dataType = type);
169+
161170
this.searchEventByAlert();
162-
} else {
163-
this.noAlertFound = true;
171+
},
172+
error: () => {
164173
this.spinner.hide('alertDetail');
165174
}
166175
});
167176
}
168177

178+
169179
resolveDataType(): Promise<EventDataTypeEnum> {
170180
return new Promise<EventDataTypeEnum>(resolve => {
171181
resolve(EventDataTypeEnum.ALERT);
@@ -174,13 +184,19 @@ export class AlertFullDetailComponent implements OnInit {
174184

175185
searchEventByAlert() {
176186
this.elasticDataService.search(1, 100, 100, DataNatureTypeEnum.EVENT, this.filterEvent)
177-
.subscribe(reponse => {
178-
this.rows = reponse.body;
179-
this.loadingEvents = false;
180-
this.spinner.hide('alertDetail');
187+
.pipe(finalize(() => this.spinner.hide('alertDetail')))
188+
.subscribe({
189+
next: response => {
190+
this.rows = response.body;
191+
this.loadingEvents = false;
192+
},
193+
error: () => {
194+
this.loadingEvents = false;
195+
}
181196
});
182197
}
183198

199+
184200
print() {
185201
this.printFormat = true;
186202
setTimeout(() => {

0 commit comments

Comments
 (0)