Skip to content

Commit bb02acf

Browse files
committed
Fix id related issues and add accessibility handle
1 parent 8b9af3b commit bb02acf

6 files changed

Lines changed: 25 additions & 14 deletions

File tree

src/app/shared/menu/menu-provider.model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { MenuRoute } from './menu-route.model';
1919
*/
2020
export interface PartialMenuSection {
2121
id?: string;
22+
accessibilityHandle?: string;
2223
visible: boolean;
2324
model: MenuItemModels;
2425
parentID?: string;

src/app/shared/menu/menu-section.model.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ export interface MenuSection {
1919
*/
2020
id: string;
2121

22+
/**
23+
* Accessibility handle that can be used to find a specific menu in the html
24+
*/
25+
accessibilityHandle?: string;
26+
2227
/**
2328
* Whether this section should be visible.
2429
*/

src/app/shared/menu/menu.structure.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,11 @@ function addProviderToList(providers: Provider[], providerType: Type<AbstractMen
8383
provider.index = provider.index ?? index;
8484
if (hasValue(parentID)) {
8585
provider.menuProviderId = provider.menuProviderId ?? `${parentID}_${index}`;
86-
provider.parentID = provider.parentID ?? parentID;
86+
let providerParentID = provider.parentID;
87+
if (hasValue(providerParentID)) {
88+
providerParentID = `${providerParentID}_0`;
89+
}
90+
provider.parentID = providerParentID ?? parentID;
8791
} else {
8892
provider.menuProviderId = provider.menuProviderId ?? `${menuID}_${index}`;
8993
}

src/app/shared/menu/providers/helper-providers/expandable-menu-provider.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ describe('AbstractExpandableMenuProvider', () => {
5959
type: MenuItemType.TEXT,
6060
text: 'sub.section.test.1',
6161
},
62-
id: `${MenuID.ADMIN}_1_0`,
63-
parentID: `${MenuID.ADMIN}_1`,
62+
id: `${MenuID.ADMIN}_1_0_0`,
63+
parentID: `${MenuID.ADMIN}_1_0`,
6464
alwaysRenderExpandable: false,
6565
},
6666
{
@@ -69,8 +69,8 @@ describe('AbstractExpandableMenuProvider', () => {
6969
type: MenuItemType.TEXT,
7070
text: 'sub.section.test.2',
7171
},
72-
id: `${MenuID.ADMIN}_1_1`,
73-
parentID: `${MenuID.ADMIN}_1`,
72+
id: `${MenuID.ADMIN}_1_0_1`,
73+
parentID: `${MenuID.ADMIN}_1_0`,
7474
alwaysRenderExpandable: false,
7575
},
7676
{
@@ -80,9 +80,9 @@ describe('AbstractExpandableMenuProvider', () => {
8080
text: 'top.section.test',
8181
},
8282
icon: 'file-import',
83-
id: `${MenuID.ADMIN}_1`,
83+
id: `${MenuID.ADMIN}_1_0`,
8484
alwaysRenderExpandable: true,
85-
}
85+
},
8686
];
8787

8888
let provider: AbstractExpandableMenuProvider;

src/app/shared/menu/providers/helper-providers/expandable-menu-provider.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,14 @@ export abstract class AbstractExpandableMenuProvider extends AbstractMenuProvide
3636
this.getSubSections(),
3737
]).pipe(
3838
map((
39-
[partialTopSection, partialSubSections]: [PartialMenuSection, PartialMenuSection[]]
39+
[partialTopSection, partialSubSections]: [PartialMenuSection, PartialMenuSection[]],
4040
) => {
41+
const parentID = partialTopSection.id ?? this.getAutomatedSectionIdForTopSection();
4142
const subSections = partialSubSections.map((partialSub, index) => {
4243
return {
4344
...partialSub,
44-
id: partialSub.id ?? `${this.menuProviderId}_${index}`,
45-
parentID: this.menuProviderId,
45+
id: partialSub.id ?? this.getAutomatedSectionIdForSubsection(index),
46+
parentID: parentID,
4647
alwaysRenderExpandable: false,
4748
};
4849
});
@@ -51,19 +52,19 @@ export abstract class AbstractExpandableMenuProvider extends AbstractMenuProvide
5152
...subSections,
5253
{
5354
...partialTopSection,
54-
id: this.menuProviderId,
55+
id: parentID,
5556
alwaysRenderExpandable: this.alwaysRenderExpandable,
5657
},
5758
];
58-
})
59+
}),
5960
);
6061
}
6162

6263
protected getAutomatedSectionIdForTopSection(): string {
6364
return this.getAutomatedSectionId(0);
6465
}
6566
protected getAutomatedSectionIdForSubsection(indexOfSubSectionInProvider: number): string {
66-
return `${this.menuProviderId}_0_${indexOfSubSectionInProvider}`;
67+
return `${this.getAutomatedSectionIdForTopSection()}_${indexOfSubSectionInProvider}`;
6768
}
6869

6970
}

src/app/shared/menu/providers/helper-providers/route-context.menu.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { CacheableObject } from '../../../../core/cache/cacheable-object.model';
1616
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
1717

1818

19-
describe('AbstractExpandableMenuProvider', () => {
19+
describe('AbstractRouteContextMenuProvider', () => {
2020

2121
class TestClass extends AbstractRouteContextMenuProvider<CacheableObject> {
2222
getRouteContext(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<CacheableObject> {

0 commit comments

Comments
 (0)