-
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][Case] Add button to go to case view after adding …
…an alert to a case (#89214)
- Loading branch information
Showing
7 changed files
with
195 additions
and
34 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
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
45 changes: 45 additions & 0 deletions
45
...ugins/security_solution/public/cases/components/timeline_actions/toaster_content.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,45 @@ | ||
/* | ||
* 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 React from 'react'; | ||
import { mount } from 'enzyme'; | ||
|
||
import { ToasterContent } from './toaster_content'; | ||
|
||
describe('ToasterContent', () => { | ||
const onViewCaseClick = jest.fn(); | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('renders with syncAlerts=true', () => { | ||
const wrapper = mount( | ||
<ToasterContent caseId="case-id" syncAlerts={true} onViewCaseClick={onViewCaseClick} /> | ||
); | ||
|
||
expect(wrapper.find('[data-test-subj="toaster-content-case-view-link"]').exists()).toBeTruthy(); | ||
expect(wrapper.find('[data-test-subj="toaster-content-sync-text"]').exists()).toBeTruthy(); | ||
}); | ||
|
||
it('renders with syncAlerts=false', () => { | ||
const wrapper = mount( | ||
<ToasterContent caseId="case-id" syncAlerts={false} onViewCaseClick={onViewCaseClick} /> | ||
); | ||
|
||
expect(wrapper.find('[data-test-subj="toaster-content-case-view-link"]').exists()).toBeTruthy(); | ||
expect(wrapper.find('[data-test-subj="toaster-content-sync-text"]').exists()).toBeFalsy(); | ||
}); | ||
|
||
it('calls onViewCaseClick', () => { | ||
const wrapper = mount( | ||
<ToasterContent caseId="case-id" syncAlerts={false} onViewCaseClick={onViewCaseClick} /> | ||
); | ||
|
||
wrapper.find('[data-test-subj="toaster-content-case-view-link"]').first().simulate('click'); | ||
expect(onViewCaseClick).toHaveBeenCalled(); | ||
}); | ||
}); |
46 changes: 46 additions & 0 deletions
46
...ck/plugins/security_solution/public/cases/components/timeline_actions/toaster_content.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,46 @@ | ||
/* | ||
* 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 React, { memo, useCallback } from 'react'; | ||
import { EuiButtonEmpty, EuiText } from '@elastic/eui'; | ||
import styled from 'styled-components'; | ||
|
||
import * as i18n from './translations'; | ||
|
||
const EuiTextStyled = styled(EuiText)` | ||
${({ theme }) => ` | ||
margin-bottom: ${theme.eui?.paddingSizes?.s ?? 8}px; | ||
`} | ||
`; | ||
|
||
interface Props { | ||
caseId: string; | ||
syncAlerts: boolean; | ||
onViewCaseClick: (id: string) => void; | ||
} | ||
|
||
const ToasterContentComponent: React.FC<Props> = ({ caseId, syncAlerts, onViewCaseClick }) => { | ||
const onClick = useCallback(() => onViewCaseClick(caseId), [caseId, onViewCaseClick]); | ||
return ( | ||
<> | ||
{syncAlerts && ( | ||
<EuiTextStyled size="s" data-test-subj="toaster-content-sync-text"> | ||
{i18n.CASE_CREATED_SUCCESS_TOAST_TEXT} | ||
</EuiTextStyled> | ||
)} | ||
<EuiButtonEmpty | ||
size="xs" | ||
flush="left" | ||
onClick={onClick} | ||
data-test-subj="toaster-content-case-view-link" | ||
> | ||
{i18n.VIEW_CASE} | ||
</EuiButtonEmpty> | ||
</> | ||
); | ||
}; | ||
|
||
export const ToasterContent = memo(ToasterContentComponent); |
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