Skip to content

Commit ee7345f

Browse files
committed
fix: improve isEmpty checks for alert target and log objects
Signed-off-by: Manuel Abascal <mjabascal10@gmail.com>
1 parent e5877af commit ee7345f

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

frontend/src/app/data-management/alert-management/shared/components/alert-host-detail/alert-host-detail.component.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,18 @@ export class AlertHostDetailComponent implements OnInit {
3131
}
3232

3333
isEmpty(): boolean {
34-
return !this.alert || !this.alert[this.type] || Object.keys(this.alert[this.type]).length === 0;
34+
const value = this.alert[this.type];
35+
36+
if (value == null) { return true; }
37+
38+
if (typeof value !== 'object') { return true; }
39+
40+
if (Array.isArray(value)) { return value.length === 0; }
41+
42+
return Object.keys(value).length === 0 && value.constructor === Object;
3543
}
3644

45+
3746
getFields(obj: any, prefix = ''): { id: string; fieldType: UtmFieldType }[] {
3847
let fields: { id: string, fieldType: UtmFieldType}[] = [];
3948

frontend/src/app/data-management/alert-management/shared/components/alert-view-detail/alert-view-detail.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@
158158

159159

160160
<div class="d-flex w-100 gap-1 justify-content-between mb-3">
161-
<app-alert-host-detail *ngIf="alert.target" [alert]="alert" type="target" [hideEmptyField] = true class="w-45"></app-alert-host-detail>
161+
<app-alert-host-detail *ngIf="!isEmpty(alert.target)" [alert]="alert" type="target" [hideEmptyField] = true class="w-45"></app-alert-host-detail>
162162
<app-alert-host-detail [alert]="alert" type="adversary" [hideEmptyField] = true class="w-45"></app-alert-host-detail>
163163
</div>
164164
</div>

frontend/src/app/data-management/alert-management/shared/components/alert-view-detail/alert-view-detail.component.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,16 @@ export class AlertViewDetailComponent implements OnInit {
161161
return Object.entries(this.log).length === 0;
162162
}
163163

164-
protected readonly ALERT_ADVERSARY_FIELD = ALERT_ADVERSARY_FIELD;
164+
isEmpty(obj: any): boolean {
165+
if (obj == null) { return true; }
166+
167+
if (typeof obj !== 'object') { return true; }
168+
169+
if (Array.isArray(obj)) { return obj.length === 0; }
170+
171+
return Object.keys(obj).length === 0 && obj.constructor === Object;
172+
}
173+
165174
}
166175

167176
export enum AlertDetailTabEnum {

0 commit comments

Comments
 (0)