From ad5e3af1418ee3c03b650be04f85128d8874b627 Mon Sep 17 00:00:00 2001 From: Alisa Ismailati Date: Mon, 22 Jan 2024 16:59:10 +0100 Subject: [PATCH] [CST-12109] "refresh" page refactor --- .../qa-event-notification.component.ts | 14 ++--------- ...space-qa-events-notifications.component.ts | 7 +----- .../dso-withdrawn-reinstate-modal.service.ts | 24 ++++++++++++++++++- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/app/item-page/simple/qa-event-notification/qa-event-notification.component.ts b/src/app/item-page/simple/qa-event-notification/qa-event-notification.component.ts index d7bfb973782..e5f509c405e 100644 --- a/src/app/item-page/simple/qa-event-notification/qa-event-notification.component.ts +++ b/src/app/item-page/simple/qa-event-notification/qa-event-notification.component.ts @@ -1,4 +1,4 @@ -import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, OnChanges, SimpleChanges } from '@angular/core'; +import { ChangeDetectionStrategy, Component, Input, OnChanges, SimpleChanges } from '@angular/core'; import { Item } from '../../../core/shared/item.model'; import { getFirstCompletedRemoteData } from '../../../core/shared/operators'; import { Observable } from 'rxjs'; @@ -10,7 +10,6 @@ import { map } from 'rxjs/operators'; import { RemoteData } from '../../../core/data/remote-data'; import { getNotificatioQualityAssuranceRoute } from '../../../admin/admin-routing-paths'; import { PaginatedList } from 'src/app/core/data/paginated-list.model'; -import { NavigationEnd, Router } from '@angular/router'; @Component({ selector: 'ds-qa-event-notification', @@ -37,16 +36,7 @@ export class QaEventNotificationComponent implements OnChanges { */ constructor( private qualityAssuranceSourceDataService: QualityAssuranceSourceDataService, - private router: Router, - private chd: ChangeDetectorRef - ) { - this.router.events.pipe().subscribe((event) => { - if (event instanceof NavigationEnd) { - this.sources$ = this.getQualityAssuranceSources$(); - this.chd.markForCheck(); - } - }); - } + ) { } /** * Detect changes to the item input and update the sources$ observable. diff --git a/src/app/my-dspace-page/my-dspace-qa-events-notifications/my-dspace-qa-events-notifications.component.ts b/src/app/my-dspace-page/my-dspace-qa-events-notifications/my-dspace-qa-events-notifications.component.ts index 02de82a59f5..d383f3a728c 100644 --- a/src/app/my-dspace-page/my-dspace-qa-events-notifications/my-dspace-qa-events-notifications.component.ts +++ b/src/app/my-dspace-page/my-dspace-qa-events-notifications/my-dspace-qa-events-notifications.component.ts @@ -1,7 +1,7 @@ import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core'; import { QualityAssuranceSourceDataService } from '../../core/notifications/qa/source/quality-assurance-source-data.service'; import { getFirstCompletedRemoteData, getPaginatedListPayload, getRemoteDataPayload } from '../../core/shared/operators'; -import { Observable, of, tap } from 'rxjs'; +import { Observable, of } from 'rxjs'; import { QualityAssuranceSourceObject } from 'src/app/core/notifications/qa/models/quality-assurance-source.model'; import { getNotificatioQualityAssuranceRoute } from '../../admin/admin-routing-paths'; @@ -30,11 +30,6 @@ export class MyDspaceQaEventsNotificationsComponent implements OnInit { this.sources$ = this.qualityAssuranceSourceDataService.getSources() .pipe( getFirstCompletedRemoteData(), - tap((rd) => { - if (rd.hasFailed) { - throw new Error('Can\'t retrieve Quality Assurance sources'); - } - }), getRemoteDataPayload(), getPaginatedListPayload(), ); diff --git a/src/app/shared/dso-page/dso-withdrawn-reinstate-service/dso-withdrawn-reinstate-modal.service.ts b/src/app/shared/dso-page/dso-withdrawn-reinstate-service/dso-withdrawn-reinstate-modal.service.ts index 13e9490bd03..a4214099a72 100644 --- a/src/app/shared/dso-page/dso-withdrawn-reinstate-service/dso-withdrawn-reinstate-modal.service.ts +++ b/src/app/shared/dso-page/dso-withdrawn-reinstate-service/dso-withdrawn-reinstate-modal.service.ts @@ -50,6 +50,15 @@ export class DsoWithdrawnReinstateModalService { ); } + /** + * Sends a quality assurance request. + * + * @param target - The target - the item's UUID. + * @param correctionType - The type of correction. + * @param reason - The reason for the request. + * Reloads the current page in order to update the withdrawn/reinstate button. + * and desplay a notification box. + */ sendQARequest(target: string, correctionType: string, reason: string): void { this.qaEventDataService.postData(target, correctionType, '', reason) .pipe ( @@ -62,11 +71,24 @@ export class DsoWithdrawnReinstateModalService { const message = (correctionType === 'request-withdrawn') ? withdrawnMessage : reinstateMessage; this.notificationsService.success(this.translateService.get(message)); this.authorizationService.invalidateAuthorizationsRequestCache(); - this.router.navigate([this.router.url]); // refresh page + this.reloadPage(true); } else { this.notificationsService.error(this.translateService.get('correction-type.manage-relation.action.notification.error')); } }); } + + /** + * Reloads the current page or navigates to a specified URL. + * @param self - A boolean indicating whether to reload the current page (true) or navigate to a specified URL (false). + * @param urlToNavigateTo - The URL to navigate to if `self` is false. + * skipLocationChange:true means dont update the url to / when navigating + */ + reloadPage(self: boolean, urlToNavigateTo?: string) { + const url = self ? this.router.url : urlToNavigateTo; + this.router.navigateByUrl('/', { skipLocationChange: true }).then(() => { + this.router.navigate([`/${url}`]); + }); + } }