Skip to content

Commit

Permalink
basic working breadcrumbs
Browse files Browse the repository at this point in the history
  • Loading branch information
parkiino committed Jul 9, 2020
1 parent d57c13d commit 661c4ad
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { getBreadcrumbs as getIPDetailsBreadcrumbs } from '../../../../network/p
import { getBreadcrumbs as getCaseDetailsBreadcrumbs } from '../../../../cases/pages/utils';
import { getBreadcrumbs as getDetectionRulesBreadcrumbs } from '../../../../detections/pages/detection_engine/rules/utils';
import { getBreadcrumbs as getTimelinesBreadcrumbs } from '../../../../timelines/pages';
import { getBreadcrumbs as getAdminBreadcrumbs } from '../../../../management/pages';
import { SecurityPageName } from '../../../../app/types';
import {
RouteSpyState,
Expand Down Expand Up @@ -61,6 +62,10 @@ const isCaseRoutes = (spyState: RouteSpyState): spyState is RouteSpyState =>
const isAlertsRoutes = (spyState: RouteSpyState) =>
spyState != null && spyState.pageName === SecurityPageName.detections;

const isAdminRoutes = (spyState: RouteSpyState) =>
spyState != null && spyState.pageName === SecurityPageName.management;

// eslint-disable-next-line complexity
export const getBreadcrumbsForRoute = (
object: RouteSpyState & TabNavigationProps,
getUrlForApp: GetUrlForApp
Expand Down Expand Up @@ -159,6 +164,27 @@ export const getBreadcrumbsForRoute = (
),
];
}

if (isAdminRoutes(spyState) && object.navTabs) {
const tempNav: SearchNavTab = { urlKey: 'administration', isDetailPage: false };
let urlStateKeys = [getOr(tempNav, spyState.pageName, object.navTabs)];
if (spyState.tabName != null) {
urlStateKeys = [...urlStateKeys, getOr(tempNav, spyState.tabName, object.navTabs)];
}

return [
...siemRootBreadcrumb,
...getAdminBreadcrumbs(
spyState,
urlStateKeys.reduce(
(acc: string[], item: SearchNavTab) => [...acc, getSearch(item, object)],
[]
),
getUrlForApp
),
];
}

if (
spyState != null &&
object.navTabs &&
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { i18n } from '@kbn/i18n';

export const HOSTS_TAB = i18n.translate('xpack.securitySolution.hostsTab', {
defaultMessage: 'Hosts',
});

export const POLICIES_TAB = i18n.translate('xpack.securitySolution.policiesTab', {
defaultMessage: 'Policies',
});
16 changes: 10 additions & 6 deletions x-pack/plugins/security_solution/public/management/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { isEmpty } from 'lodash/fp';
import React, { memo } from 'react';
import { useHistory, Route, Switch } from 'react-router-dom';

import { ChromeBreadcrumb } from 'kibana/public';
import { PolicyContainer } from './policy';
import {
MANAGEMENT_ROUTING_HOSTS_PATH,
Expand All @@ -17,13 +18,16 @@ import {
import { NotFoundPage } from '../../app/404';
import { HostsContainer } from './endpoint_hosts';
import { getHostListPath } from '../common/routing';
import {ChromeBreadcrumb} from 'kibana/public';
import {APP_ID} from 'x-pack/plugins/security_solution/common/constants';
import {GetUrlForApp} from '../../common/components/navigation/types';
import {AdministrationRouteSpyState} from '../../common/utils/route/types';
import { APP_ID, SecurityPageName } from '../../../common/constants';
import { GetUrlForApp } from '../../common/components/navigation/types';
import { AdministrationRouteSpyState } from '../../common/utils/route/types';
import { ADMINISTRATION } from '../../app/home/translations';
import { AdministrationSubTab } from '../types';
import { HOSTS_TAB, POLICIES_TAB } from '../common/translations';

const TabNameMappedToI18nKey: Record<string, string> = {

[AdministrationSubTab.hosts]: HOSTS_TAB,
[AdministrationSubTab.policies]: POLICIES_TAB,
};

export const getBreadcrumbs = (
Expand All @@ -33,7 +37,7 @@ export const getBreadcrumbs = (
): ChromeBreadcrumb[] => {
let breadcrumb = [
{
text: PAGE_TITLE,
text: ADMINISTRATION,
href: getUrlForApp(`${APP_ID}:${SecurityPageName.management}`, {
path: !isEmpty(search[0]) ? search[0] : '',
}),
Expand Down

0 comments on commit 661c4ad

Please sign in to comment.