55import {
66 Component ,
77 Input ,
8+ OnChanges ,
9+ SimpleChanges ,
810} from '@angular/core' ;
911import { RouterLink } from '@angular/router' ;
1012import { TranslateModule } from '@ngx-translate/core' ;
@@ -45,31 +47,42 @@ import {
4547/**
4648 * Component displaying alerts for an item
4749 */
48- export class ItemAlertsComponent {
50+ export class ItemAlertsComponent implements OnChanges {
4951 /**
5052 * The Item to display alerts for
5153 */
5254 @Input ( ) item : Item ;
5355
56+ /**
57+ * Whether the reinstate button should be shown
58+ */
59+ showReinstateButton$ : Observable < boolean > ;
60+
5461 /**
5562 * The AlertType enumeration
5663 * @type {AlertType }
5764 */
5865 public AlertTypeEnum = AlertType ;
5966
6067 constructor (
61- private authService : AuthorizationDataService ,
62- private dsoWithdrawnReinstateModalService : DsoWithdrawnReinstateModalService ,
63- private correctionTypeDataService : CorrectionTypeDataService ,
68+ protected authService : AuthorizationDataService ,
69+ protected dsoWithdrawnReinstateModalService : DsoWithdrawnReinstateModalService ,
70+ protected correctionTypeDataService : CorrectionTypeDataService ,
6471 ) {
6572 }
6673
74+ ngOnChanges ( changes : SimpleChanges ) : void {
75+ if ( changes . item ?. currentValue . withdrawn && this . showReinstateButton$ ) {
76+ this . showReinstateButton$ = this . shouldShowReinstateButton ( ) ;
77+ }
78+ }
79+
6780 /**
6881 * Determines whether to show the reinstate button.
6982 * The button is shown if the user is not an admin and the item has a reinstate request.
7083 * @returns An Observable that emits a boolean value indicating whether to show the reinstate button.
7184 */
72- showReinstateButton$ ( ) : Observable < boolean > {
85+ shouldShowReinstateButton ( ) : Observable < boolean > {
7386 const correction$ = this . correctionTypeDataService . findByItem ( this . item . uuid , true ) . pipe (
7487 getFirstCompletedRemoteData ( ) ,
7588 map ( ( correctionTypeRD : RemoteData < PaginatedList < CorrectionType > > ) => correctionTypeRD . hasSucceeded ? correctionTypeRD . payload . page : [ ] ) ,
@@ -78,8 +91,8 @@ export class ItemAlertsComponent {
7891 return combineLatest ( [ isAdmin$ , correction$ ] ) . pipe (
7992 map ( ( [ isAdmin , correction ] ) => {
8093 return ! isAdmin && correction . some ( ( correctionType ) => correctionType . topic === REQUEST_REINSTATE ) ;
81- } ,
82- ) ) ;
94+ } ) ,
95+ ) ;
8396 }
8497
8598 /**
0 commit comments