@@ -11,16 +11,16 @@ import { Component, computed, inject, output } from '@angular/core';
1111import { toSignal } from '@angular/core/rxjs-interop' ;
1212import { ActivatedRoute , NavigationEnd , Router , RouterLink , RouterLinkActive } from '@angular/router' ;
1313
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' ;
1817import { AuthSelectors } from '@osf/features/auth/store' ;
1918import { IconComponent } from '@osf/shared/components' ;
19+ import { WrapFnPipe } from '@osf/shared/pipes' ;
2020
2121@Component ( {
2222 selector : 'osf-nav-menu' ,
23- imports : [ RouterLinkActive , RouterLink , PanelMenuModule , TranslatePipe , IconComponent ] ,
23+ imports : [ RouterLinkActive , RouterLink , PanelMenuModule , TranslatePipe , IconComponent , WrapFnPipe ] ,
2424 templateUrl : './nav-menu.component.html' ,
2525 styleUrl : './nav-menu.component.scss' ,
2626} )
@@ -32,47 +32,23 @@ export class NavMenuComponent {
3232
3333 private readonly isAuthenticated = select ( AuthSelectors . isAuthenticated ) ;
3434
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-
6135 protected readonly mainMenuItems = computed ( ( ) => {
6236 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 ) ;
7450
75- return this . isCollectionsRoute ( ) ? menuItems : menuItems . filter ( ( item ) => item . routerLink !== '/collections' ) ;
51+ return items ;
7652 } ) ;
7753
7854 protected readonly currentRoute = toSignal (
@@ -86,25 +62,27 @@ export class NavMenuComponent {
8662 ) ;
8763
8864 protected readonly currentResourceId = computed ( ( ) => this . currentRoute ( ) . resourceId ) ;
65+ protected readonly currentProviderId = computed ( ( ) => this . currentRoute ( ) . providerId ) ;
8966 protected readonly isProjectRoute = computed ( ( ) => ! ! this . currentResourceId ( ) ) ;
9067 protected readonly isCollectionsRoute = computed ( ( ) => this . currentRoute ( ) . isCollectionsWithId ) ;
9168 protected readonly isRegistryRoute = computed ( ( ) => this . currentRoute ( ) . isRegistryRoute ) ;
92- protected readonly isRegistryRouteDetails = computed ( ( ) => this . currentRoute ( ) . isRegistryRouteDetails ) ;
69+ protected readonly isPreprintRoute = computed ( ( ) => this . currentRoute ( ) . isPreprintRoute ) ;
9370
9471 private getRouteInfo ( ) {
9572 const urlSegments = this . router . url . split ( '/' ) . filter ( ( segment ) => segment ) ;
9673 const resourceFromQueryParams = this . route . snapshot . queryParams [ 'resourceId' ] ;
9774 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' ] ;
9976 const isCollectionsWithId = urlSegments [ 0 ] === 'collections' && urlSegments [ 1 ] && urlSegments [ 1 ] !== '' ;
10077 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+
10280 return {
10381 resourceId,
104- section ,
82+ providerId ,
10583 isCollectionsWithId,
10684 isRegistryRoute,
107- isRegistryRouteDetails ,
85+ isPreprintRoute ,
10886 } ;
10987 }
11088
@@ -113,4 +91,7 @@ export class NavMenuComponent {
11391 this . closeMenu . emit ( ) ;
11492 }
11593 }
94+
95+ protected readonly hasVisibleChildren = ( item : MenuItem ) : boolean =>
96+ Array . isArray ( item . items ) && item . items . some ( ( child ) => ! ! child . visible ) ;
11697}
0 commit comments