-
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 guided tour to document details flyout (#180318)
## Summary This PR adds a guided tour for the new expandable flyout in alerts table. Where it will show up: ✅ Alerts page ✅ Alerts tab in Cases Tour will not show up in: ❌ rule creation ❌ flyout in timeline ❌ event table. https://github.com/elastic/kibana/assets/18648970/e9d0ce92-0eb4-4898-ad05-91d701aec01d **How to test** - Generate some alerts and go to Alerts page - Expand a row in alerts table - Guided tour should appear - Note that rule preview is only available to alerts. Guided tour for an event or alert preview does not have that step. To test guided tour in event and timeline, enable `expandableEventFlyoutEnabled`, `expandableTimelineFlyoutEnabled` respectively. ### Checklist - [x] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
- Loading branch information
1 parent
b2f8c0d
commit 51cc9ca
Showing
24 changed files
with
950 additions
and
14 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
121 changes: 121 additions & 0 deletions
121
...ck/plugins/security_solution/public/flyout/document_details/left/components/tour.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,121 @@ | ||
/* | ||
* 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, waitFor, fireEvent } from '@testing-library/react'; | ||
import { LeftPanelTour } from './tour'; | ||
import { LeftPanelContext } from '../context'; | ||
import { mockContextValue } from '../mocks/mock_context'; | ||
import { | ||
createMockStore, | ||
createSecuritySolutionStorageMock, | ||
TestProviders, | ||
} from '../../../../common/mock'; | ||
import { useKibana as mockUseKibana } from '../../../../common/lib/kibana/__mocks__'; | ||
import { useKibana } from '../../../../common/lib/kibana'; | ||
import { FLYOUT_TOUR_CONFIG_ANCHORS } from '../../shared/utils/tour_step_config'; | ||
import { useIsTimelineFlyoutOpen } from '../../shared/hooks/use_is_timeline_flyout_open'; | ||
import { FLYOUT_TOUR_TEST_ID } from '../../shared/components/test_ids'; | ||
|
||
jest.mock('../../../../common/lib/kibana'); | ||
jest.mock('../../shared/hooks/use_is_timeline_flyout_open'); | ||
|
||
const mockedUseKibana = mockUseKibana(); | ||
|
||
const { storage: storageMock } = createSecuritySolutionStorageMock(); | ||
const mockStore = createMockStore(undefined, undefined, undefined, { | ||
...storageMock, | ||
}); | ||
|
||
const renderLeftPanelTour = (context: LeftPanelContext = mockContextValue) => | ||
render( | ||
<TestProviders store={mockStore}> | ||
<LeftPanelContext.Provider value={context}> | ||
<LeftPanelTour /> | ||
{Object.values(FLYOUT_TOUR_CONFIG_ANCHORS).map((i, idx) => ( | ||
<div key={idx} data-test-subj={i} /> | ||
))} | ||
</LeftPanelContext.Provider> | ||
</TestProviders> | ||
); | ||
|
||
describe('<LeftPanelTour />', () => { | ||
beforeEach(() => { | ||
(useKibana as jest.Mock).mockReturnValue({ | ||
...mockedUseKibana, | ||
services: { | ||
...mockedUseKibana.services, | ||
storage: storageMock, | ||
}, | ||
}); | ||
(useIsTimelineFlyoutOpen as jest.Mock).mockReturnValue(false); | ||
|
||
storageMock.clear(); | ||
}); | ||
|
||
it('should render left panel tour for alerts starting as step 4', async () => { | ||
storageMock.set('securitySolution.documentDetails.newFeaturesTour.v8.14', { | ||
currentTourStep: 4, | ||
isTourActive: true, | ||
}); | ||
|
||
const { getByText, getByTestId } = renderLeftPanelTour(); | ||
await waitFor(() => { | ||
expect(getByTestId(`${FLYOUT_TOUR_TEST_ID}-4`)).toBeVisible(); | ||
}); | ||
fireEvent.click(getByText('Next')); | ||
await waitFor(() => { | ||
expect(getByTestId(`${FLYOUT_TOUR_TEST_ID}-5`)).toBeVisible(); | ||
}); | ||
await waitFor(() => { | ||
expect(getByText('Finish')).toBeVisible(); | ||
}); | ||
}); | ||
|
||
it('should not render left panel tour for preview', () => { | ||
storageMock.set('securitySolution.documentDetails.newFeaturesTour.v8.14', { | ||
currentTourStep: 3, | ||
isTourActive: true, | ||
}); | ||
|
||
const { queryByTestId, queryByText } = renderLeftPanelTour({ | ||
...mockContextValue, | ||
isPreview: true, | ||
}); | ||
expect(queryByTestId(`${FLYOUT_TOUR_TEST_ID}-4`)).not.toBeInTheDocument(); | ||
expect(queryByText('Next')).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('should not render left panel tour for non-alerts', async () => { | ||
storageMock.set('securitySolution.documentDetails.newFeaturesTour.v8.14', { | ||
currentTourStep: 3, | ||
isTourActive: true, | ||
}); | ||
|
||
const { queryByTestId, queryByText } = renderLeftPanelTour({ | ||
...mockContextValue, | ||
getFieldsData: () => '', | ||
}); | ||
expect(queryByTestId(`${FLYOUT_TOUR_TEST_ID}-4`)).not.toBeInTheDocument(); | ||
expect(queryByText('Next')).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('should not render left panel tour for flyout in timeline', () => { | ||
(useIsTimelineFlyoutOpen as jest.Mock).mockReturnValue(true); | ||
storageMock.set('securitySolution.documentDetails.newFeaturesTour.v8.14', { | ||
currentTourStep: 3, | ||
isTourActive: true, | ||
}); | ||
|
||
const { queryByTestId, queryByText } = renderLeftPanelTour({ | ||
...mockContextValue, | ||
isPreview: true, | ||
}); | ||
expect(queryByTestId(`${FLYOUT_TOUR_TEST_ID}-4`)).not.toBeInTheDocument(); | ||
expect(queryByText('Next')).not.toBeInTheDocument(); | ||
}); | ||
}); |
32 changes: 32 additions & 0 deletions
32
x-pack/plugins/security_solution/public/flyout/document_details/left/components/tour.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,32 @@ | ||
/* | ||
* 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, { memo, useMemo } from 'react'; | ||
import { getField } from '../../shared/utils'; | ||
import { EventKind } from '../../shared/constants/event_kinds'; | ||
import { useLeftPanelContext } from '../context'; | ||
import { FlyoutTour } from '../../shared/components/flyout_tour'; | ||
import { getLeftSectionTourSteps } from '../../shared/utils/tour_step_config'; | ||
import { useIsTimelineFlyoutOpen } from '../../shared/hooks/use_is_timeline_flyout_open'; | ||
|
||
/** | ||
* Guided tour for the left panel in details flyout | ||
*/ | ||
export const LeftPanelTour: FC = memo(() => { | ||
const { getFieldsData, isPreview } = useLeftPanelContext(); | ||
const eventKind = getField(getFieldsData('event.kind')); | ||
const isAlert = eventKind === EventKind.signal; | ||
const isTimelineFlyoutOpen = useIsTimelineFlyoutOpen(); | ||
const showTour = isAlert && !isPreview && !isTimelineFlyoutOpen; | ||
|
||
const tourStepContent = useMemo(() => getLeftSectionTourSteps(), []); | ||
|
||
return showTour ? <FlyoutTour tourStepContent={tourStepContent} totalSteps={5} /> : null; | ||
}); | ||
|
||
LeftPanelTour.displayName = 'LeftPanelTour'; |
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
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
Oops, something went wrong.