From 322dccdb4d903264467c50c51e826441ad799055 Mon Sep 17 00:00:00 2001 From: Joao Silva <100691367+JoaoSilvaGrafana@users.noreply.github.com> Date: Wed, 9 Oct 2024 15:53:05 +0100 Subject: [PATCH] Navigation: Fix wrong active item shown when parent is bookmarked (#94478) --- .../AppChrome/MegaMenu/utils.test.ts | 20 +++++++++++++++++++ .../components/AppChrome/MegaMenu/utils.ts | 4 +++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/public/app/core/components/AppChrome/MegaMenu/utils.test.ts b/public/app/core/components/AppChrome/MegaMenu/utils.test.ts index 0a99bffd6b3..ea5a289bd95 100644 --- a/public/app/core/components/AppChrome/MegaMenu/utils.test.ts +++ b/public/app/core/components/AppChrome/MegaMenu/utils.test.ts @@ -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'); }); diff --git a/public/app/core/components/AppChrome/MegaMenu/utils.ts b/public/app/core/components/AppChrome/MegaMenu/utils.ts index ab41e68dee6..e8864399a0c 100644 --- a/public/app/core/components/AppChrome/MegaMenu/utils.ts +++ b/public/app/core/components/AppChrome/MegaMenu/utils.ts @@ -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); }