Skip to content

Commit

Permalink
feat: update snapshot
Browse files Browse the repository at this point in the history
Signed-off-by: SuZhou-Joe <suzhou@amazon.com>
  • Loading branch information
SuZhou-Joe committed Jul 21, 2024
1 parent 66b9b49 commit 3670a30
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 27 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,24 @@ describe('<CollapsibleNavGroupEnabled />', () => {
fireEvent.click(getByTestId('back'));
expect(getAllByTestId('collapsibleNavAppLink-link-in-analytics').length).toEqual(2);
});

it('should hide left navigation when in home page', async () => {
const props = mockProps({
navGroupsMap: {
[DEFAULT_NAV_GROUPS.analytics.id]: {
...DEFAULT_NAV_GROUPS.analytics,
navLinks: [
{
id: 'link-in-analytics',
title: 'link-in-analytics',
showInAllNavGroup: true,
},
],
},
},
});
props.appId$ = new BehaviorSubject('home');
const { container } = render(<CollapsibleNavGroupEnabled {...props} isNavOpen />);
expect(container).toMatchSnapshot();
});
});
50 changes: 27 additions & 23 deletions src/core/public/chrome/ui/header/collapsible_nav_group_enabled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,29 +183,6 @@ export function CollapsibleNavGroupEnabled({
const navGroupsMap = useObservable(observables.navGroupsMap$, {});
const currentNavGroup = useObservable(observables.currentNavGroup$, undefined);

const onGroupClick = (
e: React.MouseEvent<HTMLButtonElement, MouseEvent>,
group: NavGroupItemInMap
) => {
const fulfilledLinks = fulfillRegistrationLinksToChromeNavLinks(
navGroupsMap[group.id]?.navLinks,
navLinks
);
setCurrentNavGroup(group.id);

// the `navGroupsMap[group.id]?.navLinks` has already been sorted
const firstLink = fulfilledLinks[0];
if (firstLink) {
const propsForEui = createEuiListItem({
link: firstLink,
appId,
dataTestSubj: 'collapsibleNavAppLink',
navigateToApp,
});
propsForEui.onClick(e);
}
};

const navLinksForRender: ChromeNavLink[] = useMemo(() => {
if (currentNavGroup) {
return fulfillRegistrationLinksToChromeNavLinks(
Expand Down Expand Up @@ -281,6 +258,33 @@ export function CollapsibleNavGroupEnabled({
return 270;
}, [isNavOpen]);

if (appId === 'home') {
return null;
}

const onGroupClick = (
e: React.MouseEvent<HTMLButtonElement, MouseEvent>,
group: NavGroupItemInMap
) => {
const fulfilledLinks = fulfillRegistrationLinksToChromeNavLinks(
navGroupsMap[group.id]?.navLinks,
navLinks
);
setCurrentNavGroup(group.id);

// the `navGroupsMap[group.id]?.navLinks` has already been sorted
const firstLink = fulfilledLinks[0];
if (firstLink) {
const propsForEui = createEuiListItem({
link: firstLink,
appId,
dataTestSubj: 'collapsibleNavAppLink',
navigateToApp,
});
propsForEui.onClick(e);
}
};

return (
<EuiFlyout
data-test-subj="collapsibleNav"
Expand Down

0 comments on commit 3670a30

Please sign in to comment.