mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-15 22:13:02 +00:00
Fix id related issues and add accessibility handle
This commit is contained in:
@@ -19,6 +19,7 @@ import { MenuRoute } from './menu-route.model';
|
|||||||
*/
|
*/
|
||||||
export interface PartialMenuSection {
|
export interface PartialMenuSection {
|
||||||
id?: string;
|
id?: string;
|
||||||
|
accessibilityHandle?: string;
|
||||||
visible: boolean;
|
visible: boolean;
|
||||||
model: MenuItemModels;
|
model: MenuItemModels;
|
||||||
parentID?: string;
|
parentID?: string;
|
||||||
|
@@ -19,6 +19,11 @@ export interface MenuSection {
|
|||||||
*/
|
*/
|
||||||
id: string;
|
id: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Accessibility handle that can be used to find a specific menu in the html
|
||||||
|
*/
|
||||||
|
accessibilityHandle?: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether this section should be visible.
|
* Whether this section should be visible.
|
||||||
*/
|
*/
|
||||||
|
@@ -83,7 +83,11 @@ function addProviderToList(providers: Provider[], providerType: Type<AbstractMen
|
|||||||
provider.index = provider.index ?? index;
|
provider.index = provider.index ?? index;
|
||||||
if (hasValue(parentID)) {
|
if (hasValue(parentID)) {
|
||||||
provider.menuProviderId = provider.menuProviderId ?? `${parentID}_${index}`;
|
provider.menuProviderId = provider.menuProviderId ?? `${parentID}_${index}`;
|
||||||
provider.parentID = provider.parentID ?? parentID;
|
let providerParentID = provider.parentID;
|
||||||
|
if (hasValue(providerParentID)) {
|
||||||
|
providerParentID = `${providerParentID}_0`;
|
||||||
|
}
|
||||||
|
provider.parentID = providerParentID ?? parentID;
|
||||||
} else {
|
} else {
|
||||||
provider.menuProviderId = provider.menuProviderId ?? `${menuID}_${index}`;
|
provider.menuProviderId = provider.menuProviderId ?? `${menuID}_${index}`;
|
||||||
}
|
}
|
||||||
|
@@ -59,8 +59,8 @@ describe('AbstractExpandableMenuProvider', () => {
|
|||||||
type: MenuItemType.TEXT,
|
type: MenuItemType.TEXT,
|
||||||
text: 'sub.section.test.1',
|
text: 'sub.section.test.1',
|
||||||
},
|
},
|
||||||
id: `${MenuID.ADMIN}_1_0`,
|
id: `${MenuID.ADMIN}_1_0_0`,
|
||||||
parentID: `${MenuID.ADMIN}_1`,
|
parentID: `${MenuID.ADMIN}_1_0`,
|
||||||
alwaysRenderExpandable: false,
|
alwaysRenderExpandable: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -69,8 +69,8 @@ describe('AbstractExpandableMenuProvider', () => {
|
|||||||
type: MenuItemType.TEXT,
|
type: MenuItemType.TEXT,
|
||||||
text: 'sub.section.test.2',
|
text: 'sub.section.test.2',
|
||||||
},
|
},
|
||||||
id: `${MenuID.ADMIN}_1_1`,
|
id: `${MenuID.ADMIN}_1_0_1`,
|
||||||
parentID: `${MenuID.ADMIN}_1`,
|
parentID: `${MenuID.ADMIN}_1_0`,
|
||||||
alwaysRenderExpandable: false,
|
alwaysRenderExpandable: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -80,9 +80,9 @@ describe('AbstractExpandableMenuProvider', () => {
|
|||||||
text: 'top.section.test',
|
text: 'top.section.test',
|
||||||
},
|
},
|
||||||
icon: 'file-import',
|
icon: 'file-import',
|
||||||
id: `${MenuID.ADMIN}_1`,
|
id: `${MenuID.ADMIN}_1_0`,
|
||||||
alwaysRenderExpandable: true,
|
alwaysRenderExpandable: true,
|
||||||
}
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
let provider: AbstractExpandableMenuProvider;
|
let provider: AbstractExpandableMenuProvider;
|
||||||
|
@@ -36,13 +36,14 @@ export abstract class AbstractExpandableMenuProvider extends AbstractMenuProvide
|
|||||||
this.getSubSections(),
|
this.getSubSections(),
|
||||||
]).pipe(
|
]).pipe(
|
||||||
map((
|
map((
|
||||||
[partialTopSection, partialSubSections]: [PartialMenuSection, PartialMenuSection[]]
|
[partialTopSection, partialSubSections]: [PartialMenuSection, PartialMenuSection[]],
|
||||||
) => {
|
) => {
|
||||||
|
const parentID = partialTopSection.id ?? this.getAutomatedSectionIdForTopSection();
|
||||||
const subSections = partialSubSections.map((partialSub, index) => {
|
const subSections = partialSubSections.map((partialSub, index) => {
|
||||||
return {
|
return {
|
||||||
...partialSub,
|
...partialSub,
|
||||||
id: partialSub.id ?? `${this.menuProviderId}_${index}`,
|
id: partialSub.id ?? this.getAutomatedSectionIdForSubsection(index),
|
||||||
parentID: this.menuProviderId,
|
parentID: parentID,
|
||||||
alwaysRenderExpandable: false,
|
alwaysRenderExpandable: false,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@@ -51,11 +52,11 @@ export abstract class AbstractExpandableMenuProvider extends AbstractMenuProvide
|
|||||||
...subSections,
|
...subSections,
|
||||||
{
|
{
|
||||||
...partialTopSection,
|
...partialTopSection,
|
||||||
id: this.menuProviderId,
|
id: parentID,
|
||||||
alwaysRenderExpandable: this.alwaysRenderExpandable,
|
alwaysRenderExpandable: this.alwaysRenderExpandable,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
})
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,7 +64,7 @@ export abstract class AbstractExpandableMenuProvider extends AbstractMenuProvide
|
|||||||
return this.getAutomatedSectionId(0);
|
return this.getAutomatedSectionId(0);
|
||||||
}
|
}
|
||||||
protected getAutomatedSectionIdForSubsection(indexOfSubSectionInProvider: number): string {
|
protected getAutomatedSectionIdForSubsection(indexOfSubSectionInProvider: number): string {
|
||||||
return `${this.menuProviderId}_0_${indexOfSubSectionInProvider}`;
|
return `${this.getAutomatedSectionIdForTopSection()}_${indexOfSubSectionInProvider}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -16,7 +16,7 @@ import { CacheableObject } from '../../../../core/cache/cacheable-object.model';
|
|||||||
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
|
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
|
||||||
|
|
||||||
|
|
||||||
describe('AbstractExpandableMenuProvider', () => {
|
describe('AbstractRouteContextMenuProvider', () => {
|
||||||
|
|
||||||
class TestClass extends AbstractRouteContextMenuProvider<CacheableObject> {
|
class TestClass extends AbstractRouteContextMenuProvider<CacheableObject> {
|
||||||
getRouteContext(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<CacheableObject> {
|
getRouteContext(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<CacheableObject> {
|
||||||
|
Reference in New Issue
Block a user