Skip to content

Commit

Permalink
Update navigation landing pages to use appLinks config (elastic#132027)
Browse files Browse the repository at this point in the history
* Update navigation landing pages to use appLinks config

* Please code review

* align app links changes

* Update links descriptions

* Rollback title changes

* Fix wrong links descriptions

* Fix unit tests

* Fix description

Co-authored-by: semd <sergi.massaneda@elastic.co>
  • Loading branch information
2 people authored and Esteban Beltran committed May 17, 2022
1 parent 59ffe0d commit b5dc585
Show file tree
Hide file tree
Showing 32 changed files with 580 additions and 527 deletions.
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

0 comments on commit b5dc585

Please sign in to comment.