From 585e01de2b35582f1afa984ce35b99541239af41 Mon Sep 17 00:00:00 2001 From: SuZhou-Joe Date: Wed, 14 Aug 2024 11:29:11 +0800 Subject: [PATCH] feat: append navLinks inside second level to custom category if no entry for the nav group Signed-off-by: SuZhou-Joe --- .../collapsible_nav_group_enabled.test.tsx | 42 +++++++++++++++++++ .../header/collapsible_nav_group_enabled.tsx | 16 +++++++ 2 files changed, 58 insertions(+) diff --git a/src/core/public/chrome/ui/header/collapsible_nav_group_enabled.test.tsx b/src/core/public/chrome/ui/header/collapsible_nav_group_enabled.test.tsx index e0530b8a6289..25ce7cf41d80 100644 --- a/src/core/public/chrome/ui/header/collapsible_nav_group_enabled.test.tsx +++ b/src/core/public/chrome/ui/header/collapsible_nav_group_enabled.test.tsx @@ -287,4 +287,46 @@ describe('', () => { ); expect(queryAllByTestId('collapsibleNavAppLink-link-in-all').length).toEqual(1); }); + + it('should show links with custom category if the nav link is inside second level but no entry in all use case', async () => { + const props = mockProps({ + currentNavGroupId: ALL_USE_CASE_ID, + navGroupsMap: { + [DEFAULT_NAV_GROUPS.essentials.id]: { + ...DEFAULT_NAV_GROUPS.essentials, + navLinks: [ + { + id: 'link-in-essentials', + title: 'link-in-essentials', + }, + { + id: 'link-in-all', + title: 'link-in-all', + }, + ], + }, + }, + navLinks: [ + { + id: 'link-in-essentials', + title: 'link-in-essentials', + baseUrl: '', + href: '', + }, + { + id: 'link-in-all', + title: 'link-in-all', + baseUrl: '', + href: '', + }, + ], + }); + const { queryAllByTestId, getByText, getByTestId } = render( + + ); + // Should render custom category + expect(getByText('Custom')).toBeInTheDocument(); + expect(getByTestId('collapsibleNavAppLink-link-in-essentials')).toBeInTheDocument(); + expect(queryAllByTestId('collapsibleNavAppLink-link-in-all').length).toEqual(1); + }); }); diff --git a/src/core/public/chrome/ui/header/collapsible_nav_group_enabled.tsx b/src/core/public/chrome/ui/header/collapsible_nav_group_enabled.tsx index 35668a1a727b..af67974ecb9d 100644 --- a/src/core/public/chrome/ui/header/collapsible_nav_group_enabled.tsx +++ b/src/core/public/chrome/ui/header/collapsible_nav_group_enabled.tsx @@ -312,6 +312,22 @@ export function CollapsibleNavGroupEnabled({ order: Number.MAX_SAFE_INTEGER, category: categoryInfo, }); + } else { + /** + * Find if there are any links inside a use case but without a `see all` entry. + * If so, append these features into custom category as a fallback + */ + fulfillRegistrationLinksToChromeNavLinks(group.navLinks, navLinks) + // Filter out links that already exists in all use case + .filter( + (navLink) => !navLinksForAll.find((navLinkInAll) => navLinkInAll.id === navLink.id) + ) + .forEach((navLink) => { + navLinksForAll.push({ + ...navLink, + category: customCategory, + }); + }); } });