Skip to content

Commit

Permalink
117287: Fixed UI freezing on withdrawn item pages
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrevryghem committed Oct 29, 2024
1 parent d3de28d commit 638fba5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/app/item-page/alerts/item-alerts.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<span class="align-self-center">{{'item.alerts.withdrawn' | translate}}</span>
<div class="gap-2 d-flex">
<a routerLink="/home" class="btn btn-primary btn-sm">{{"404.link.home-page" | translate}}</a>
<a *ngIf="showReinstateButton$() | async" class="btn btn-primary btn-sm" (click)="openReinstateModal()">{{ 'item.alerts.reinstate-request' | translate}}</a>
<a *ngIf="showReinstateButton$ | async" class="btn btn-primary btn-sm" (click)="openReinstateModal()">{{ 'item.alerts.reinstate-request' | translate}}</a>
</div>
</div>
</ds-alert>
Expand Down
27 changes: 20 additions & 7 deletions src/app/item-page/alerts/item-alerts.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
import {
Component,
Input,
OnChanges,
SimpleChanges,
} from '@angular/core';
import { RouterLink } from '@angular/router';
import { TranslateModule } from '@ngx-translate/core';
Expand Down Expand Up @@ -45,31 +47,42 @@ import {
/**
* Component displaying alerts for an item
*/
export class ItemAlertsComponent {
export class ItemAlertsComponent implements OnChanges {
/**
* The Item to display alerts for
*/
@Input() item: Item;

/**
* Whether the reinstate button should be shown
*/
showReinstateButton$: Observable<boolean>;

/**
* The AlertType enumeration
* @type {AlertType}
*/
public AlertTypeEnum = AlertType;

constructor(
private authService: AuthorizationDataService,
private dsoWithdrawnReinstateModalService: DsoWithdrawnReinstateModalService,
private correctionTypeDataService: CorrectionTypeDataService,
protected authService: AuthorizationDataService,
protected dsoWithdrawnReinstateModalService: DsoWithdrawnReinstateModalService,
protected correctionTypeDataService: CorrectionTypeDataService,
) {
}

ngOnChanges(changes: SimpleChanges): void {
if (changes.item?.currentValue.withdrawn && this.showReinstateButton$) {
this.showReinstateButton$ = this.shouldShowReinstateButton();
}
}

/**
* Determines whether to show the reinstate button.
* The button is shown if the user is not an admin and the item has a reinstate request.
* @returns An Observable that emits a boolean value indicating whether to show the reinstate button.
*/
showReinstateButton$(): Observable<boolean> {
shouldShowReinstateButton(): Observable<boolean> {
const correction$ = this.correctionTypeDataService.findByItem(this.item.uuid, true).pipe(
getFirstCompletedRemoteData(),
map((correctionTypeRD: RemoteData<PaginatedList<CorrectionType>>) => correctionTypeRD.hasSucceeded ? correctionTypeRD.payload.page : []),
Expand All @@ -78,8 +91,8 @@ export class ItemAlertsComponent {
return combineLatest([isAdmin$, correction$]).pipe(
map(([isAdmin, correction]) => {
return !isAdmin && correction.some((correctionType) => correctionType.topic === REQUEST_REINSTATE);
},
));
}),
);
}

/**
Expand Down

0 comments on commit 638fba5

Please sign in to comment.