Navigation: Fix wrong active item shown when parent is bookmarked (#94478)

This commit is contained in:
Joao Silva 2024-10-09 15:53:05 +01:00 committed by GitHub
parent 55d970ef9a
commit 322dccdb4d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 1 deletions

View File

@ -5,6 +5,22 @@ import { enrichHelpItem, getActiveItem, findByUrl } from './utils';
const starredDashboardUid = 'foo';
const mockNavTree: NavModelItem[] = [
{
text: 'Bookmarks',
url: '/bookmarks',
id: 'bookmarks',
children: [
{
text: 'Item with children',
url: '/itemWithChildren',
id: 'item-with-children',
parentItem: {
text: 'Bookmarks',
id: 'bookmarks',
},
},
],
},
{
text: 'Item',
url: '/item',
@ -112,6 +128,10 @@ describe('getActiveItem', () => {
const mockPage: NavModelItem = {
text: 'Some child page',
id: 'child',
parentItem: {
text: 'Item with children',
id: 'item-with-children',
},
};
expect(getActiveItem(mockNavTree, mockPage)?.id).toEqual('child');
});

View File

@ -98,7 +98,9 @@ export const getActiveItem = (
}
}
if (parentItem) {
// Do not search for the parent in the bookmarks section
const isInBookmarksSection = navTree[0]?.parentItem?.id === 'bookmarks';
if (parentItem && !isInBookmarksSection) {
return getActiveItem(navTree, parentItem);
}