Skip to content

Commit

Permalink
feat: append navLinks inside second level to custom category if no en…
Browse files Browse the repository at this point in the history
…try for the nav group

Signed-off-by: SuZhou-Joe <[email protected]>
  • Loading branch information
SuZhou-Joe committed Aug 14, 2024
1 parent b4b421c commit 585e01d
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -287,4 +287,46 @@ describe('<CollapsibleNavGroupEnabled />', () => {
);
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(
<CollapsibleNavGroupEnabled {...props} isNavOpen />
);
// Should render custom category
expect(getByText('Custom')).toBeInTheDocument();
expect(getByTestId('collapsibleNavAppLink-link-in-essentials')).toBeInTheDocument();
expect(queryAllByTestId('collapsibleNavAppLink-link-in-all').length).toEqual(1);
});
});
16 changes: 16 additions & 0 deletions src/core/public/chrome/ui/header/collapsible_nav_group_enabled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
});
}
});

Expand Down

0 comments on commit 585e01d

Please sign in to comment.