-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[Cases] Refactor: Move cases action buttons out of timelines #126265
Merged
academo
merged 94 commits into
elastic:main
from
academo:refactor/cases-action-buttons-out-of-timelines
Mar 3, 2022
Merged
Changes from 93 commits
Commits
Show all changes
94 commits
Select commit
Hold shift + click to select a range
bcfad7e
WIP
905abb5
WIP2
dc424af
Use new cases context hooks to open and close the flyout
143d99d
Update timelines to use new hooks
6959d73
CLose flyout on create success
0b40092
Add back sucess toast
e3f4133
Move code to a dedicated component
f14fdaf
Add CasesContext to observability
7e1e92f
Remove dependency
352ca84
Small refactor
0ff9cbb
Use observabilityAppId instead of observabilityFeatureId for buttons
49b2985
Add CasesContext to timetable
4db364e
Fix detection engine test cases
0c1d07c
Fix broken tests
b48bdb1
Fix broken tests
05ad4c4
Rename hook
ac2c745
Add test cases for cases context ui
8df4ff9
Add test for new hook
c48e33f
Remove state from the provider context
74a5fa3
Remove basevalue
49387de
apply suggested renaming
1ca5435
Add usecallback
0573285
Add reducer types, fix test type, remove redundant check
2114d79
Accept attachments as a prop for the cases select modal
2e6307a
Expose useCasesAddToExistingCase hook, reducer code and global component
cd78b3c
use the new hook to open the select cases modasl
a2c0428
Fix tests and types
5b48b85
Add tests for cases global components
9ecb270
[Fleet] showing agent policy creation error message on UI (#125931)
juliaElastic 09154c2
[ResponseOps] Adds tooltip to time window selector in ES query rule f…
szabosteve 531eb8f
[Lens] Allow detaching from global time range (#125563)
flash1293 95c437c
[Fleet] refactor auto upgrade package policies logic (#125909)
juliaElastic 6140292
skip flaky suite (#126027)
mistic b9af573
Remove deprecated api (#125524)
criamico 62cfeac
Upgrade `markdown-it` dependency (`10.0.0` → `12.3.2`). (#125526)
azasypkin fc43fb7
skipping failing tests (#126039)
MadameSheema 89b17a2
remove unused deprecated code and use field format plugin directly fo…
mattkime 5be8008
[data views] Improve preview pane (#126013)
mattkime c06f45b
[Alerting] Provide services to set context for recovered alerts (#124…
ymao1 fef5006
[Discover] Re-introduce saved_searches test (#126059)
d0f0f0a
[Archive Migration] index pattern without timefield (#125870)
43f9642
delete unused es_archive visualize_embedding (#126001)
b954622
Bump packages (#126119)
jportner 4cb5e60
Add tests for all cases selector and attachments
e3c0706
Add tests for use add to existing case hook
6a1d4e6
Merge remote-tracking branch 'upstream/main' into refactor/cases-add-…
3b1a27e
Merge remote-tracking branch 'upstream/main' into refactor/cases-add-…
051d73c
Merge remote-tracking branch 'upstream/main' into refactor/cases-add-…
b3aa5b4
First version of the cases timeline actions
e8bb69f
export add alert to new case button from cases plugin
dc0799d
Make Cases ECS compatible with timelines and security_solution
8276423
Delete new case button
00a4045
Add helpers
564067a
Use the cases hook directly for add to new case
8da19dc
Merge remote-tracking branch 'upstream/main' into refactor/cases-acti…
f59c2af
Merge remote-tracking branch 'upstream/main' into refactor/cases-acti…
5defb0b
Remov unused dependencies
00953b0
Rename callbacks, remove timelines calls
2226ed7
Fixing tests for the dropdown
dcecbbd
Fix broken test
edbf3ca
mocking cases for tests
c55e626
Fix detectiosn tests
a46c296
Merge remote-tracking branch 'upstream/main' into refactor/cases-acti…
7bfb741
Merge remote-tracking branch 'upstream/main' into refactor/cases-acti…
5f06c64
Observability now uses the new cases hooks
9f1be0b
Wrap events viewer into cases context
e357096
Merge remote-tracking branch 'upstream/main' into refactor/cases-acti…
b8218df
Merge branch 'main' into refactor/cases-action-buttons-out-of-timelines
academo 0b35248
Open the create case flyout if create case was selected in the modal
8e23e5c
Fix cases mocks for security_solution
a8485ba
Update tests
9ba06da
Merge remote-tracking branch 'upstream/main' into refactor/cases-acti…
480263e
Add tests for use cases toast
c5b55da
Improve cases mock
c5a5518
delete security mock
1181fe7
replace tests mocks for cases
c092167
fix import mock
302316b
Do not require onRowClick
d525312
Show the toast inside the modal
ba0da91
show the toast inside the flyout
2eab5da
remove toast logic from the consumer plugin
a594b93
fix typescript types
c322fa1
Rename type
b5b3a59
Fix broken test
cd0be88
Fix file name and broken test
de1c0f1
Use internal navigation hook
b92c00c
Update hook dependencies
cf47c49
Move useCaseToast
f80a1b7
Fix mock paths
9294657
fix eslint
5147ade
Merge remote-tracking branch 'upstream/main' into refactor/cases-acti…
115998c
Add test cases for the toast content
fbee51e
Merge remote-tracking branch 'upstream/main' into refactor/cases-acti…
8878fa1
Add cases context to the overview page
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 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
75 changes: 75 additions & 0 deletions
75
x-pack/plugins/cases/public/common/use_cases_toast.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 { renderHook } from '@testing-library/react-hooks'; | ||
import { useToasts } from '../common/lib/kibana'; | ||
import { AppMockRenderer, createAppMockRenderer, TestProviders } from '../common/mock'; | ||
import { CaseToastSuccessContent, useCasesToast } from './use_cases_toast'; | ||
import { mockCase } from '../containers/mock'; | ||
import React from 'react'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
jest.mock('../common/lib/kibana'); | ||
|
||
const useToastsMock = useToasts as jest.Mock; | ||
|
||
describe('Use cases toast hook', () => { | ||
academo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
describe('Toast hook', () => { | ||
const successMock = jest.fn(); | ||
useToastsMock.mockImplementation(() => { | ||
return { | ||
addSuccess: successMock, | ||
}; | ||
}); | ||
it('should create a success tost when invoked with a case', () => { | ||
const { result } = renderHook( | ||
() => { | ||
return useCasesToast(); | ||
}, | ||
{ wrapper: TestProviders } | ||
); | ||
result.current.showSuccessAttach(mockCase); | ||
expect(successMock).toHaveBeenCalled(); | ||
}); | ||
}); | ||
describe('Toast content', () => { | ||
let appMockRender: AppMockRenderer; | ||
const onViewCaseClick = jest.fn(); | ||
beforeEach(() => { | ||
appMockRender = createAppMockRenderer(); | ||
onViewCaseClick.mockReset(); | ||
}); | ||
|
||
it('renders a correct successfull message with synced alerts', () => { | ||
const result = appMockRender.render( | ||
<CaseToastSuccessContent syncAlerts={true} onViewCaseClick={onViewCaseClick} /> | ||
); | ||
expect(result.getByTestId('toaster-content-sync-text')).toHaveTextContent( | ||
'Alerts in this case have their status synched with the case status' | ||
); | ||
expect(result.getByTestId('toaster-content-case-view-link')).toHaveTextContent('View Case'); | ||
expect(onViewCaseClick).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('renders a correct successfull message with not synced alerts', () => { | ||
const result = appMockRender.render( | ||
<CaseToastSuccessContent syncAlerts={false} onViewCaseClick={onViewCaseClick} /> | ||
); | ||
expect(result.queryByTestId('toaster-content-sync-text')).toBeFalsy(); | ||
expect(result.getByTestId('toaster-content-case-view-link')).toHaveTextContent('View Case'); | ||
expect(onViewCaseClick).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('Calls the onViewCaseClick when clicked', () => { | ||
const result = appMockRender.render( | ||
<CaseToastSuccessContent syncAlerts={false} onViewCaseClick={onViewCaseClick} /> | ||
); | ||
userEvent.click(result.getByTestId('toaster-content-case-view-link')); | ||
expect(onViewCaseClick).toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); |
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,82 @@ | ||
/* | ||
* 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 { EuiButtonEmpty, EuiText } from '@elastic/eui'; | ||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
import { toMountPoint } from '../../../../../src/plugins/kibana_react/public'; | ||
import { Case } from '../../common'; | ||
import { useToasts } from '../common/lib/kibana'; | ||
import { useCaseViewNavigation } from '../common/navigation'; | ||
import { CASE_SUCCESS_SYNC_TEXT, CASE_SUCCESS_TOAST, VIEW_CASE } from './translations'; | ||
|
||
const LINE_CLAMP = 3; | ||
const Title = styled.span` | ||
text-overflow: ellipsis; | ||
display: -webkit-box; | ||
-webkit-line-clamp: ${LINE_CLAMP}; | ||
-webkit-box-orient: vertical; | ||
overflow: hidden; | ||
`; | ||
const EuiTextStyled = styled(EuiText)` | ||
${({ theme }) => ` | ||
margin-bottom: ${theme.eui?.paddingSizes?.s ?? 8}px; | ||
`} | ||
`; | ||
|
||
export const useCasesToast = () => { | ||
const { navigateToCaseView } = useCaseViewNavigation(); | ||
|
||
const toasts = useToasts(); | ||
|
||
return { | ||
showSuccessAttach: (theCase: Case) => { | ||
const onViewCaseClick = () => { | ||
navigateToCaseView({ | ||
detailName: theCase.id, | ||
}); | ||
}; | ||
return toasts.addSuccess({ | ||
color: 'success', | ||
iconType: 'check', | ||
title: toMountPoint(<Title>{CASE_SUCCESS_TOAST(theCase.title)}</Title>), | ||
text: toMountPoint( | ||
<CaseToastSuccessContent | ||
syncAlerts={theCase.settings.syncAlerts} | ||
onViewCaseClick={onViewCaseClick} | ||
/> | ||
), | ||
}); | ||
}, | ||
}; | ||
}; | ||
export const CaseToastSuccessContent = ({ | ||
syncAlerts, | ||
onViewCaseClick, | ||
}: { | ||
syncAlerts: boolean; | ||
onViewCaseClick: () => void; | ||
}) => { | ||
return ( | ||
<> | ||
{syncAlerts && ( | ||
<EuiTextStyled size="s" data-test-subj="toaster-content-sync-text"> | ||
{CASE_SUCCESS_SYNC_TEXT} | ||
</EuiTextStyled> | ||
)} | ||
<EuiButtonEmpty | ||
size="xs" | ||
flush="left" | ||
onClick={onViewCaseClick} | ||
data-test-subj="toaster-content-case-view-link" | ||
> | ||
{VIEW_CASE} | ||
</EuiButtonEmpty> | ||
</> | ||
); | ||
}; | ||
CaseToastSuccessContent.displayName = 'CaseToastSuccessContent'; |
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.
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.
This change is necessary to allow integration with security and observability that define this as possible undefined on their own ECS types.