-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Security Solution][Serverless] Left navigation #156600
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
5bad175
security nav components from poc
semd 21c9631
chrome setProjectNavigation
semd f79342e
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine 9f68f4f
adapted to setSideNavComponent
semd 1f9c1a7
Merge branch '156414_serverless_security_left_nav' of https://github.…
semd a80335a
cleaning
semd 7f4e01e
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine 0910ab7
serverless-security ownership
semd f6478eb
Merge branch '156414_serverless_security_left_nav' of https://github.…
semd 766cb1a
serverless-security ownership
semd 8b02cab
type fix
semd 43c43e1
serverless security tests implemented
semd fd6cf01
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine 47ee471
add appEx cc to serverless_security codeowners
semd 7af5d4c
Merge branch '156414_serverless_security_left_nav' of https://github.…
semd 4d1bbbe
Merge branch 'main' into 156414_serverless_security_left_nav
semd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is OK for now, but later we will need to split code ownership by the components, subfolders etc. to reduce PR noise across Security Solution teams.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, It makes sense, let's define what team owns what sub-directories, and then I'll update it