-
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] expandable flyout - add status to flyout header (#…
- Loading branch information
1 parent
f7faa82
commit 68b8ac3
Showing
12 changed files
with
241 additions
and
10 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
1 change: 1 addition & 0 deletions
1
...olution/public/common/components/event_details/overview/__snapshots__/index.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
59 changes: 59 additions & 0 deletions
59
x-pack/plugins/security_solution/public/flyout/right/components/status.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,59 @@ | ||
/* | ||
* 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 { ExpandableFlyoutContext } from '@kbn/expandable-flyout/src/context'; | ||
import { StorybookProviders } from '../../../common/mock/storybook_providers'; | ||
import { DocumentStatus } from './status'; | ||
import { RightPanelContext } from '../context'; | ||
import { mockBrowserFields, mockDataFormattedForFieldBrowser } from '../mocks/mock_context'; | ||
|
||
export default { | ||
component: DocumentStatus, | ||
title: 'Flyout/Status', | ||
}; | ||
|
||
const flyoutContextValue = { | ||
closeFlyout: () => {}, | ||
} as unknown as ExpandableFlyoutContext; | ||
|
||
export const Default: Story<void> = () => { | ||
const contextValue = { | ||
eventId: 'eventId', | ||
browserFields: mockBrowserFields, | ||
dataFormattedForFieldBrowser: mockDataFormattedForFieldBrowser, | ||
scopeId: 'alerts-page', | ||
} as unknown as RightPanelContext; | ||
|
||
return ( | ||
<StorybookProviders> | ||
<ExpandableFlyoutContext.Provider value={flyoutContextValue}> | ||
<RightPanelContext.Provider value={contextValue}> | ||
<DocumentStatus /> | ||
</RightPanelContext.Provider> | ||
</ExpandableFlyoutContext.Provider> | ||
</StorybookProviders> | ||
); | ||
}; | ||
|
||
export const Empty: Story<void> = () => { | ||
const contextValue = { | ||
eventId: 'eventId', | ||
browserFields: {}, | ||
dataFormattedForFieldBrowser: [], | ||
scopeId: 'scopeId', | ||
} as unknown as RightPanelContext; | ||
|
||
return ( | ||
<ExpandableFlyoutContext.Provider value={flyoutContextValue}> | ||
<RightPanelContext.Provider value={contextValue}> | ||
<DocumentStatus /> | ||
</RightPanelContext.Provider> | ||
</ExpandableFlyoutContext.Provider> | ||
); | ||
}; |
75 changes: 75 additions & 0 deletions
75
x-pack/plugins/security_solution/public/flyout/right/components/status.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,75 @@ | ||
/* | ||
* 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 { ExpandableFlyoutContext } from '@kbn/expandable-flyout/src/context'; | ||
import { RightPanelContext } from '../context'; | ||
import { DocumentStatus } from './status'; | ||
import { mockDataFormattedForFieldBrowser } from '../mocks/mock_context'; | ||
import { TestProviders } from '../../../common/mock'; | ||
import { useAlertsActions } from '../../../detections/components/alerts_table/timeline_actions/use_alerts_actions'; | ||
import { FLYOUT_HEADER_STATUS_BUTTON_TEST_ID } from './test_ids'; | ||
|
||
jest.mock('../../../detections/components/alerts_table/timeline_actions/use_alerts_actions'); | ||
|
||
const flyoutContextValue = { | ||
closeFlyout: jest.fn(), | ||
} as unknown as ExpandableFlyoutContext; | ||
|
||
const renderStatus = (contextValue: RightPanelContext) => | ||
render( | ||
<TestProviders> | ||
<ExpandableFlyoutContext.Provider value={flyoutContextValue}> | ||
<RightPanelContext.Provider value={contextValue}> | ||
<DocumentStatus /> | ||
</RightPanelContext.Provider> | ||
</ExpandableFlyoutContext.Provider> | ||
</TestProviders> | ||
); | ||
|
||
const actionItem = { | ||
key: 'key', | ||
name: 'name', | ||
'data-test-subj': 'data-test-subj', | ||
}; | ||
|
||
(useAlertsActions as jest.Mock).mockReturnValue({ | ||
actionItems: [actionItem], | ||
}); | ||
|
||
describe('<DocumentStatus />', () => { | ||
it('should render status information', () => { | ||
const contextValue = { | ||
eventId: 'eventId', | ||
browserFields: {}, | ||
dataFormattedForFieldBrowser: mockDataFormattedForFieldBrowser, | ||
scopeId: 'scopeId', | ||
} as unknown as RightPanelContext; | ||
|
||
const { getByTestId, getByText } = renderStatus(contextValue); | ||
|
||
expect(getByTestId(FLYOUT_HEADER_STATUS_BUTTON_TEST_ID)).toBeInTheDocument(); | ||
expect(getByText('open')).toBeInTheDocument(); | ||
|
||
getByTestId(FLYOUT_HEADER_STATUS_BUTTON_TEST_ID).click(); | ||
expect(getByTestId('data-test-subj')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render empty component', () => { | ||
const contextValue = { | ||
eventId: 'eventId', | ||
browserFields: {}, | ||
dataFormattedForFieldBrowser: [], | ||
scopeId: 'scopeId', | ||
} as unknown as RightPanelContext; | ||
|
||
const { container } = renderStatus(contextValue); | ||
|
||
expect(container).toBeEmptyDOMElement(); | ||
}); | ||
}); |
65 changes: 65 additions & 0 deletions
65
x-pack/plugins/security_solution/public/flyout/right/components/status.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,65 @@ | ||
/* | ||
* 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 { FC } from 'react'; | ||
import React, { useMemo } from 'react'; | ||
import { find } from 'lodash/fp'; | ||
import { useExpandableFlyoutContext } from '@kbn/expandable-flyout'; | ||
import type { | ||
EnrichedFieldInfo, | ||
EnrichedFieldInfoWithValues, | ||
} from '../../../common/components/event_details/types'; | ||
import { SIGNAL_STATUS_FIELD_NAME } from '../../../timelines/components/timeline/body/renderers/constants'; | ||
import { StatusPopoverButton } from '../../../common/components/event_details/overview/status_popover_button'; | ||
import { useRightPanelContext } from '../context'; | ||
import { getEnrichedFieldInfo } from '../../../common/components/event_details/helpers'; | ||
|
||
/** | ||
* Checks if the field info has data to convert EnrichedFieldInfo into EnrichedFieldInfoWithValues | ||
*/ | ||
function hasData(fieldInfo?: EnrichedFieldInfo): fieldInfo is EnrichedFieldInfoWithValues { | ||
return !!fieldInfo && Array.isArray(fieldInfo.values); | ||
} | ||
|
||
/** | ||
* Document details status displayed in flyout right section header | ||
*/ | ||
export const DocumentStatus: FC = () => { | ||
const { closeFlyout } = useExpandableFlyoutContext(); | ||
const { eventId, browserFields, dataFormattedForFieldBrowser, scopeId } = useRightPanelContext(); | ||
|
||
const statusData = useMemo(() => { | ||
const item = find( | ||
{ field: SIGNAL_STATUS_FIELD_NAME, category: 'kibana' }, | ||
dataFormattedForFieldBrowser | ||
); | ||
return ( | ||
item && | ||
getEnrichedFieldInfo({ | ||
eventId, | ||
contextId: scopeId, | ||
scopeId, | ||
browserFields: browserFields || {}, | ||
item, | ||
}) | ||
); | ||
}, [browserFields, dataFormattedForFieldBrowser, eventId, scopeId]); | ||
|
||
if (!statusData || !hasData(statusData)) return null; | ||
|
||
return ( | ||
<StatusPopoverButton | ||
eventId={eventId} | ||
contextId={scopeId} | ||
enrichedFieldInfo={statusData} | ||
scopeId={scopeId} | ||
handleOnEventClosed={closeFlyout} | ||
/> | ||
); | ||
}; | ||
|
||
DocumentStatus.displayName = 'DocumentStatus'; |
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