Skip to content

Commit f2a012c

Browse files
committed
feat(dashboard-render): improve dashboard loading logic and enhance error handling for filters
Signed-off-by: Manuel Abascal <mjabascal10@gmail.com>
1 parent a2d52aa commit f2a012c

2 files changed

Lines changed: 25 additions & 12 deletions

File tree

frontend/src/app/dashboard/dashboard-render/dashboard-render.component.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div class="container-fluid pr-2 pl-2 pt-2">
2-
<div *ngIf="dashboard" class="d-flex justify-content-between align-items-center mb-2">
2+
<div *ngIf="dashboard?.name" class="d-flex justify-content-between align-items-center mb-2">
33
<h5 class="card-title mb-0 label-header">{{dashboard.name}}
44
</h5>
55
<div class="header-elements d-flex justify-content-end align-items-center">
@@ -17,9 +17,9 @@ <h5 class="card-title mb-0 label-header">{{dashboard.name}}
1717
</div>
1818
</div>
1919
<div class="w-100 h-100 mb-3">
20-
<gridster [options]="options" style="background-color: #f1f1f1;z-index: 0; margin-bottom: 15px">
20+
<gridster *ngIf="(layout$ | async) as layout" [options]="options" style="background-color: #f1f1f1;z-index: 0; margin-bottom: 15px">
2121
<gridster-item #gridsterItem
22-
*ngFor="let item of layout$ | async; trackBy: trackByFn; let index = index" [item]="item.grid"
22+
*ngFor="let item of layout; trackBy: trackByFn; let index = index" [item]="item.grid"
2323
(mouseenter)="activeTimeGridster=item.visualization.id"
2424
[ngStyle]="{'z-index':(activeTimeGridster===item.visualization.id?100:0)+''}">
2525
<app-utm-viewer [building]="false"
@@ -36,7 +36,7 @@ <h5 class="card-title mb-0 label-header">{{dashboard.name}}
3636
<div style="height: 15px"></div>
3737
</div>
3838

39-
<div *ngIf="!loadingVisualizations"
39+
<div *ngIf="loadingVisualizations"
4040
class="dashboard-loader d-flex justify-content-start align-content-center w-100 h-100">
4141
<app-utm-spinner [height]="'110px'" [loading]="!loadingVisualizations" [width]="'110px'"
4242
label="Loading dashboard"

frontend/src/app/dashboard/dashboard-render/dashboard-render.component.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,31 @@ export class DashboardRenderComponent implements OnInit, OnDestroy, AfterViewIni
7373
}
7474

7575
ngOnInit() {
76+
7677
document.body.classList.add('overflow-hidden');
7778
this.loadingVisualizations = true;
78-
this.layout$ = this.activatedRoute.data
79-
.pipe(
80-
tap((visualizations) => {
81-
this.dashboard = this.layoutService.dashboard;
82-
this.filters = this.dashboard && this.dashboard.filters ? JSON.parse(this.dashboard.filters) : [];
83-
this.loadingVisualizations = false;
84-
}),
85-
map(data => data.response)
79+
80+
this.layout$ = this.activatedRoute.data.pipe(
81+
map(data => {
82+
const response = data && data.response ? data.response : [];
83+
84+
this.dashboard = this.layoutService.dashboard ? this.layoutService.dashboard : null;
85+
86+
try {
87+
this.filters = this.dashboard && this.dashboard.filters
88+
? JSON.parse(this.dashboard.filters)
89+
: [];
90+
} catch {
91+
this.filters = [];
92+
}
93+
94+
this.loadingVisualizations = false;
95+
96+
return response;
97+
})
8698
);
8799

100+
88101
this.dashboardBehavior.$filterDashboard.subscribe(dashboardFilter => {
89102
if (dashboardFilter) {
90103
mergeParams(dashboardFilter.filter, this.filtersValues).then(newFilters => {

0 commit comments

Comments
 (0)