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 23c4156 commit c54fcb8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 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
21 changes: 17 additions & 4 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,12 +47,17 @@ 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}
Expand All @@ -64,12 +71,18 @@ export class ItemAlertsComponent {
) {
}

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 c54fcb8

Please sign in to comment.