TopNav: Fixes breadcrumb issues and title for apps when topnav is disabled (#61835)

This commit is contained in:
Torkel Ödegaard 2023-01-23 11:03:28 +01:00 committed by GitHub
parent 97fc6c4eb4
commit cd99bfec68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 2 deletions

View File

@ -144,5 +144,22 @@ describe('breadcrumb utils', () => {
{ text: 'My page', href: '/my-page' },
]);
});
it('Should add breadcrumbs for child pages that have not set parentItem', () => {
const pageNav: NavModelItem = {
text: 'My page',
url: '/my-page',
children: [
{ text: 'A', url: '/a', active: true },
{ text: 'B', url: '/b' },
],
};
expect(buildBreadcrumbs(mockHomeNav, pageNav, mockHomeNav)).toEqual([
{ text: 'Home', href: '/home' },
{ text: 'My page', href: '/my-page' },
{ text: 'A', href: '/a' },
]);
});
});
});

View File

@ -16,6 +16,7 @@ export function buildBreadcrumbs(sectionNav: NavModelItem, pageNav?: NavModelIte
if (urlSearchParams.has('editview')) {
urlToMatch += `?editview=${urlSearchParams.get('editview')}`;
}
if (!foundHome && !node.hideFromBreadcrumbs) {
if (homeNav && urlToMatch === homeNav.url) {
crumbs.unshift({ text: getNavTitle(homeNav.id) ?? homeNav.text, href: node.url ?? '' });
@ -31,8 +32,19 @@ export function buildBreadcrumbs(sectionNav: NavModelItem, pageNav?: NavModelIte
}
if (pageNav) {
if (pageNav.url && pageNav.children) {
const child = pageNav.children.find((child) => child.active);
if (child) {
addCrumbs(child);
// Some pages set up children but they are not connected to parent pageNav
if (child.parentItem !== pageNav) {
addCrumbs(pageNav);
}
}
} else {
addCrumbs(pageNav);
}
}
addCrumbs(sectionNav);

View File

@ -112,7 +112,8 @@ const stateSlice = createSlice({
...pluginNav,
node: {
...pluginNav.main,
hideFromBreadcrumbs: true,
// Because breadcumbs code is also used to set title when topnav should only set hideFromBreadcrumbs when topnav is enabled
hideFromBreadcrumbs: config.featureToggles.topnav,
},
};
}