Skip to content

Commit

Permalink
[Security Solutions] Refactor breadcrumbs to support new menu structu…
Browse files Browse the repository at this point in the history
…re (#131624)

* Refactor breadcrumbs to support new structure

* Fix code style

* Fix more code style

* Fix unit test

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
machadoum and kibanamachine committed May 23, 2022
1 parent 9649307 commit a3646eb
Show file tree
Hide file tree
Showing 16 changed files with 976 additions and 735 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const useFormatUrl = (page: SecurityPageName) => {
return { formatUrl, search };
};

type GetSecuritySolutionUrl = (param: {
export type GetSecuritySolutionUrl = (param: {
deepLinkId: SecurityPageName;
path?: string;
absolute?: boolean;
Expand All @@ -63,6 +63,7 @@ export const useGetSecuritySolutionUrl = () => {
({ deepLinkId, path = '', absolute = false, skipSearch = false }) => {
const search = needsUrlState(deepLinkId) ? getUrlStateQueryString() : '';
const formattedPath = formatPath(path, search, skipSearch);

return getAppUrl({ deepLinkId, path: formattedPath, absolute });
},
[getAppUrl, getUrlStateQueryString]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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 { ChromeBreadcrumb } from '@kbn/core/public';
import { SecurityPageName } from '../../../../app/types';
import { APP_NAME } from '../../../../../common/constants';
import { getAppLandingUrl } from '../../link_to/redirect_to_landing';

import { GetSecuritySolutionUrl } from '../../link_to';
import { getAncestorLinksInfo } from '../../../links';
import { GenericNavRecord } from '../types';

export const getLeadingBreadcrumbsForSecurityPage = (
pageName: SecurityPageName,
getSecuritySolutionUrl: GetSecuritySolutionUrl,
navTabs: GenericNavRecord,
isGroupedNavigationEnabled: boolean
): [ChromeBreadcrumb, ...ChromeBreadcrumb[]] => {
const landingPath = getSecuritySolutionUrl({ deepLinkId: SecurityPageName.landing });

const siemRootBreadcrumb: ChromeBreadcrumb = {
text: APP_NAME,
href: getAppLandingUrl(landingPath),
};

const breadcrumbs: ChromeBreadcrumb[] = getAncestorLinksInfo(pageName).map(({ title, id }) => {
const newTitle = title;
// Get title from navTabs because pages title on the new structure might be different.
const oldTitle = navTabs[id] ? navTabs[id].name : title;

return {
text: isGroupedNavigationEnabled ? newTitle : oldTitle,
href: getSecuritySolutionUrl({ deepLinkId: id }),
};
});

return [siemRootBreadcrumb, ...breadcrumbs];
};
Loading

0 comments on commit a3646eb

Please sign in to comment.