Skip to content

Commit

Permalink
[CST-12109] "refresh" page refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
alisaismailati committed Jan 22, 2024
1 parent e4858f2 commit ad5e3af
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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',
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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(),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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}`]);
});
}
}

0 comments on commit ad5e3af

Please sign in to comment.