Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: updating report does not show Data loaded toast #744

Merged
merged 3 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions src/app/debug/debug-tab.service.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
import { Injectable } from '@angular/core';
import { Observable, Subject } from 'rxjs';
import { RefreshCondition } from '../shared/interfaces/refresh-condition';

@Injectable({
providedIn: 'root',
})
export class DebugTabService {
private refreshAllSubject: Subject<number[]> = new Subject();
private refreshTableSubject: Subject<void> = new Subject();
private refreshTreeSubject: Subject<number[]> = new Subject();
private refreshAllSubject: Subject<RefreshCondition> = new Subject();
private refreshTableSubject: Subject<RefreshCondition> = new Subject();
private refreshTreeSubject: Subject<RefreshCondition> = new Subject();

refreshAll$: Observable<number[]> = this.refreshAllSubject.asObservable();
refreshTable$: Observable<void> = this.refreshTableSubject.asObservable();
refreshTree$: Observable<number[]> = this.refreshTreeSubject.asObservable();
refreshAll$: Observable<RefreshCondition> = this.refreshAllSubject.asObservable();
refreshTable$: Observable<RefreshCondition> = this.refreshTableSubject.asObservable();
refreshTree$: Observable<RefreshCondition> = this.refreshTreeSubject.asObservable();

// triggers a refresh that refreshes both the debug table and the debug tree
refreshAll(reportIds: number[]): void {
this.refreshAllSubject.next(reportIds);
refreshAll(condition: RefreshCondition): void {
this.refreshAllSubject.next(condition);
}

// triggers a refresh that refreshes only the debug table
refreshTable(): void {
this.refreshTableSubject.next();
refreshTable(condition?: RefreshCondition): void {
this.refreshTableSubject.next(condition ?? ({} as RefreshCondition));
}

//triggers a refresh that refreshes only the debug tree and the reports in the debug tree where the reportId is present in the argument
refreshTree(reportIds: number[]): void {
this.refreshTreeSubject.next(reportIds);
refreshTree(condition: RefreshCondition): void {
this.refreshTreeSubject.next(condition);
}
}
33 changes: 20 additions & 13 deletions src/app/debug/debug-tree/debug-tree.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { SimpleFileTreeUtil } from '../../shared/util/simple-file-tree-util';
import { View } from '../../shared/interfaces/view';
import { DebugTabService } from '../debug-tab.service';
import { ErrorHandling } from '../../shared/classes/error-handling.service';
import { RefreshCondition } from '../../shared/interfaces/refresh-condition';

@Component({
selector: 'app-debug-tree',
Expand Down Expand Up @@ -83,9 +84,13 @@ export class DebugTreeComponent implements OnDestroy {
},
});
this.subscriptions.add(showMultipleSubscription);
const refreshAll: Subscription = this.debugTab.refreshAll$.subscribe((ids: number[]) => this.refreshReports(ids));
const refreshAll: Subscription = this.debugTab.refreshAll$.subscribe((condition: RefreshCondition) =>
this.refreshReports(condition),
);
this.subscriptions.add(refreshAll);
const refreshTree: Subscription = this.debugTab.refreshTree$.subscribe((ids: number[]) => this.refreshReports(ids));
const refreshTree: Subscription = this.debugTab.refreshTree$.subscribe((condition: RefreshCondition) =>
this.refreshReports(condition),
);
this.subscriptions.add(refreshTree);
}

Expand Down Expand Up @@ -190,21 +195,23 @@ export class DebugTreeComponent implements OnDestroy {
return false;
}

async refreshReports(ids: number[]): Promise<void> {
async refreshReports(condition: RefreshCondition): Promise<void> {
const selectedReportId = this.tree.getSelected().originalValue.storageId;
let lastSelectedReport: FileTreeItem | undefined;
for (let i = 0; i < this.tree.items.length; i++) {
const report: Report = this.tree.items[i].originalValue as Report;
if (ids.includes(report.storageId)) {
const fileItem: FileTreeItem = await this.getNewReport(report.storageId);
if (selectedReportId === report.storageId) {
lastSelectedReport = fileItem;
if (condition.reportIds) {
for (let i = 0; i < this.tree.items.length; i++) {
const report: Report = this.tree.items[i].originalValue as Report;
if (condition.reportIds.includes(report.storageId)) {
const fileItem: FileTreeItem = await this.getNewReport(report.storageId);
if (selectedReportId === report.storageId) {
lastSelectedReport = fileItem;
}
this.tree.items[i] = fileItem;
}
this.tree.items[i] = fileItem;
}
}
if (lastSelectedReport) {
this.tree.selectItem(lastSelectedReport.path);
if (lastSelectedReport) {
this.tree.selectItem(lastSelectedReport.path);
}
}
this.hideOrShowCheckpointsBasedOnView(this._currentView);
}
Expand Down
25 changes: 17 additions & 8 deletions src/app/debug/table/table.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { CompareReport } from '../../shared/interfaces/compare-reports';
import { DebugTabService } from '../debug-tab.service';
import { ViewDropdownComponent } from '../../shared/components/view-dropdown/view-dropdown.component';
import { DeleteModalComponent } from '../../shared/components/delete-modal/delete-modal.component';
import { RefreshCondition } from '../../shared/interfaces/refresh-condition';

@Component({
selector: 'app-table',
Expand Down Expand Up @@ -181,9 +182,11 @@ export class TableComponent implements OnInit, OnDestroy {
error: () => catchError(this.errorHandler.handleError()),
});
this.subscriptions.add(filterContextSubscription);
const refreshAll = this.debugTab.refreshAll$.subscribe(() => this.refresh());
const refreshAll = this.debugTab.refreshAll$.subscribe((condition: RefreshCondition) => this.refresh(condition));
this.subscriptions.add(refreshAll);
const refreshTable = this.debugTab.refreshTable$.subscribe(() => this.refresh());
const refreshTable = this.debugTab.refreshTable$.subscribe((condition: RefreshCondition) =>
this.refresh(condition),
);
this.subscriptions.add(refreshTable);
const amountOfRecordsInTableSubscription = this.settingsService.amountOfRecordsInTableObservable.subscribe(
(value) => (this.tableSettings.displayAmount = value),
Expand Down Expand Up @@ -216,14 +219,14 @@ export class TableComponent implements OnInit, OnDestroy {
this.retrieveRecords();
}

loadData(): void {
this.retrieveRecords();
loadData(showToast: boolean = true): void {
this.retrieveRecords(showToast);
this.loadMetadataCount();
this.loadReportInProgressThreshold();
this.loadReportInProgressSettings();
}

retrieveRecords() {
retrieveRecords(showToast: boolean = true) {
this.httpService
.getMetadataReports(this.tableSettings, this.currentView)
.pipe(catchError(this.errorHandler.handleError()))
Expand All @@ -233,7 +236,9 @@ export class TableComponent implements OnInit, OnDestroy {
this.tableSettings.reportMetadata = value;
this.tableDataSource.data = value;
this.tableSettings.tableLoaded = true;
this.toastService.showSuccess('Data loaded!');
if (showToast) {
this.toastService.showSuccess('Data loaded!');
}
},
});
}
Expand Down Expand Up @@ -469,8 +474,12 @@ export class TableComponent implements OnInit, OnDestroy {
}
}

refresh(): void {
this.loadData();
refresh(refreshCondition?: RefreshCondition): void {
if (refreshCondition) {
this.loadData(refreshCondition.displayToast);
} else {
this.loadData();
}
}

openReport(storageId: number): void {
Expand Down
5 changes: 3 additions & 2 deletions src/app/report/edit-display/edit-display.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export class EditDisplayComponent implements OnChanges {
next: (response: TestResult): void => {
this.toastService.showSuccess('Report rerun successful');
this.rerunResult = response;
this.debugTab.refreshTable();
this.debugTab.refreshTable({ displayToast: false });
},
});
} else {
Expand Down Expand Up @@ -300,7 +300,8 @@ export class EditDisplayComponent implements OnChanges {
this.selectedNode = response.report;
}
this.disableEditing();
this.debugTab.refreshAll([+storageId]);
this.debugTab.refreshAll({ reportIds: [+storageId], displayToast: false });
this.toastService.showSuccess('Report updated successfully.');
},
});
}
Expand Down
4 changes: 4 additions & 0 deletions src/app/shared/interfaces/refresh-condition.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface RefreshCondition {
reportIds?: number[];
displayToast?: boolean;
}
Loading