-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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 attach alert to new case flyout #125505
[Cases] Refactor attach alert to new case flyout #125505
Conversation
…lyout-modal-cases-alert
@@ -26,15 +26,6 @@ export interface CasesContextFeatures { | |||
|
|||
export type CasesFeatures = Partial<CasesContextFeatures>; | |||
|
|||
export interface CasesContextValue { |
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 was moved out of here as it is not a common type for BE and FE but only FE.
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.
@academo Out of curiosity what does BE and FE stand for?
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.
BE = Backend, FE = Frontend.
@@ -0,0 +1,50 @@ | |||
/* |
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 reducer will be only to handle the state for the CasesContext which will handle the flyout, modals and in general third integrations. It is not intended to be used for all cases plugin purposes.
@@ -0,0 +1,21 @@ | |||
/* |
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 is the component that decides to show or not the flyout based on the state and eventually the select case modal too and any other integration the cases plugin would offer.
|
||
export const CasesContext = React.createContext<CasesContextValue | undefined>(undefined); | ||
export interface CasesContextValue { |
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.
Brought from common types.
@@ -16,8 +16,8 @@ import { UsePostComment } from '../../../containers/use_post_comment'; | |||
|
|||
export interface CreateCaseFlyoutProps { | |||
afterCaseCreated?: (theCase: Case, postComment: UsePostComment['postComment']) => Promise<void>; | |||
onClose: () => void; | |||
onSuccess: (theCase: Case) => Promise<void>; | |||
onClose?: () => void; |
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.
These attributes are now optional because third party plugins might decide to not need them. The idea is they could simply say: "Open the modal, attach this info to a case" and might or not care about the outcome of the operation.
@@ -0,0 +1,45 @@ | |||
/* |
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 hook is the direct integration with third party plugins. Plugins will load this hook and use it to open or close the flyout as required.
@@ -57,6 +57,7 @@ const MySpinner = styled(EuiLoadingSpinner)` | |||
`; | |||
export type SupportedCreateCaseAttachment = CommentRequestAlertType | CommentRequestUserType; | |||
export type CreateCaseAttachment = SupportedCreateCaseAttachment[]; | |||
export type CaseAttachments = SupportedCreateCaseAttachment[]; |
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 is a type to replace CreateCaseAttachment
. That will come in cleanup PRs to make this PR smaller.
@@ -0,0 +1,34 @@ | |||
/* |
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.
lazy component to load the CasesContext.
The CasesContext
is required to render the cases flyout and eventually the modals. You use the useCreateCaseFlyout hook to interact with this context.
Plugins should wrap the components that will show the flyout or modal on this.
x-pack/plugins/cases/public/components/create/flyout/use_cases_add_to_new_case_flyout.test.tsx
Show resolved
Hide resolved
x-pack/plugins/security_solution/public/common/lib/kibana/hooks.ts
Outdated
Show resolved
Hide resolved
x-pack/plugins/observability/public/pages/alerts/containers/alerts_page/alerts_page.tsx
Show resolved
Hide resolved
x-pack/plugins/timelines/public/components/actions/timeline/cases/add_to_new_case_button.tsx
Show resolved
Hide resolved
onSuccess: onCaseSuccess, | ||
}); | ||
|
||
const handleClick = () => { |
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 code will be moved out in following PRs. see #125945
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.
LGTM! Thank you for doing this! 🚀
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.
👍 changes lgtm, on the right track to removing from timelines
@elasticmachine merge upstream |
@elasticmachine merge upstream |
💛 Build succeeded, but was flakyTest FailuresMetrics [docs]Module Count
Public APIs missing comments
Async chunks
Public APIs missing exports
Page load bundle
Unknown metric groupsAPI count
ESLint disabled in files
ESLint disabled line counts
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: cc @academo |
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.
LGTM! I confirm that add to case
works well in Obervability
@@ -140,6 +159,7 @@ export const useAddToCase = ({ | |||
} | |||
}, [onClose, closePopover, dispatch, eventId]); | |||
return { | |||
caseAttachments, | |||
addNewCaseClick, |
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.
@academo I was wondering if we can get rid of addNewCaseClick
. This is currently used here https://github.com/elastic/kibana/blob/main/x-pack/plugins/timelines/public/components/actions/timeline/cases/add_to_case_action_button.tsx#L49, which actually comes down to https://github.com/elastic/kibana/blob/main/x-pack/plugins/timelines/public/plugin.ts#L100, but I don't see getAddToCasePopover
being used anywhere.
My understanding is that add_to_new_case_button.tsx
is currently in use, where as add_to_case_action_button.tsx
is a leftover. If that's the case, could you get rid of unused stuff in the follow up PRs you are working on?
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.
Friendly reminder: Looks like this PR hasn’t been backported yet. |
Co-authored-by: Kibana Machine <[email protected]>
Summary
Closes #124524 see there for more details.
Refactors the existing method to open the "attach to new case" flyout in timelines. This PR itself doesn't change any user behaviour or UI.
This PR introduces these changes:
useCasesAddToNewCaseFlyout
hook to invoke the add to new case flyout from any third party plugin. To use this hook, plugins must wrap their code in a<CasesContext>
CasesContext
.Missing in this PR:
getAddToCasePopover
#125658A follow up PR will address Refactor plugin cases "Attach to existing case"
Diagrams
In a visual way, the code is coming from this:
to this:
Checklist
Delete any items that are not applicable to this PR.