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

Update navigation landing pages to use appLinks config #132027

Merged
merged 8 commits into from
May 17, 2022
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
@@ -0,0 +1,54 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { renderHook } from '@testing-library/react-hooks';
import { SecurityPageName } from '../../../app/types';
import { NavLinkItem } from '../../links/types';
import { TestProviders } from '../../mock';
import { useAppNavLinks, useAppRootNavLink } from './nav_links';

const mockNavLinks = [
{
description: 'description',
id: SecurityPageName.administration,
links: [
{
description: 'description 2',
id: SecurityPageName.endpoints,
links: [],
path: '/path_2',
title: 'title 2',
},
],
path: '/path',
title: 'title',
},
];

jest.mock('../../links', () => ({
getNavLinkItems: () => mockNavLinks,
}));

const renderUseAppNavLinks = () =>
renderHook<{}, NavLinkItem[]>(() => useAppNavLinks(), { wrapper: TestProviders });

const renderUseAppRootNavLink = (id: SecurityPageName) =>
renderHook<{ id: SecurityPageName }, NavLinkItem | undefined>(() => useAppRootNavLink(id), {
wrapper: TestProviders,
});

describe('useAppNavLinks', () => {
it('should return all nav links', () => {
const { result } = renderUseAppNavLinks();
expect(result.current).toEqual(mockNavLinks);
});

it('should return a root nav links', () => {
const { result } = renderUseAppRootNavLink(SecurityPageName.administration);
expect(result.current).toEqual(mockNavLinks[0]);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { useKibana } from '../../lib/kibana';
import { useEnableExperimental } from '../../hooks/use_experimental_features';
import { useLicense } from '../../hooks/use_license';
import { getNavLinkItems } from '../../links';
import type { SecurityPageName } from '../../../app/types';
import type { NavLinkItem } from '../../links/types';

export const useAppNavLinks = (): NavLinkItem[] => {
const license = useLicense();
const enableExperimental = useEnableExperimental();
const capabilities = useKibana().services.application.capabilities;

return getNavLinkItems({ enableExperimental, license, capabilities });
};

export const useAppRootNavLink = (linkId: SecurityPageName): NavLinkItem | undefined => {
return useAppNavLinks().find(({ id }) => id === linkId);
};
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,10 @@ export type GetUrlForApp = (
) => string;

export type NavigateToUrl = (url: string) => void;

export interface NavigationCategory {
label: string;
linkIds: readonly SecurityPageName[];
}

export type NavigationCategories = Readonly<NavigationCategory[]>;

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

Loading