-
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
Add Host risk information flyout to Host risk KPI panel #121075
Merged
machadoum
merged 6 commits into
elastic:main
from
machadoum:siem-explore-issue-119024-3
Dec 22, 2021
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
82cdf07
Create HoverVisibilityContainer component
machadoum 16d9406
Add Host risk information flyout to Host rik KPI panel
machadoum 9d368a7
Update snapshot test
machadoum 3ef7933
Fix cypress test
machadoum d18437d
Code review improvements
machadoum 4baeec6
Merge branch 'main' into siem-explore-issue-119024-3
kibanamachine 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
54 changes: 54 additions & 0 deletions
54
...gins/security_solution/public/common/components/hover_visibility_container/index.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,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 { mount } from 'enzyme'; | ||
import React from 'react'; | ||
|
||
import { TestProviders } from '../../mock'; | ||
|
||
import { HoverVisibilityContainer } from '.'; | ||
|
||
describe('HoverVisibilityContainer', () => { | ||
const targetClass1 = 'Component1'; | ||
const targetClass2 = 'Component2'; | ||
const Component1 = () => <div className={targetClass1} />; | ||
const Component2 = () => <div className={targetClass2} />; | ||
|
||
test('it renders a transparent inspect button by default', () => { | ||
const wrapper = mount( | ||
<TestProviders> | ||
<HoverVisibilityContainer targetClassNames={[targetClass1, targetClass2]}> | ||
<Component1 /> | ||
<Component2 /> | ||
</HoverVisibilityContainer> | ||
</TestProviders> | ||
); | ||
expect(wrapper.find(`HoverVisibilityContainer`)).toHaveStyleRule('opacity', '0', { | ||
modifier: `.${targetClass1}`, | ||
}); | ||
expect(wrapper.find(`HoverVisibilityContainer`)).toHaveStyleRule('opacity', '1', { | ||
modifier: `:hover .${targetClass2}`, | ||
}); | ||
}); | ||
|
||
test('it renders an opaque inspect button when it has mouse focus', () => { | ||
const wrapper = mount( | ||
<TestProviders> | ||
<HoverVisibilityContainer targetClassNames={[targetClass1, targetClass2]}> | ||
<Component1 /> | ||
<Component2 /> | ||
</HoverVisibilityContainer> | ||
</TestProviders> | ||
); | ||
expect(wrapper.find(`HoverVisibilityContainer`)).toHaveStyleRule('opacity', '1', { | ||
modifier: `:hover .${targetClass1}`, | ||
}); | ||
expect(wrapper.find(`HoverVisibilityContainer`)).toHaveStyleRule('opacity', '1', { | ||
modifier: `:hover .${targetClass2}`, | ||
}); | ||
}); | ||
}); |
54 changes: 54 additions & 0 deletions
54
...k/plugins/security_solution/public/common/components/hover_visibility_container/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,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 React from 'react'; | ||
import styled, { css } from 'styled-components'; | ||
import { getOr } from 'lodash/fp'; | ||
|
||
const StyledDiv = styled.div<{ targetClassNames: string[] }>` | ||
width: 100%; | ||
display: flex; | ||
flex-grow: 1; | ||
|
||
> * { | ||
max-width: 100%; | ||
} | ||
|
||
${({ targetClassNames }) => | ||
css` | ||
${targetClassNames.map((cn) => `.${cn}`).join(', ')} { | ||
pointer-events: none; | ||
opacity: 0; | ||
transition: opacity ${(props) => getOr(250, 'theme.eui.euiAnimSpeedNormal', props)} ease; | ||
} | ||
|
||
${targetClassNames.map((cn) => `&:hover .${cn}`).join(', ')} { | ||
pointer-events: auto; | ||
opacity: 1; | ||
} | ||
`} | ||
`; | ||
|
||
interface HoverVisibilityContainerProps { | ||
show?: boolean; | ||
children: React.ReactNode; | ||
targetClassNames: string[]; | ||
} | ||
|
||
export const HoverVisibilityContainer = React.memo<HoverVisibilityContainerProps>( | ||
({ show = true, targetClassNames, children }) => { | ||
if (!show) return <>{children}</>; | ||
|
||
return ( | ||
<StyledDiv data-test-subj="hoverVisibilityContainer" targetClassNames={targetClassNames}> | ||
{children} | ||
</StyledDiv> | ||
); | ||
} | ||
); | ||
|
||
HoverVisibilityContainer.displayName = 'HoverVisibilityContainer'; |
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
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
33 changes: 33 additions & 0 deletions
33
...ck/plugins/security_solution/public/hosts/components/host_risk_information/index.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,33 @@ | ||
/* | ||
* 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 { render, fireEvent } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { HostRiskInformation } from '.'; | ||
import { TestProviders } from '../../../common/mock'; | ||
|
||
describe('Host Risk Flyout', () => { | ||
it('renders', () => { | ||
const { queryByTestId } = render(<HostRiskInformation />); | ||
|
||
expect(queryByTestId('open-risk-information-flyout')).toBeInTheDocument(); | ||
}); | ||
|
||
it('opens and displays table with 5 rows', () => { | ||
const NUMBER_OF_ROWS = 1 + 5; // 1 header row + 5 severity rows | ||
const { getByTestId, queryByTestId, queryAllByRole } = render( | ||
<TestProviders> | ||
<HostRiskInformation /> | ||
</TestProviders> | ||
); | ||
|
||
fireEvent.click(getByTestId('open-risk-information-flyout')); | ||
|
||
expect(queryByTestId('risk-information-table')).toBeInTheDocument(); | ||
expect(queryAllByRole('row')).toHaveLength(NUMBER_OF_ROWS); | ||
}); | ||
}); |
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.
👏🏼