forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SIEM][CASE] Persist callout when dismissed (elastic#68372)
- Loading branch information
Showing
20 changed files
with
618 additions
and
154 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
89 changes: 89 additions & 0 deletions
89
x-pack/plugins/security_solution/public/cases/components/callout/callout.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,89 @@ | ||
/* | ||
* 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 { CallOut, CallOutProps } from './callout'; | ||
|
||
describe('Callout', () => { | ||
const defaultProps: CallOutProps = { | ||
id: 'md5-hex', | ||
type: 'primary', | ||
title: 'a tittle', | ||
messages: [ | ||
{ | ||
id: 'generic-error', | ||
title: 'message-one', | ||
description: <p>{'error'}</p>, | ||
}, | ||
], | ||
showCallOut: true, | ||
handleDismissCallout: jest.fn(), | ||
}; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('It renders the callout', () => { | ||
const wrapper = mount(<CallOut {...defaultProps} />); | ||
expect(wrapper.find(`[data-test-subj="case-callout-md5-hex"]`).exists()).toBeTruthy(); | ||
expect(wrapper.find(`[data-test-subj="callout-messages-md5-hex"]`).exists()).toBeTruthy(); | ||
expect(wrapper.find(`[data-test-subj="callout-dismiss-md5-hex"]`).exists()).toBeTruthy(); | ||
}); | ||
|
||
it('hides the callout', () => { | ||
const wrapper = mount(<CallOut {...defaultProps} showCallOut={false} />); | ||
expect(wrapper.find(`[data-test-subj="case-callout-md5-hex"]`).exists()).toBeFalsy(); | ||
}); | ||
|
||
it('does not shows any messages when the list is empty', () => { | ||
const wrapper = mount(<CallOut {...defaultProps} messages={[]} />); | ||
expect(wrapper.find(`[data-test-subj="callout-messages-md5-hex"]`).exists()).toBeFalsy(); | ||
}); | ||
|
||
it('transform the button color correctly - primary', () => { | ||
const wrapper = mount(<CallOut {...defaultProps} />); | ||
const className = | ||
wrapper.find(`button[data-test-subj="callout-dismiss-md5-hex"]`).first().prop('className') ?? | ||
''; | ||
expect(className.includes('euiButton--primary')).toBeTruthy(); | ||
}); | ||
|
||
it('transform the button color correctly - success', () => { | ||
const wrapper = mount(<CallOut {...defaultProps} type={'success'} />); | ||
const className = | ||
wrapper.find(`button[data-test-subj="callout-dismiss-md5-hex"]`).first().prop('className') ?? | ||
''; | ||
expect(className.includes('euiButton--secondary')).toBeTruthy(); | ||
}); | ||
|
||
it('transform the button color correctly - warning', () => { | ||
const wrapper = mount(<CallOut {...defaultProps} type={'warning'} />); | ||
const className = | ||
wrapper.find(`button[data-test-subj="callout-dismiss-md5-hex"]`).first().prop('className') ?? | ||
''; | ||
expect(className.includes('euiButton--warning')).toBeTruthy(); | ||
}); | ||
|
||
it('transform the button color correctly - danger', () => { | ||
const wrapper = mount(<CallOut {...defaultProps} type={'danger'} />); | ||
const className = | ||
wrapper.find(`button[data-test-subj="callout-dismiss-md5-hex"]`).first().prop('className') ?? | ||
''; | ||
expect(className.includes('euiButton--danger')).toBeTruthy(); | ||
}); | ||
|
||
it('dismiss the callout correctly', () => { | ||
const wrapper = mount(<CallOut {...defaultProps} messages={[]} />); | ||
expect(wrapper.find(`[data-test-subj="callout-dismiss-md5-hex"]`).exists()).toBeTruthy(); | ||
wrapper.find(`button[data-test-subj="callout-dismiss-md5-hex"]`).simulate('click'); | ||
wrapper.update(); | ||
|
||
expect(defaultProps.handleDismissCallout).toHaveBeenCalledWith('md5-hex', 'primary'); | ||
}); | ||
}); |
53 changes: 53 additions & 0 deletions
53
x-pack/plugins/security_solution/public/cases/components/callout/callout.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,53 @@ | ||
/* | ||
* 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 { EuiCallOut, EuiButton, EuiDescriptionList } from '@elastic/eui'; | ||
import { isEmpty } from 'lodash/fp'; | ||
import React, { memo, useCallback } from 'react'; | ||
|
||
import { ErrorMessage } from './types'; | ||
import * as i18n from './translations'; | ||
|
||
export interface CallOutProps { | ||
id: string; | ||
type: NonNullable<ErrorMessage['errorType']>; | ||
title: string; | ||
messages: ErrorMessage[]; | ||
showCallOut: boolean; | ||
handleDismissCallout: (id: string, type: NonNullable<ErrorMessage['errorType']>) => void; | ||
} | ||
|
||
const CallOutComponent = ({ | ||
id, | ||
type, | ||
title, | ||
messages, | ||
showCallOut, | ||
handleDismissCallout, | ||
}: CallOutProps) => { | ||
const handleCallOut = useCallback(() => handleDismissCallout(id, type), [ | ||
handleDismissCallout, | ||
id, | ||
type, | ||
]); | ||
|
||
return showCallOut ? ( | ||
<EuiCallOut title={title} color={type} iconType="gear" data-test-subj={`case-callout-${id}`}> | ||
{!isEmpty(messages) && ( | ||
<EuiDescriptionList data-test-subj={`callout-messages-${id}`} listItems={messages} /> | ||
)} | ||
<EuiButton | ||
data-test-subj={`callout-dismiss-${id}`} | ||
color={type === 'success' ? 'secondary' : type} | ||
onClick={handleCallOut} | ||
> | ||
{i18n.DISMISS_CALLOUT} | ||
</EuiButton> | ||
</EuiCallOut> | ||
) : null; | ||
}; | ||
|
||
export const CallOut = memo(CallOutComponent); |
28 changes: 28 additions & 0 deletions
28
x-pack/plugins/security_solution/public/cases/components/callout/helpers.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,28 @@ | ||
/* | ||
* 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 md5 from 'md5'; | ||
import { createCalloutId } from './helpers'; | ||
|
||
describe('createCalloutId', () => { | ||
it('creates id correctly with one id', () => { | ||
const digest = md5('one'); | ||
const id = createCalloutId(['one']); | ||
expect(id).toBe(digest); | ||
}); | ||
|
||
it('creates id correctly with multiples ids', () => { | ||
const digest = md5('one|two|three'); | ||
const id = createCalloutId(['one', 'two', 'three']); | ||
expect(id).toBe(digest); | ||
}); | ||
|
||
it('creates id correctly with multiples ids and delimiter', () => { | ||
const digest = md5('one,two,three'); | ||
const id = createCalloutId(['one', 'two', 'three'], ','); | ||
expect(id).toBe(digest); | ||
}); | ||
}); |
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
Oops, something went wrong.