@@ -23,6 +23,7 @@ import {
2323 Subject ,
2424} from 'rxjs' ;
2525import {
26+ catchError ,
2627 first ,
2728 map ,
2829 startWith ,
@@ -59,44 +60,58 @@ export class SubscribeMenuProvider extends DSpaceObjectPageMenuProvider {
5960 if ( ! isPlatformBrowser ( this . platformId ) ) {
6061 return of ( [ ] ) ;
6162 }
62- const realSections$ = this . refresh$ . pipe (
63- startWith ( undefined ) ,
64- switchMap ( ( ) =>
65- combineLatest ( [
66- this . authorizationService . isAuthorized ( FeatureID . CanSubscribe , dso . self ) ,
67- this . authService . getAuthenticatedUserFromStore ( ) . pipe ( first ( ) ) ,
68- ] ) ,
69- ) ,
63+
64+ // 1. Crear un ID único desde el principio
65+ const sectionId = `subscribe-section-${ dso . uuid } ` ;
66+
67+ return this . refresh$ . pipe (
68+ startWith ( null ) , // Inicializar el flujo
69+ switchMap ( ( ) => combineLatest ( [
70+ this . authorizationService . isAuthorized ( FeatureID . CanSubscribe , dso . self ) ,
71+ this . authService . getAuthenticatedUserFromStore ( ) . pipe ( first ( ) ) ,
72+ ] ) ) ,
7073 switchMap ( ( [ canSubscribe , user ] ) => {
74+ // 2. Siempre retornar estructura con ID incluso si no hay permiso
75+ const baseSection = {
76+ id : sectionId ,
77+ visible : false ,
78+ model : null ,
79+ } as PartialMenuSection ;
80+
7181 if ( ! canSubscribe || ! user ) {
72- return of ( [ ] ) ;
82+ // 3. Emitir sección oculta pero con ID válido
83+ return of ( [ baseSection ] ) ;
7384 }
85+
7486 const openModal = ( ) => {
7587 const modalRef = this . modalService . open ( SubscriptionModalComponent ) ;
7688 modalRef . componentInstance . dso = dso ;
7789 modalRef . componentInstance . updated . subscribe ( ( ) => this . refresh$ . next ( ) ) ;
7890 } ;
91+
7992 return this . subscriptionService . getSubscriptionsByPersonDSO ( user . id , dso . uuid ) . pipe (
80- map ( ( rd ) => {
93+ map ( rd => {
8194 const subscription = rd . payload ?. page ?. [ 0 ] ;
82- const key = subscription ? 'subscriptions.manage' : 'subscriptions.tooltip' ;
83- return [
84- {
85- visible : true ,
86- model : {
87- type : MenuItemType . ONCLICK ,
88- text : key ,
89- function : openModal ,
90- } as OnClickMenuItemModel ,
91- icon : 'bell' ,
92- } as PartialMenuSection ,
93- ] ;
95+ return [ {
96+ ...baseSection ,
97+ visible : true ,
98+ model : {
99+ type : MenuItemType . ONCLICK ,
100+ text : subscription ? 'subscriptions.manage' : 'subscriptions.tooltip' ,
101+ function : openModal ,
102+ } as OnClickMenuItemModel ,
103+ icon : 'bell' ,
104+ } ] ;
94105 } ) ,
106+ catchError ( ( ) => of ( [ baseSection ] ) ) , // 4. En errores mantener sección oculta
95107 ) ;
96108 } ) ,
97- ) ;
98- return realSections$ . pipe (
99- startWith ( [ ] as PartialMenuSection [ ] ) ,
109+ // 5. Inicializar con la estructura básica
110+ startWith ( [ {
111+ id : sectionId ,
112+ visible : false ,
113+ model : null ,
114+ } as PartialMenuSection ] ) ,
100115 ) ;
101116 }
102117}
0 commit comments