From 4f1013a20d1be64c2517d15bbf6ef94b622ce72a Mon Sep 17 00:00:00 2001 From: Yana De Pauw Date: Mon, 20 Jan 2025 13:27:36 +0100 Subject: [PATCH] Fix small issues --- src/app/app.menus.ts | 1 - src/app/shared/menu/menu-provider.model.ts | 7 +++++-- src/app/shared/menu/menu-provider.service.ts | 15 ++++++++------- src/app/shared/menu/menu.structure.ts | 2 +- .../helper-providers/expandable-menu-provider.ts | 8 ++++++++ src/app/shared/menu/providers/item-claim.menu.ts | 2 +- 6 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/app/app.menus.ts b/src/app/app.menus.ts index 8240a9cb1b..b4989b4bb6 100644 --- a/src/app/app.menus.ts +++ b/src/app/app.menus.ts @@ -73,7 +73,6 @@ export const MENUS = buildMenuStructure({ ClaimMenuProvider.onRoute( MenuRoute.SIMPLE_ITEM_PAGE, MenuRoute.FULL_ITEM_PAGE, - MenuRoute.SIMPLE_COLLECTION_PAGE, ), ]), ], diff --git a/src/app/shared/menu/menu-provider.model.ts b/src/app/shared/menu/menu-provider.model.ts index 8a517934b9..026ef034bd 100644 --- a/src/app/shared/menu/menu-provider.model.ts +++ b/src/app/shared/menu/menu-provider.model.ts @@ -22,7 +22,6 @@ export interface PartialMenuSection { visible: boolean; model: MenuItemModels; parentID?: string; - index?: number; active?: boolean; shouldPersistOnRouteChange?: boolean; icon?: string; @@ -65,7 +64,7 @@ export abstract class AbstractMenuProvider implements MenuProvider { /** * ID of the menu this provider is part of - * If not set up, this will be set based on the provider class name + * This will be set to the menu ID of the menu in which it is present in the app.menus.ts file */ menuID?: MenuID; @@ -144,6 +143,10 @@ export abstract class AbstractMenuProvider implements MenuProvider { */ abstract getSections(route?: ActivatedRouteSnapshot, state?: RouterStateSnapshot): Observable; + protected getAutomatedSectionId(indexOfSectionInProvider: number): string { + return `${this.menuProviderId}_${indexOfSectionInProvider};` + } + } diff --git a/src/app/shared/menu/menu-provider.service.ts b/src/app/shared/menu/menu-provider.service.ts index c0f34be481..2ef19010c1 100644 --- a/src/app/shared/menu/menu-provider.service.ts +++ b/src/app/shared/menu/menu-provider.service.ts @@ -92,8 +92,8 @@ export class MenuProviderService { provider: AbstractMenuProvider, sections: PartialMenuSection[] }, sectionIndex) => { - providerWithSection.sections.forEach((section) => { - this.addSection(providerWithSection.provider, section); + providerWithSection.sections.forEach((section, index) => { + this.addSection(providerWithSection.provider, section, index); }); return this.waitForMenu$(providerWithSection.provider.menuID); }); @@ -156,8 +156,8 @@ export class MenuProviderService { provider: AbstractMenuProvider, sections: PartialMenuSection[] }) => { - providerWithSection.sections.forEach((section) => { - this.addSection(providerWithSection.provider, section); + providerWithSection.sections.forEach((section, index) => { + this.addSection(providerWithSection.provider, section, index); }); return this.waitForMenu$(providerWithSection.provider.menuID); }); @@ -172,12 +172,13 @@ export class MenuProviderService { * @param provider - The provider of the section which will be used to provide extra data to the section * @param section - The partial section to be added to the menus */ - private addSection(provider: AbstractMenuProvider, section: PartialMenuSection) { + private addSection(provider: AbstractMenuProvider, section: PartialMenuSection, index: number) { this.menuService.addSection(provider.menuID, { ...section, - id: section.id ?? `${provider.menuProviderId}`, + id: section.id ?? `${provider.menuProviderId}_${index}`, parentID: section.parentID ?? provider.parentID, - index: section.index ?? provider.index, + index: provider.index, + active: section.active ?? true, shouldPersistOnRouteChange: section.shouldPersistOnRouteChange ?? provider.shouldPersistOnRouteChange, alwaysRenderExpandable: section.alwaysRenderExpandable ?? provider.alwaysRenderExpandable, }); diff --git a/src/app/shared/menu/menu.structure.ts b/src/app/shared/menu/menu.structure.ts index 81103ce182..0541d110e0 100644 --- a/src/app/shared/menu/menu.structure.ts +++ b/src/app/shared/menu/menu.structure.ts @@ -53,7 +53,7 @@ function processProviderType(providers: Provider[], menuID: string, providerType const childProviderTypes = (providerType as any).childProviderTypes; childProviderTypes.forEach((childProviderType, childIndex: number) => { - processProviderType(providers, menuID, childProviderType, childIndex, `${menuID}_${index}`, hasSubProviders); + processProviderType(providers, menuID, childProviderType, childIndex, `${menuID}_${index}_0`, hasSubProviders); }); processProviderType(providers, menuID, providerPart, index, parentID, true); diff --git a/src/app/shared/menu/providers/helper-providers/expandable-menu-provider.ts b/src/app/shared/menu/providers/helper-providers/expandable-menu-provider.ts index e95aa80103..40ab500268 100644 --- a/src/app/shared/menu/providers/helper-providers/expandable-menu-provider.ts +++ b/src/app/shared/menu/providers/helper-providers/expandable-menu-provider.ts @@ -58,4 +58,12 @@ export abstract class AbstractExpandableMenuProvider extends AbstractMenuProvide }) ); } + + protected getAutomatedSectionIdForTopSection(): string { + return this.getAutomatedSectionId(0); + } + protected getAutomatedSectionIdForSubsection(indexOfSubSectionInProvider: number): string { + return `${this.menuProviderId}_0_${indexOfSubSectionInProvider};` + } + } diff --git a/src/app/shared/menu/providers/item-claim.menu.ts b/src/app/shared/menu/providers/item-claim.menu.ts index 06f26a773d..e61872a704 100644 --- a/src/app/shared/menu/providers/item-claim.menu.ts +++ b/src/app/shared/menu/providers/item-claim.menu.ts @@ -81,7 +81,7 @@ export class ClaimMenuProvider extends DSpaceObjectPageMenuProvider { this.translate.get('researcherprofile.success.claim.body'), ); this.authorizationService.invalidateAuthorizationsRequestCache(); - this.menuService.hideMenuSection(MenuID.DSO_EDIT, this.menuProviderId); + this.menuService.hideMenuSection(MenuID.DSO_EDIT, this.getAutomatedSectionId(0)); } else { this.notificationsService.error( this.translate.get('researcherprofile.error.claim.title'),