Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Stateful sidenav] Fix collapsed menu for panels with no landing pages #195904

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ describe('builds navigation tree', () => {

const accordionToggleButton = await findByTestId(/nav-item-group1\s/);
accordionToggleButton.click();
expect(navigateToUrl).not.toHaveBeenCalled();
expect(navigateToUrl).not.toHaveBeenCalled(); // Should not navigate to the href
unmount();
}

Expand All @@ -138,6 +138,85 @@ describe('builds navigation tree', () => {
}
});

test('should render panel opener groups as accordion when the sideNav is collapsed', async () => {
const panelOpenerNode: ChromeProjectNavigationNode = {
id: 'nestedGroup1',
title: 'Nested Group 1',
path: 'group1.nestedGroup1',
renderAs: 'panelOpener', // Should be converted to accordion when sideNav is collapsed
children: [
{
id: 'item1',
title: 'Item 1',
href: 'https://foo',
path: 'group1.item1',
},
],
};

const nodes: ChromeProjectNavigationNode = {
id: 'group1',
title: 'Group 1',
path: 'group1',
children: [panelOpenerNode],
};

{
// Side nav is collapsed
const { queryAllByTestId, unmount } = renderNavigation({
navTreeDef: of({
body: [nodes],
}),
services: { isSideNavCollapsed: true },
});

const accordionButtonLabel = queryAllByTestId('accordionToggleBtn').map((c) => c.textContent);
expect(accordionButtonLabel).toEqual(['Group 1', 'Nested Group 1']); // 2 accordion buttons

unmount();
}

{
// Side nav is not collapsed
const { queryAllByTestId, unmount } = renderNavigation({
navTreeDef: of({
body: [nodes],
}),
services: { isSideNavCollapsed: false }, // No conversion to accordion
});

const accordionButtonLabel = queryAllByTestId('accordionToggleBtn').map((c) => c.textContent);

expect(accordionButtonLabel).toEqual(['Group 1']); // Only 1 accordion button (top level)
unmount();
}

{
// Panel opener with a link
const { queryAllByTestId, unmount } = renderNavigation({
navTreeDef: of({
body: [
{
...nodes,
children: [
{
...panelOpenerNode,
href: '/foo/bar', // Panel opener with a link should not be converted to accordion
},
],
},
],
}),
services: { isSideNavCollapsed: true }, // SideNav is collapsed
});

const accordionButtonLabel = queryAllByTestId('accordionToggleBtn').map((c) => c.textContent);

expect(accordionButtonLabel).toEqual(['Group 1']); // Only 1 accordion button (top level)
unmount();
}
});

test('should track click event', async () => {
const navigateToUrl = jest.fn();
const reportEvent = jest.fn();
Expand Down
1 change: 0 additions & 1 deletion packages/shared-ux/chrome/navigation/__jest__/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export const getServicesMock = (): NavigationServices => {
return {
basePath,
recentlyAccessed$,
navIsOpen: true,
navigateToUrl,
activeNodes$: of(activeNodes),
isSideNavCollapsed: false,
Expand Down
6 changes: 3 additions & 3 deletions packages/shared-ux/chrome/navigation/mocks/storybook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ import { EventTracker } from '../src/analytics';
import { NavigationServices } from '../src/types';

type Arguments = NavigationServices;
export type Params = Pick<Arguments, 'navIsOpen' | 'recentlyAccessed$' | 'activeNodes$'>;
export type Params = Pick<Arguments, 'isSideNavCollapsed' | 'recentlyAccessed$' | 'activeNodes$'>;

export class StorybookMock extends AbstractStorybookMock<{}, NavigationServices> {
propArguments = {};

serviceArguments = {
navIsOpen: {
isSideNavCollapsed: {
control: 'boolean',
defaultValue: true,
defaultValue: false,
},
};

Expand Down
1 change: 0 additions & 1 deletion packages/shared-ux/chrome/navigation/src/services.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export const NavigationKibanaProvider: FC<PropsWithChildren<NavigationKibanaDepe
basePath,
recentlyAccessed$: chrome.recentlyAccessed.get$(),
navigateToUrl,
navIsOpen: true,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did some cleaning, this navIsOpen is not used anywhere.

activeNodes$,
isSideNavCollapsed,
eventTracker: new EventTracker({ reportEvent: analytics.reportEvent }),
Expand Down
1 change: 0 additions & 1 deletion packages/shared-ux/chrome/navigation/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export type NavigateToUrlFn = ApplicationStart['navigateToUrl'];
export interface NavigationServices {
basePath: BasePathService;
recentlyAccessed$: Observable<ChromeRecentlyAccessedHistoryItem[]>;
navIsOpen: boolean;
navigateToUrl: NavigateToUrlFn;
activeNodes$: Observable<ChromeProjectNavigationNode[][]>;
isSideNavCollapsed: boolean;
Expand Down
Loading