-
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] add threat intelligence overview to expandable fl…
…yout (#155328)
- Loading branch information
1 parent
8a3f5eb
commit 4eeec18
Showing
15 changed files
with
1,250 additions
and
0 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
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
38 changes: 38 additions & 0 deletions
38
.../plugins/security_solution/public/flyout/right/components/insights_subsection.stories.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,38 @@ | ||
/* | ||
* 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 type { Story } from '@storybook/react'; | ||
import { InsightsSubSection } from './insights_subsection'; | ||
|
||
export default { | ||
component: InsightsSubSection, | ||
title: 'Flyout/InsightsSubSection', | ||
}; | ||
|
||
const title = 'Title'; | ||
const children = <div>{'hello'}</div>; | ||
|
||
export const Basic: Story<void> = () => { | ||
return <InsightsSubSection title={title}>{children}</InsightsSubSection>; | ||
}; | ||
|
||
export const Loading: Story<void> = () => { | ||
return ( | ||
<InsightsSubSection loading={true} title={title}> | ||
{null} | ||
</InsightsSubSection> | ||
); | ||
}; | ||
|
||
export const NoTitle: Story<void> = () => { | ||
return <InsightsSubSection title={''}>{children}</InsightsSubSection>; | ||
}; | ||
|
||
export const NoChildren: Story<void> = () => { | ||
return <InsightsSubSection title={title}>{null}</InsightsSubSection>; | ||
}; |
67 changes: 67 additions & 0 deletions
67
x-pack/plugins/security_solution/public/flyout/right/components/insights_subsection.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,67 @@ | ||
/* | ||
* 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 { InsightsSubSection } from './insights_subsection'; | ||
|
||
const title = 'Title'; | ||
const dataTestSubj = 'test'; | ||
const children = <div>{'hello'}</div>; | ||
|
||
describe('<InsightsSubSection />', () => { | ||
it('should render children component', () => { | ||
const { getByTestId } = render( | ||
<InsightsSubSection title={title} data-test-subj={dataTestSubj}> | ||
{children} | ||
</InsightsSubSection> | ||
); | ||
|
||
const titleDataTestSubj = `${dataTestSubj}Title`; | ||
const contentDataTestSubj = `${dataTestSubj}Content`; | ||
|
||
expect(getByTestId(titleDataTestSubj)).toHaveTextContent(title); | ||
expect(getByTestId(contentDataTestSubj)).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render loading component', () => { | ||
const { getByTestId } = render( | ||
<InsightsSubSection loading={true} title={title} data-test-subj={dataTestSubj}> | ||
{children} | ||
</InsightsSubSection> | ||
); | ||
|
||
const loadingDataTestSubj = `${dataTestSubj}Loading`; | ||
expect(getByTestId(loadingDataTestSubj)).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render null if error', () => { | ||
const { container } = render( | ||
<InsightsSubSection error={true} title={title}> | ||
{children} | ||
</InsightsSubSection> | ||
); | ||
|
||
expect(container).toBeEmptyDOMElement(); | ||
}); | ||
|
||
it('should render null if no title', () => { | ||
const { container } = render(<InsightsSubSection title={''}>{children}</InsightsSubSection>); | ||
|
||
expect(container).toBeEmptyDOMElement(); | ||
}); | ||
|
||
it('should render null if no children', () => { | ||
const { container } = render( | ||
<InsightsSubSection error={true} title={title}> | ||
{null} | ||
</InsightsSubSection> | ||
); | ||
|
||
expect(container).toBeEmptyDOMElement(); | ||
}); | ||
}); |
79 changes: 79 additions & 0 deletions
79
x-pack/plugins/security_solution/public/flyout/right/components/insights_subsection.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,79 @@ | ||
/* | ||
* 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 { EuiFlexGroup, EuiFlexItem, EuiLoadingSpinner, EuiSpacer, EuiTitle } from '@elastic/eui'; | ||
|
||
export interface InsightsSectionProps { | ||
/** | ||
* Renders a loading spinner if true | ||
*/ | ||
loading?: boolean; | ||
/** | ||
* Returns a null component if true | ||
*/ | ||
error?: boolean; | ||
/** | ||
* Title at the top of the component | ||
*/ | ||
title: string; | ||
/** | ||
* Content of the component | ||
*/ | ||
children: React.ReactNode; | ||
/** | ||
* Prefix data-test-subj to use for the elements | ||
*/ | ||
['data-test-subj']?: string; | ||
} | ||
|
||
/** | ||
* Presentational component to handle loading and error in the subsections of the Insights section. | ||
* Should be used for Entities, Threat Intelligence, Prevalence, Correlations and Results | ||
*/ | ||
export const InsightsSubSection: React.FC<InsightsSectionProps> = ({ | ||
loading = false, | ||
error = false, | ||
title, | ||
'data-test-subj': dataTestSubj, | ||
children, | ||
}) => { | ||
const loadingDataTestSubj = `${dataTestSubj}Loading`; | ||
// showing the loading in this component instead of SummaryPanel because we're hiding the entire section if no data | ||
|
||
if (loading) { | ||
return ( | ||
<EuiFlexGroup justifyContent="center"> | ||
<EuiFlexItem grow={false}> | ||
<EuiLoadingSpinner data-test-subj={loadingDataTestSubj} /> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
); | ||
} | ||
|
||
// hide everything | ||
if (error || !title || !children) { | ||
return null; | ||
} | ||
|
||
const titleDataTestSubj = `${dataTestSubj}Title`; | ||
const contentDataTestSubj = `${dataTestSubj}Content`; | ||
|
||
return ( | ||
<> | ||
<EuiTitle size="xxs" data-test-subj={titleDataTestSubj}> | ||
<h5>{title}</h5> | ||
</EuiTitle> | ||
<EuiSpacer size="s" /> | ||
<EuiFlexGroup data-test-subj={contentDataTestSubj} direction="column" gutterSize="s"> | ||
{children} | ||
</EuiFlexGroup> | ||
</> | ||
); | ||
}; | ||
|
||
InsightsSubSection.displayName = 'InsightsSubSection'; |
Oops, something went wrong.