-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security Solution][Serverless] Left navigation (#156600)
## Summary closes: #156414 Adds the basic navigation to the Security Solution project. - Renders the current navigation hierarchy as in the classic Security. - Uses the basic styles defined by Core (dark sideNav has been dropped). - Reuses the Security SideNav package. - Adds the `setSideNavComponent` API to the Serverless plugin.  ### Run project `yarn serverless-security` ## Next steps - Add the new features needed in the navigation package to align with the new Security IA design. - Update the configuration of the links to display the hierarchy defined by the new Security IA. - Add Serverless specific styles to the sideNav in the ServerlesSecurity plugin. --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
- Loading branch information
1 parent
1abd32c
commit c4d233d
Showing
27 changed files
with
1,103 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* 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 { BehaviorSubject } from 'rxjs'; | ||
import type { NavigationLink } from './common/links/types'; | ||
|
||
const setupMock = () => ({ | ||
resolver: jest.fn(), | ||
}); | ||
|
||
const startMock = () => ({ | ||
getNavLinks$: jest.fn(() => new BehaviorSubject<NavigationLink[]>([])), | ||
setIsSidebarEnabled: jest.fn(), | ||
}); | ||
|
||
export const securitySolutionMock = { | ||
createSetup: setupMock, | ||
createStart: startMock, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* 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 { ServerlessPluginStart } from './types'; | ||
|
||
const startMock = (): ServerlessPluginStart => ({ | ||
setSideNavComponent: jest.fn(), | ||
}); | ||
|
||
export const serverlessMock = { | ||
createStart: startMock, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,5 +21,6 @@ | |
"@kbn/serverless-project-switcher", | ||
"@kbn/serverless-types", | ||
"@kbn/utils", | ||
"@kbn/core-chrome-browser", | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
module.exports = { | ||
preset: '@kbn/test', | ||
rootDir: '../../../', | ||
projects: ['<rootDir>/x-pack/plugins/serverless_security/public/*/jest.config.js'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
x-pack/plugins/serverless_security/public/components/jest.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
module.exports = { | ||
preset: '@kbn/test', | ||
rootDir: '../../../../..', | ||
roots: ['<rootDir>/x-pack/plugins/serverless_security/public/components'], | ||
testMatch: [ | ||
'<rootDir>/x-pack/plugins/serverless_security/public/components/**/*.test.{js,mjs,ts,tsx}', | ||
], | ||
coverageDirectory: | ||
'<rootDir>/target/kibana-coverage/jest/x-pack/plugins/serverless_security/public/components', | ||
coverageReporters: ['text', 'html'], | ||
collectCoverageFrom: [ | ||
'<rootDir>/x-pack/plugins/serverless_security/public/components/**/*.{ts,tsx}', | ||
'!<rootDir>/x-pack/plugins/serverless_security/public/components/*.test.{ts,tsx}', | ||
'!<rootDir>/x-pack/plugins/serverless_security/public/components/{__test__,__snapshots__,__examples__,*mock*,tests,test_helpers,integration_tests,types}/**/*', | ||
'!<rootDir>/x-pack/plugins/serverless_security/public/components/*mock*.{ts,tsx}', | ||
'!<rootDir>/x-pack/plugins/serverless_security/public/components/*.test.{ts,tsx}', | ||
'!<rootDir>/x-pack/plugins/serverless_security/public/components/*.d.ts', | ||
'!<rootDir>/x-pack/plugins/serverless_security/public/components/*.config.ts', | ||
'!<rootDir>/x-pack/plugins/serverless_security/public/components/index.{js,ts,tsx}', | ||
], | ||
}; |
26 changes: 26 additions & 0 deletions
26
x-pack/plugins/serverless_security/public/components/side_navigation/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* 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 React from 'react'; | ||
import { CoreStart } from '@kbn/core/public'; | ||
import type { | ||
SideNavComponent, | ||
SideNavCompProps, | ||
} from '@kbn/core-chrome-browser/src/project_navigation'; | ||
import { ServerlessSecurityPluginStartDependencies } from '../../types'; | ||
import { SecuritySideNavigation } from './side_navigation'; | ||
import { KibanaServicesProvider } from '../../services'; | ||
|
||
export const getSecuritySideNavComponent = ( | ||
core: CoreStart, | ||
pluginsStart: ServerlessSecurityPluginStartDependencies | ||
): SideNavComponent => { | ||
return (_props: SideNavCompProps) => ( | ||
<KibanaServicesProvider core={core} pluginsStart={pluginsStart}> | ||
<SecuritySideNavigation /> | ||
</KibanaServicesProvider> | ||
); | ||
}; |
101 changes: 101 additions & 0 deletions
101
...ck/plugins/serverless_security/public/components/side_navigation/side_navigation.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* 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 React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { SecuritySideNavigation } from './side_navigation'; | ||
import { useSideNavItems, useSideNavSelectedId } from '../../hooks/use_side_nav_items'; | ||
import { SecurityPageName } from '@kbn/security-solution-plugin/common'; | ||
import { KibanaServicesProvider } from '../../services.mock'; | ||
|
||
jest.mock('../../hooks/use_side_nav_items'); | ||
const mockUseSideNavItems = useSideNavItems as jest.Mock; | ||
const mockUseSideNavSelectedId = useSideNavSelectedId as jest.Mock; | ||
|
||
const mockSolutionSideNav = jest.fn((_props: unknown) => <div data-test-subj="solutionSideNav" />); | ||
jest.mock('@kbn/security-solution-side-nav', () => ({ | ||
SolutionSideNav: (props: unknown) => mockSolutionSideNav(props), | ||
})); | ||
|
||
const sideNavItems = [ | ||
{ | ||
id: SecurityPageName.dashboards, | ||
label: 'Dashboards', | ||
href: '/dashboards', | ||
onClick: jest.fn(), | ||
}, | ||
{ | ||
id: SecurityPageName.alerts, | ||
label: 'Alerts', | ||
href: '/alerts', | ||
onClick: jest.fn(), | ||
}, | ||
]; | ||
const sideNavFooterItems = [ | ||
{ | ||
id: SecurityPageName.administration, | ||
label: 'Manage', | ||
href: '/administration', | ||
onClick: jest.fn(), | ||
}, | ||
]; | ||
|
||
mockUseSideNavItems.mockReturnValue(sideNavItems); | ||
mockUseSideNavSelectedId.mockReturnValue(SecurityPageName.alerts); | ||
|
||
describe('SecuritySideNavigation', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should render loading when not items received', () => { | ||
mockUseSideNavItems.mockReturnValueOnce([]); | ||
const component = render(<SecuritySideNavigation />, { wrapper: KibanaServicesProvider }); | ||
expect(component.queryByTestId('sideNavLoader')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should not render loading when items received', () => { | ||
const component = render(<SecuritySideNavigation />, { wrapper: KibanaServicesProvider }); | ||
expect(component.queryByTestId('sideNavLoader')).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('should render the SideNav when items received', () => { | ||
const component = render(<SecuritySideNavigation />, { wrapper: KibanaServicesProvider }); | ||
expect(component.queryByTestId('solutionSideNav')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should pass item props to the SolutionSideNav component', () => { | ||
render(<SecuritySideNavigation />, { wrapper: KibanaServicesProvider }); | ||
|
||
expect(mockSolutionSideNav).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
items: sideNavItems, | ||
}) | ||
); | ||
}); | ||
|
||
it('should pass footerItems props to the SolutionSideNav component', () => { | ||
mockUseSideNavItems.mockReturnValueOnce(sideNavFooterItems); | ||
render(<SecuritySideNavigation />, { wrapper: KibanaServicesProvider }); | ||
|
||
expect(mockSolutionSideNav).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
footerItems: sideNavFooterItems, | ||
}) | ||
); | ||
}); | ||
|
||
it('should selectedId the SolutionSideNav component', () => { | ||
render(<SecuritySideNavigation />, { wrapper: KibanaServicesProvider }); | ||
|
||
expect(mockSolutionSideNav).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
selectedId: SecurityPageName.alerts, | ||
}) | ||
); | ||
}); | ||
}); |
44 changes: 44 additions & 0 deletions
44
x-pack/plugins/serverless_security/public/components/side_navigation/side_navigation.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* 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 React from 'react'; | ||
import { EuiLoadingSpinner, useEuiTheme } from '@elastic/eui'; | ||
import { SolutionNav } from '@kbn/shared-ux-page-solution-nav'; | ||
import { SolutionSideNav } from '@kbn/security-solution-side-nav'; | ||
import { | ||
usePartitionFooterNavItems, | ||
useSideNavItems, | ||
useSideNavSelectedId, | ||
} from '../../hooks/use_side_nav_items'; | ||
|
||
export const SecuritySideNavigation: React.FC = () => { | ||
const { euiTheme } = useEuiTheme(); | ||
const sideNavItems = useSideNavItems(); | ||
const selectedId = useSideNavSelectedId(sideNavItems); | ||
const [items, footerItems] = usePartitionFooterNavItems(sideNavItems); | ||
|
||
const isLoading = items.length === 0 && footerItems.length === 0; | ||
|
||
return isLoading ? ( | ||
<EuiLoadingSpinner size="m" data-test-subj="sideNavLoader" /> | ||
) : ( | ||
<SolutionNav | ||
canBeCollapsed={false} | ||
name={'Security'} | ||
icon={'logoSecurity'} | ||
children={ | ||
<SolutionSideNav | ||
items={items} | ||
footerItems={footerItems} | ||
selectedId={selectedId} | ||
panelTopOffset={`calc(${euiTheme.size.l} * 2)`} | ||
/> | ||
} | ||
closeFlyoutButtonPosition={'inside'} | ||
/> | ||
); | ||
}; |
16 changes: 16 additions & 0 deletions
16
x-pack/plugins/serverless_security/public/hooks/__mocks__/use_link_props.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* 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 type { GetLinkProps } from '../use_link_props'; | ||
|
||
export const getLinkProps = jest.fn(() => ({ | ||
href: '/test-href', | ||
onClick: jest.fn(), | ||
})); | ||
|
||
export const useLinkProps: GetLinkProps = getLinkProps; | ||
export const useGetLinkProps: () => GetLinkProps = jest.fn(() => getLinkProps); |
21 changes: 21 additions & 0 deletions
21
x-pack/plugins/serverless_security/public/hooks/__mocks__/use_side_nav_items.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* 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 type { SolutionSideNavItem } from '@kbn/security-solution-side-nav'; | ||
|
||
const { usePartitionFooterNavItems: originalUsePartitionFooterNavItems } = | ||
jest.requireActual('../use_side_nav_items'); | ||
|
||
export const useSideNavItems = jest.fn((): SolutionSideNavItem[] => []); | ||
|
||
export const usePartitionFooterNavItems = jest.fn( | ||
(sideNavItems: SolutionSideNavItem[]): [SolutionSideNavItem[], SolutionSideNavItem[]] => | ||
// Same implementation as original for convenience. Can be overridden in tests if needed | ||
originalUsePartitionFooterNavItems(sideNavItems) | ||
); | ||
|
||
export const useSideNavSelectedId = jest.fn((_sideNavItems: SolutionSideNavItem[]): string => ''); |
Oops, something went wrong.