-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[Security Solution] add highlighted fields to overview tab #153074
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 hidden or 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
75 changes: 75 additions & 0 deletions
75
...k/plugins/security_solution/public/flyout/right/components/highlighted_fields.stories.tsx
This file contains hidden or 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 type { Story } from '@storybook/react'; | ||
| import { ExpandableFlyoutContext } from '@kbn/expandable-flyout/src/context'; | ||
| import { HighlightedFields } from './highlighted_fields'; | ||
| import { RightPanelContext } from '../context'; | ||
|
|
||
| export default { | ||
| component: HighlightedFields, | ||
| title: 'Flyout/HighlightedFields', | ||
| }; | ||
|
|
||
| // TODO ideally we would want to have some data here, but we need to spent some time getting all the foundation items for storybook | ||
| // (ReduxStoreProvider, CellActionsProvider...) similarly to how it was done for the TestProvidersComponent | ||
| // see ticket https://github.com/elastic/security-team/issues/6223 | ||
| export const Expanded: Story<void> = () => { | ||
| const flyoutContextValue = { | ||
| openRightPanel: () => window.alert('openRightPanel called'), | ||
| } as unknown as ExpandableFlyoutContext; | ||
| const panelContextValue = { | ||
| eventId: 'eventId', | ||
| indexName: 'indexName', | ||
| dataFormattedForFieldBrowser: [], | ||
| browserFields: {}, | ||
| } as unknown as RightPanelContext; | ||
|
|
||
| return ( | ||
| <ExpandableFlyoutContext.Provider value={flyoutContextValue}> | ||
| <RightPanelContext.Provider value={panelContextValue}> | ||
| <HighlightedFields expanded={true} /> | ||
| </RightPanelContext.Provider> | ||
| </ExpandableFlyoutContext.Provider> | ||
| ); | ||
| }; | ||
|
|
||
| export const Collapsed: Story<void> = () => { | ||
| const flyoutContextValue = { | ||
| openRightPanel: () => window.alert('openRightPanel called'), | ||
| } as unknown as ExpandableFlyoutContext; | ||
| const panelContextValue = { | ||
| eventId: 'eventId', | ||
| indexName: 'indexName', | ||
| dataFormattedForFieldBrowser: [], | ||
| browserFields: {}, | ||
| } as unknown as RightPanelContext; | ||
|
|
||
| return ( | ||
| <ExpandableFlyoutContext.Provider value={flyoutContextValue}> | ||
| <RightPanelContext.Provider value={panelContextValue}> | ||
| <HighlightedFields /> | ||
| </RightPanelContext.Provider> | ||
| </ExpandableFlyoutContext.Provider> | ||
| ); | ||
| }; | ||
|
|
||
| export const Emtpy: Story<void> = () => { | ||
| const flyoutContextValue = {} as unknown as ExpandableFlyoutContext; | ||
| const panelContextValue = { | ||
| eventId: null, | ||
| } as unknown as RightPanelContext; | ||
|
|
||
| return ( | ||
| <ExpandableFlyoutContext.Provider value={flyoutContextValue}> | ||
| <RightPanelContext.Provider value={panelContextValue}> | ||
| <HighlightedFields /> | ||
| </RightPanelContext.Provider> | ||
| </ExpandableFlyoutContext.Provider> | ||
| ); | ||
| }; |
184 changes: 184 additions & 0 deletions
184
x-pack/plugins/security_solution/public/flyout/right/components/highlighted_fields.test.tsx
This file contains hidden or 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,184 @@ | ||
| /* | ||
| * 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 { RightPanelContext } from '../context'; | ||
| import { | ||
| HIGHLIGHTED_FIELDS_DETAILS_TEST_ID, | ||
| HIGHLIGHTED_FIELDS_GO_TO_TABLE_LINK, | ||
| HIGHLIGHTED_FIELDS_HEADER_EXPAND_ICON_TEST_ID, | ||
| HIGHLIGHTED_FIELDS_HEADER_TITLE_TEST_ID, | ||
| } from './test_ids'; | ||
| import { ExpandableFlyoutContext } from '@kbn/expandable-flyout/src/context'; | ||
| import { HighlightedFields } from './highlighted_fields'; | ||
| import { RightPanelKey, RightPanelTableTabPath } from '..'; | ||
| import { getMockTheme } from '../../../common/lib/kibana/kibana_react.mock'; | ||
| import { ThemeProvider } from 'styled-components'; | ||
|
|
||
| const mockTheme = getMockTheme({ | ||
| eui: { | ||
| euiSizeL: '10px', | ||
| }, | ||
| }); | ||
|
|
||
| describe('<HighlightedFields />', () => { | ||
| it('should render the component collapsed', () => { | ||
| const flyoutContextValue = { | ||
| openRightPanel: jest.fn(), | ||
| } as unknown as ExpandableFlyoutContext; | ||
| const panelContextValue = { | ||
| eventId: 'eventId', | ||
| indexName: 'indexName', | ||
| dataFormattedForFieldBrowser: [], | ||
| browserFields: {}, | ||
| } as unknown as RightPanelContext; | ||
|
|
||
| const { getByTestId } = render( | ||
| <ThemeProvider theme={mockTheme}> | ||
| <ExpandableFlyoutContext.Provider value={flyoutContextValue}> | ||
| <RightPanelContext.Provider value={panelContextValue}> | ||
| <HighlightedFields /> | ||
| </RightPanelContext.Provider> | ||
| </ExpandableFlyoutContext.Provider> | ||
| </ThemeProvider> | ||
| ); | ||
|
|
||
| expect(getByTestId(HIGHLIGHTED_FIELDS_HEADER_TITLE_TEST_ID)).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should render the component expanded', () => { | ||
| const flyoutContextValue = { | ||
| openRightPanel: jest.fn(), | ||
| } as unknown as ExpandableFlyoutContext; | ||
| const panelContextValue = { | ||
| eventId: 'eventId', | ||
| indexName: 'indexName', | ||
| dataFormattedForFieldBrowser: [], | ||
| browserFields: {}, | ||
| } as unknown as RightPanelContext; | ||
|
|
||
| const { getByTestId } = render( | ||
| <ThemeProvider theme={mockTheme}> | ||
| <ExpandableFlyoutContext.Provider value={flyoutContextValue}> | ||
| <RightPanelContext.Provider value={panelContextValue}> | ||
| <HighlightedFields expanded={true} /> | ||
| </RightPanelContext.Provider> | ||
| </ExpandableFlyoutContext.Provider> | ||
| </ThemeProvider> | ||
| ); | ||
|
|
||
| expect(getByTestId(HIGHLIGHTED_FIELDS_HEADER_TITLE_TEST_ID)).toBeInTheDocument(); | ||
| expect(getByTestId(HIGHLIGHTED_FIELDS_DETAILS_TEST_ID)).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should expand details when clicking on header', () => { | ||
| const flyoutContextValue = { | ||
| openRightPanel: jest.fn(), | ||
| } as unknown as ExpandableFlyoutContext; | ||
| const panelContextValue = { | ||
| eventId: 'eventId', | ||
| indexName: 'indexName', | ||
| dataFormattedForFieldBrowser: [], | ||
| browserFields: {}, | ||
| } as unknown as RightPanelContext; | ||
|
|
||
| const { getByTestId } = render( | ||
| <ThemeProvider theme={mockTheme}> | ||
| <ExpandableFlyoutContext.Provider value={flyoutContextValue}> | ||
| <RightPanelContext.Provider value={panelContextValue}> | ||
| <HighlightedFields /> | ||
| </RightPanelContext.Provider> | ||
| </ExpandableFlyoutContext.Provider> | ||
| </ThemeProvider> | ||
| ); | ||
|
|
||
| getByTestId(HIGHLIGHTED_FIELDS_HEADER_EXPAND_ICON_TEST_ID).click(); | ||
| getByTestId(HIGHLIGHTED_FIELDS_GO_TO_TABLE_LINK).click(); | ||
| expect(flyoutContextValue.openRightPanel).toHaveBeenCalledWith({ | ||
| id: RightPanelKey, | ||
| path: RightPanelTableTabPath, | ||
| params: { | ||
| id: panelContextValue.eventId, | ||
| indexName: panelContextValue.indexName, | ||
| }, | ||
| }); | ||
| expect(getByTestId(HIGHLIGHTED_FIELDS_DETAILS_TEST_ID)).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should render empty component if dataFormattedForFieldBrowser is null', () => { | ||
| const flyoutContextValue = {} as unknown as ExpandableFlyoutContext; | ||
| const panelContextValue = { | ||
| eventId: 'eventId', | ||
| indexName: 'indexName', | ||
| dataFormattedForFieldBrowser: null, | ||
| browserFields: {}, | ||
| } as unknown as RightPanelContext; | ||
|
|
||
| const { baseElement } = render( | ||
| <ExpandableFlyoutContext.Provider value={flyoutContextValue}> | ||
| <RightPanelContext.Provider value={panelContextValue}> | ||
| <HighlightedFields /> | ||
| </RightPanelContext.Provider> | ||
| </ExpandableFlyoutContext.Provider> | ||
| ); | ||
|
|
||
| expect(baseElement).toMatchInlineSnapshot(` | ||
| <body> | ||
| <div /> | ||
| </body> | ||
| `); | ||
| }); | ||
|
|
||
| it('should render empty component if browserFields is null', () => { | ||
| const flyoutContextValue = {} as unknown as ExpandableFlyoutContext; | ||
| const panelContextValue = { | ||
| eventId: 'eventId', | ||
| indexName: 'indexName', | ||
| dataFormattedForFieldBrowser: [], | ||
| browserFields: null, | ||
| } as unknown as RightPanelContext; | ||
|
|
||
| const { baseElement } = render( | ||
| <ExpandableFlyoutContext.Provider value={flyoutContextValue}> | ||
| <RightPanelContext.Provider value={panelContextValue}> | ||
| <HighlightedFields /> | ||
| </RightPanelContext.Provider> | ||
| </ExpandableFlyoutContext.Provider> | ||
| ); | ||
|
|
||
| expect(baseElement).toMatchInlineSnapshot(` | ||
| <body> | ||
| <div /> | ||
| </body> | ||
| `); | ||
| }); | ||
|
|
||
| it('should render empty component if eventId is null', () => { | ||
| const flyoutContextValue = {} as unknown as ExpandableFlyoutContext; | ||
| const panelContextValue = { | ||
| eventId: null, | ||
| indexName: 'indexName', | ||
| dataFormattedForFieldBrowser: [], | ||
| browserFields: {}, | ||
| } as unknown as RightPanelContext; | ||
|
|
||
| const { baseElement } = render( | ||
| <ExpandableFlyoutContext.Provider value={flyoutContextValue}> | ||
| <RightPanelContext.Provider value={panelContextValue}> | ||
| <HighlightedFields /> | ||
| </RightPanelContext.Provider> | ||
| </ExpandableFlyoutContext.Provider> | ||
| ); | ||
|
|
||
| expect(baseElement).toMatchInlineSnapshot(` | ||
| <body> | ||
| <div /> | ||
| </body> | ||
| `); | ||
| }); | ||
| }); | ||
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.
just a nitpick but maybe this can be extracted into some helper on top of this file, looks like it only changes a little bit in between tests
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.
that's a good point! To not slow down development (there is still a lot to do) I logged a tech debt ticket for this (I also have one for some Storybook cleanup)