Skip to content

Commit

Permalink
Add loading indicators and error handling for async data (#422)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeknovy authored Sep 30, 2024
1 parent 79e8c55 commit 28441c1
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/app/dashboard/dashboard.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ <h6 class="card-header bg-transparent">Recent Test Runs</h6>
</tr>
</thead>
<tbody>
<tr *ngIf="!latestItems || latestItems.length === 0">
<tr *ngIf="!isLoading && latestItems.length === 0">
<td colspan="5" class="text-muted no-data">Nothing here yet! Upload some test reports. <span><a href="https://jtlreporter.site/docs/guides/manual-data-upload">Show me how!</a></span></td>
</tr>
<tr *ngFor="let _ of latestItems" (click)="open(_.projectName, _.name, _.id)">
Expand Down
24 changes: 17 additions & 7 deletions src/app/dashboard/dashboard.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,24 @@ import { ItemsListing, ProjectsOverallStats } from "../items.service.model";
import { Router } from "@angular/router";
import { SharedMainBarService } from "../shared-main-bar.service";
import { getValidationResults } from "../utils/showZeroErrorTolerance";
import { catchError } from "rxjs/operators";
import { of } from "rxjs";

@Component({
selector: "app-dashboard",
templateUrl: "./dashboard.component.html",
styleUrls: ["./dashboard.component.css", "../shared-styles.css"]
selector: 'app-dashboard',
templateUrl: './dashboard.component.html',
styleUrls: ['./dashboard.component.css', '../shared-styles.css']
})
export class DashboardComponent implements OnInit {
latestItems: ItemsListing[];
overallStats: ProjectsOverallStats;
Math: Math;
isLoading = true;

constructor(
private projectService: ProjectApiService,
private router: Router,
private sharedMainBarService: SharedMainBarService
private sharedMainBarService: SharedMainBarService,
) {
this.Math = Math;
}
Expand All @@ -31,8 +34,13 @@ export class DashboardComponent implements OnInit {

fetchLatestItems() {
this.projectService.fetchLatestItems()
.pipe(catchError(r => {
this.isLoading = false;
return of(r);
}))
.subscribe(_ => {
this.latestItems = _;
this.isLoading = false;
});
}

Expand All @@ -45,12 +53,14 @@ export class DashboardComponent implements OnInit {
}

displayItemValidationError(zeroErrorEnabled, errorCount, errorRate, duration, minTestDuration) {
const { zeroErrorToleranceValidation, minTestDurationValidation } = getValidationResults(zeroErrorEnabled, errorRate, errorCount, duration, minTestDuration);
return zeroErrorToleranceValidation || minTestDurationValidation
const {
zeroErrorToleranceValidation,
minTestDurationValidation
} = getValidationResults(zeroErrorEnabled, errorRate, errorCount, duration, minTestDuration);
return zeroErrorToleranceValidation || minTestDurationValidation;
}



isValidationEnabled(zeroErrorEnabled, minTestDuration): boolean {
return zeroErrorEnabled || minTestDuration > 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/scenario/scenario.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ <h6 class="card-header bg-transparent">Test Runs
</th>
</tr>
</thead>
<tbody *ngIf="items.data.length === 0">
<tbody *ngIf="!isLoading && items.data.length === 0">
<tr>
<td colspan="8" class="text-muted text-center">Nothing here yet! Please upload some test reports.</td>
</tr>
Expand Down
13 changes: 12 additions & 1 deletion src/app/scenario/scenario.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class ScenarioComponent implements OnInit, OnDestroy {
isAnonymous = false;
validationEnabled = false
minTestDuration = null
isLoading = true;

constructor(
private route: ActivatedRoute,
Expand Down Expand Up @@ -59,7 +60,17 @@ export class ScenarioComponent implements OnInit, OnDestroy {
});

if (!this.isAnonymous) {
this.items$ = this.itemsService.items$;
this.items$ = this.itemsService.items$
this.items$
.pipe(catchError(r => {
this.isLoading = false;
return of(r);
}))
.subscribe(items => {
if (items.name) {
this.isLoading = false;
}
})
this.environment$ = this.environmentService.environment$.subscribe(value => this.page = 1);

this.route.params.pipe<any>(
Expand Down

0 comments on commit 28441c1

Please sign in to comment.