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.
[SecuritySolution] Retrieve onboarding steps (elastic#181442)
## Summary Fixes elastic#181190 Relevant PRs: elastic#143598 | elastic#163739 ### Steps to Verify: 1. Entering [these](https://p.elstc.co/paste/sEmk++Tb#mjwuX7IN8hIN+kOy5gdtfweQNi9sUl+4lVRAewc6hR+) in your kibana.dev.yml 2. Execute this command to set the Guided onboarding steps to alertsCases ``` curl --location --request PUT 'http://localhost:5601/internal/guided_onboarding/state' \ --header 'kbn-xsrf: cypress-creds' \ --header 'x-elastic-internal-origin: security-solution' \ --header 'Content-Type: application/json' \ --header 'Authorization: Basic {YOUR_AUTH_TOKEN}' \. // If you are using Postman just fill in the Auth tab --data '{ "status": "in_progress", "guide": { "isActive": true, "status": "in_progress", "steps": [ { "id": "add_data", "status": "complete" }, { "id": "rules", "status": "complete" }, { "id": "alertsCases", "status": "active" } ], "guideId": "siem" } }' ``` 3. Make sure you have alerts available. 4. To test the old flyout with Guided onboarding tour, please go to Stack Management > Advanced settings > Expandable flyout **OFF** ### It compatible with the new expandable flyout: 1. It shows `expandable flyout tour` when the guided onboarding tour is **not enabled**. 3. The first two steps should be `hidden` when the `left` expandable is opened. 5. Most of the guided onboarding tour steps should be hidden when `Add to new case` flyout or `Add to existing case` modal opened. 6. Once the test case is created, the `insight section` and `correlation tab` should be opened automatically to fetch cases. 7. `expandable flyout tour` should be visible again after the guided onboarding tour is finished. https://github.com/elastic/kibana/assets/6295984/b19bfce9-ec02-4291-b616-e24d3e984a03 ### It compatible with the old flyout: https://github.com/elastic/kibana/assets/6295984/b10b8bdf-e159-4663-b455-1f4541358a11 ### Checklist Delete any items that are not applicable to this PR. - [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 --------- Co-authored-by: Sergi Massaneda <sergi.massaneda@elastic.co> Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
- Loading branch information
Showing
46 changed files
with
1,101 additions
and
383 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
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
21 changes: 21 additions & 0 deletions
21
x-pack/plugins/cases/public/components/cases_context/state/cases_state_context.ts
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,21 @@ | ||
/* | ||
* 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, { useContext } from 'react'; | ||
import type { CasesContextState } from './cases_context_reducer'; | ||
|
||
export const CasesStateContext = React.createContext<CasesContextState | undefined>(undefined); | ||
|
||
export const useCasesStateContext = () => { | ||
const casesStateContext = useContext(CasesStateContext); | ||
if (!casesStateContext) { | ||
throw new Error( | ||
'useCasesStateContext must be used within a CasesProvider and have a defined value. See https://github.com/elastic/kibana/blob/main/x-pack/plugins/cases/README.md#cases-ui' | ||
); | ||
} | ||
return casesStateContext; | ||
}; |
77 changes: 77 additions & 0 deletions
77
x-pack/plugins/cases/public/components/cases_context/state/use_is_add_to_case_open.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,77 @@ | ||
/* | ||
* 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 { act, renderHook } from '@testing-library/react-hooks'; | ||
import { useCasesAddToExistingCaseModal } from '../../all_cases/selector_modal/use_cases_add_to_existing_case_modal'; | ||
import { createAppMockRenderer } from '../../../common/mock'; | ||
import { useIsAddToCaseOpen } from './use_is_add_to_case_open'; | ||
import { useCasesToast } from '../../../common/use_cases_toast'; | ||
import { useCasesAddToNewCaseFlyout } from '../../create/flyout/use_cases_add_to_new_case_flyout'; | ||
|
||
jest.mock('../../../common/use_cases_toast'); | ||
const useCasesToastMock = useCasesToast as jest.Mock; | ||
useCasesToastMock.mockReturnValue({ | ||
showInfoToast: jest.fn(), | ||
}); | ||
|
||
const { AppWrapper } = createAppMockRenderer(); | ||
|
||
describe('use is add to existing case modal open hook', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should throw if called outside of a cases context', () => { | ||
const { result } = renderHook(useIsAddToCaseOpen); | ||
expect(result.error?.message).toContain( | ||
'useCasesStateContext must be used within a CasesProvider and have a defined value' | ||
); | ||
}); | ||
|
||
it('should return false when the add to case modal and flyout are not open', async () => { | ||
const { result } = renderHook(useIsAddToCaseOpen, { wrapper: AppWrapper }); | ||
expect(result.current).toEqual(false); | ||
}); | ||
|
||
it('should return true when the add to existing case modal opens', async () => { | ||
const { result, rerender } = renderHook( | ||
() => { | ||
return { | ||
modal: useCasesAddToExistingCaseModal(), | ||
isOpen: useIsAddToCaseOpen(), | ||
}; | ||
}, | ||
{ wrapper: AppWrapper } | ||
); | ||
|
||
expect(result.current.isOpen).toEqual(false); | ||
act(() => { | ||
result.current.modal.open(); | ||
}); | ||
rerender(); | ||
expect(result.current.isOpen).toEqual(true); | ||
}); | ||
|
||
it('should return true when the add to new case flyout opens', async () => { | ||
const { result, rerender } = renderHook( | ||
() => { | ||
return { | ||
flyout: useCasesAddToNewCaseFlyout(), | ||
isOpen: useIsAddToCaseOpen(), | ||
}; | ||
}, | ||
{ wrapper: AppWrapper } | ||
); | ||
|
||
expect(result.current.isOpen).toEqual(false); | ||
act(() => { | ||
result.current.flyout.open(); | ||
}); | ||
rerender(); | ||
expect(result.current.isOpen).toEqual(true); | ||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
x-pack/plugins/cases/public/components/cases_context/state/use_is_add_to_case_open.ts
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,18 @@ | ||
/* | ||
* 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 { useCasesStateContext } from './cases_state_context'; | ||
|
||
export type UseIsAddToCaseOpen = () => boolean; | ||
|
||
/** | ||
* This hook is to check if the "add to case" is open, either the modal or the flyout | ||
*/ | ||
export const useIsAddToCaseOpen: UseIsAddToCaseOpen = () => { | ||
const { selectCaseModal, createCaseFlyout } = useCasesStateContext(); | ||
return selectCaseModal.isModalOpen || createCaseFlyout.isFlyoutOpen; | ||
}; |
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
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.