From af62a1de8ecb9852cffad39936c58053826767fe Mon Sep 17 00:00:00 2001 From: Matthijs Smets Date: Tue, 22 Oct 2024 16:27:04 +0200 Subject: [PATCH 1/2] refactor: refreshing debug tab can now be done with conditions, to allow not showing the Data loaded toast --- src/app/debug/debug-tab.service.ts | 25 +++++++------- .../debug/debug-tree/debug-tree.component.ts | 33 +++++++++++-------- src/app/debug/table/table.component.ts | 25 +++++++++----- .../edit-display/edit-display.component.ts | 5 +-- .../shared/interfaces/refresh-condition.ts | 4 +++ 5 files changed, 57 insertions(+), 35 deletions(-) create mode 100644 src/app/shared/interfaces/refresh-condition.ts diff --git a/src/app/debug/debug-tab.service.ts b/src/app/debug/debug-tab.service.ts index b0ed5b23..7c084a67 100644 --- a/src/app/debug/debug-tab.service.ts +++ b/src/app/debug/debug-tab.service.ts @@ -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 = new Subject(); - private refreshTableSubject: Subject = new Subject(); - private refreshTreeSubject: Subject = new Subject(); + private refreshAllSubject: Subject = new Subject(); + private refreshTableSubject: Subject = new Subject(); + private refreshTreeSubject: Subject = new Subject(); - refreshAll$: Observable = this.refreshAllSubject.asObservable(); - refreshTable$: Observable = this.refreshTableSubject.asObservable(); - refreshTree$: Observable = this.refreshTreeSubject.asObservable(); + refreshAll$: Observable = this.refreshAllSubject.asObservable(); + refreshTable$: Observable = this.refreshTableSubject.asObservable(); + refreshTree$: Observable = 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); } } diff --git a/src/app/debug/debug-tree/debug-tree.component.ts b/src/app/debug/debug-tree/debug-tree.component.ts index 356e5a55..6fdc4a7c 100644 --- a/src/app/debug/debug-tree/debug-tree.component.ts +++ b/src/app/debug/debug-tree/debug-tree.component.ts @@ -23,6 +23,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', @@ -85,9 +86,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); } @@ -181,21 +186,23 @@ export class DebugTreeComponent implements OnDestroy { return false; } - async refreshReports(ids: number[]): Promise { + async refreshReports(condition: RefreshCondition): Promise { 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); } diff --git a/src/app/debug/table/table.component.ts b/src/app/debug/table/table.component.ts index eaef647d..9267afda 100644 --- a/src/app/debug/table/table.component.ts +++ b/src/app/debug/table/table.component.ts @@ -34,6 +34,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', @@ -183,9 +184,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); } @@ -214,14 +217,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())) @@ -231,7 +234,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!'); + } }, }); } @@ -464,9 +469,13 @@ export class TableComponent implements OnInit, OnDestroy { this.retrieveRecords(); } - refresh(): void { + refresh(refreshCondition?: RefreshCondition): void { this.tableSettings.displayAmount = 10; - this.loadData(); + if (refreshCondition) { + this.loadData(refreshCondition.displayToast); + } else { + this.loadData(); + } } openReport(storageId: number): void { diff --git a/src/app/report/edit-display/edit-display.component.ts b/src/app/report/edit-display/edit-display.component.ts index c3adaea7..bd747803 100644 --- a/src/app/report/edit-display/edit-display.component.ts +++ b/src/app/report/edit-display/edit-display.component.ts @@ -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 }); }, }); } @@ -297,7 +297,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.'); }, }); } diff --git a/src/app/shared/interfaces/refresh-condition.ts b/src/app/shared/interfaces/refresh-condition.ts new file mode 100644 index 00000000..6430d1d9 --- /dev/null +++ b/src/app/shared/interfaces/refresh-condition.ts @@ -0,0 +1,4 @@ +export interface RefreshCondition { + reportIds?: number[]; + displayToast?: boolean; +} From 9790f37b51ae2fb891b8af132527f6e796b5ec3e Mon Sep 17 00:00:00 2001 From: Matthijs Smets Date: Wed, 23 Oct 2024 18:19:13 +0200 Subject: [PATCH 2/2] refactor: fix linting issues from merging with github UI --- src/app/debug/table/table.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/debug/table/table.component.ts b/src/app/debug/table/table.component.ts index 6130d86c..8491f3ca 100644 --- a/src/app/debug/table/table.component.ts +++ b/src/app/debug/table/table.component.ts @@ -481,7 +481,7 @@ export class TableComponent implements OnInit, OnDestroy { this.loadData(); } } - + openReport(storageId: number): void { this.httpService .getReport(storageId, this.currentView.storageName)