@@ -11,16 +11,16 @@ import { Component, computed, inject, output } from '@angular/core';
11
11
import { toSignal } from '@angular/core/rxjs-interop' ;
12
12
import { ActivatedRoute , NavigationEnd , Router , RouterLink , RouterLinkActive } from '@angular/router' ;
13
13
14
- import { MENU_ITEMS , MODERATION_MENU_ITEM , PROJECT_MENU_ITEMS , REGISTRATION_MENU_ITEMS } from '@core/constants' ;
15
- import { filterMenuItems } from '@osf/core/helpers' ;
16
- import { ProviderSelectors } from '@osf/core/store/provider' ;
17
- import { UserSelectors } from '@osf/core/store/user' ;
14
+ import { MENU_ITEMS } from '@core/constants' ;
15
+ import { filterMenuItems , updateMenuItems } from '@osf/core/helpers' ;
16
+ import { RouteContext } from '@osf/core/models' ;
18
17
import { AuthSelectors } from '@osf/features/auth/store' ;
19
18
import { IconComponent } from '@osf/shared/components' ;
19
+ import { WrapFnPipe } from '@osf/shared/pipes' ;
20
20
21
21
@Component ( {
22
22
selector : 'osf-nav-menu' ,
23
- imports : [ RouterLinkActive , RouterLink , PanelMenuModule , TranslatePipe , IconComponent ] ,
23
+ imports : [ RouterLinkActive , RouterLink , PanelMenuModule , TranslatePipe , IconComponent , WrapFnPipe ] ,
24
24
templateUrl : './nav-menu.component.html' ,
25
25
styleUrl : './nav-menu.component.scss' ,
26
26
} )
@@ -32,47 +32,23 @@ export class NavMenuComponent {
32
32
33
33
private readonly isAuthenticated = select ( AuthSelectors . isAuthenticated ) ;
34
34
35
- protected readonly myProjectMenuItems = PROJECT_MENU_ITEMS ;
36
- protected readonly registrationMenuItems = computed ( ( ) => {
37
- const menu = [ ...REGISTRATION_MENU_ITEMS ] ;
38
- if ( this . isUserModerator ( ) ) {
39
- const menuItems = menu [ 0 ] . items ?? [ ] ;
40
- if ( ! menuItems . some ( ( item ) => item . label === MODERATION_MENU_ITEM . label ) ) {
41
- menuItems . push ( MODERATION_MENU_ITEM ) ;
42
- }
43
- }
44
- const withRouterLinks = menu . map ( ( section ) => ( {
45
- ...section ,
46
- items : section . items ?. map ( ( item ) => {
47
- const isModerationPage = item . state && item . state [ 'isModeration' ] ;
48
- const routeId = isModerationPage ? this . provider ( ) ?. id : this . currentResourceId ( ) ;
49
- return {
50
- ...item ,
51
- routerLink : item . routerLink ? [ '/registries' , routeId , item . routerLink ] : null ,
52
- queryParams : isModerationPage ? { resourceId : this . currentResourceId ( ) } : { } ,
53
- } ;
54
- } ) ,
55
- } ) ) ;
56
- return withRouterLinks ;
57
- } ) ;
58
- protected readonly isUserModerator = select ( UserSelectors . isCurrentUserModerator ) ;
59
- protected readonly provider = select ( ProviderSelectors . getCurrentProvider ) ;
60
-
61
35
protected readonly mainMenuItems = computed ( ( ) => {
62
36
const isAuthenticated = this . isAuthenticated ( ) ;
63
- const menuItems = filterMenuItems ( MENU_ITEMS , isAuthenticated ) ;
64
-
65
- if ( this . isRegistryRouteDetails ( ) ) {
66
- menuItems . map ( ( menuItem ) => {
67
- if ( menuItem . id === 'registries' ) {
68
- menuItem . expanded = true ;
69
- return menuItem ;
70
- }
71
- return menuItem ;
72
- } ) ;
73
- }
37
+ const filtered = filterMenuItems ( MENU_ITEMS , isAuthenticated ) ;
38
+
39
+ const routeContext : RouteContext = {
40
+ resourceId : this . currentResourceId ( ) ,
41
+ providerId : this . currentProviderId ( ) ,
42
+ isProject : this . isProjectRoute ( ) && ! this . isRegistryRoute ( ) && ! this . isPreprintRoute ( ) ,
43
+ isRegistry : this . isRegistryRoute ( ) ,
44
+ isPreprint : this . isPreprintRoute ( ) ,
45
+ isCollections : this . isCollectionsRoute ( ) || false ,
46
+ currentUrl : this . router . url ,
47
+ } ;
48
+
49
+ const items = updateMenuItems ( filtered , routeContext ) ;
74
50
75
- return this . isCollectionsRoute ( ) ? menuItems : menuItems . filter ( ( item ) => item . routerLink !== '/collections' ) ;
51
+ return items ;
76
52
} ) ;
77
53
78
54
protected readonly currentRoute = toSignal (
@@ -86,25 +62,27 @@ export class NavMenuComponent {
86
62
) ;
87
63
88
64
protected readonly currentResourceId = computed ( ( ) => this . currentRoute ( ) . resourceId ) ;
65
+ protected readonly currentProviderId = computed ( ( ) => this . currentRoute ( ) . providerId ) ;
89
66
protected readonly isProjectRoute = computed ( ( ) => ! ! this . currentResourceId ( ) ) ;
90
67
protected readonly isCollectionsRoute = computed ( ( ) => this . currentRoute ( ) . isCollectionsWithId ) ;
91
68
protected readonly isRegistryRoute = computed ( ( ) => this . currentRoute ( ) . isRegistryRoute ) ;
92
- protected readonly isRegistryRouteDetails = computed ( ( ) => this . currentRoute ( ) . isRegistryRouteDetails ) ;
69
+ protected readonly isPreprintRoute = computed ( ( ) => this . currentRoute ( ) . isPreprintRoute ) ;
93
70
94
71
private getRouteInfo ( ) {
95
72
const urlSegments = this . router . url . split ( '/' ) . filter ( ( segment ) => segment ) ;
96
73
const resourceFromQueryParams = this . route . snapshot . queryParams [ 'resourceId' ] ;
97
74
const resourceId = this . route . firstChild ?. snapshot . params [ 'id' ] || resourceFromQueryParams ;
98
- const section = this . route . firstChild ?. firstChild ?. snapshot . url [ 0 ] ?. path || 'overview' ;
75
+ const providerId = this . route . firstChild ?. snapshot . params [ 'providerId' ] ;
99
76
const isCollectionsWithId = urlSegments [ 0 ] === 'collections' && urlSegments [ 1 ] && urlSegments [ 1 ] !== '' ;
100
77
const isRegistryRoute = urlSegments [ 0 ] === 'registries' && ! ! urlSegments [ 2 ] ;
101
- const isRegistryRouteDetails = urlSegments [ 0 ] === 'registries' && urlSegments [ 2 ] === 'overview' ;
78
+ const isPreprintRoute = urlSegments [ 0 ] === 'preprints' && ! ! urlSegments [ 2 ] ;
79
+
102
80
return {
103
81
resourceId,
104
- section ,
82
+ providerId ,
105
83
isCollectionsWithId,
106
84
isRegistryRoute,
107
- isRegistryRouteDetails ,
85
+ isPreprintRoute ,
108
86
} ;
109
87
}
110
88
@@ -113,4 +91,7 @@ export class NavMenuComponent {
113
91
this . closeMenu . emit ( ) ;
114
92
}
115
93
}
94
+
95
+ protected readonly hasVisibleChildren = ( item : MenuItem ) : boolean =>
96
+ Array . isArray ( item . items ) && item . items . some ( ( child ) => ! ! child . visible ) ;
116
97
}
0 commit comments