mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
# Backport This will backport the following commits from `main` to `8.9`: - [[Cases] Fix bug in cases bulk action in the alerts table (#160526)](https://github.com/elastic/kibana/pull/160526) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Christos Nasikas","email":"christos.nasikas@elastic.co"},"sourceCommit":{"committedDate":"2023-06-26T15:32:29Z","message":"[Cases] Fix bug in cases bulk action in the alerts table (#160526)\n\n## Summary\n\nIn 8.8 we move the logic of the cases action from solutions to the\nalerts table. A bug was introduced when you try to attach an alert to a\nnew case through the cases modal.\n\nBefore\n\n\n771a5d28
-e279-43d4-b72e-2dfb6689bae6\n\nError in `console`\n\n```\nUncaught (in promise) TypeError: Cannot read properties of undefined (reading 'id')\n at getAttachments (use_bulk_actions.ts💯1)\n at use_cases_add_to_existing_case_modal.tsx:52:1\n at onRowClick (use_cases_add_to_existing_case_modal.tsx:107:1)\n at all_cases_selector_modal.tsx:36:1\n at all_cases_list.tsx:208:1\n at table_filters.tsx:128:1\n at HTMLUnknownElement.callCallback (react-dom.development.js:3945:1)\n at Object.invokeGuardedCallbackDev (react-dom.development.js:3994:1)\n at invokeGuardedCallback (react-dom.development.js:4056:1)\n at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:4070:1)\n```\n\nAfter \n\n\n89e44018
-49cf-41f7-8e07-01c6eb197624\n\n### Checklist\n\nDelete any items that are not applicable to this PR.\n\n- [x] [Unit or functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere updated or added to match the most common scenarios\n\n### For maintainers\n\n- [x] This was checked for breaking API changes and was [labeled\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n\n## Release notes\nFix a bug in the alerts table where you cannot create a new case when\nattaching alerts to a case from the cases modal","sha":"df21ba0e11d24b9e7db70152b6ab421fc10db69c","branchLabelMapping":{"^v8.10.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:fix","Team:ResponseOps","Feature:Cases","v8.9.0","v8.8.2","v8.10.0"],"number":160526,"url":"https://github.com/elastic/kibana/pull/160526","mergeCommit":{"message":"[Cases] Fix bug in cases bulk action in the alerts table (#160526)\n\n## Summary\n\nIn 8.8 we move the logic of the cases action from solutions to the\nalerts table. A bug was introduced when you try to attach an alert to a\nnew case through the cases modal.\n\nBefore\n\n\n771a5d28
-e279-43d4-b72e-2dfb6689bae6\n\nError in `console`\n\n```\nUncaught (in promise) TypeError: Cannot read properties of undefined (reading 'id')\n at getAttachments (use_bulk_actions.ts💯1)\n at use_cases_add_to_existing_case_modal.tsx:52:1\n at onRowClick (use_cases_add_to_existing_case_modal.tsx:107:1)\n at all_cases_selector_modal.tsx:36:1\n at all_cases_list.tsx:208:1\n at table_filters.tsx:128:1\n at HTMLUnknownElement.callCallback (react-dom.development.js:3945:1)\n at Object.invokeGuardedCallbackDev (react-dom.development.js:3994:1)\n at invokeGuardedCallback (react-dom.development.js:4056:1)\n at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:4070:1)\n```\n\nAfter \n\n\n89e44018
-49cf-41f7-8e07-01c6eb197624\n\n### Checklist\n\nDelete any items that are not applicable to this PR.\n\n- [x] [Unit or functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere updated or added to match the most common scenarios\n\n### For maintainers\n\n- [x] This was checked for breaking API changes and was [labeled\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n\n## Release notes\nFix a bug in the alerts table where you cannot create a new case when\nattaching alerts to a case from the cases modal","sha":"df21ba0e11d24b9e7db70152b6ab421fc10db69c"}},"sourceBranch":"main","suggestedTargetBranches":["8.9","8.8"],"targetPullRequestStates":[{"branch":"8.9","label":"v8.9.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.8","label":"v8.8.2","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.10.0","labelRegex":"^v8.10.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/160526","number":160526,"mergeCommit":{"message":"[Cases] Fix bug in cases bulk action in the alerts table (#160526)\n\n## Summary\n\nIn 8.8 we move the logic of the cases action from solutions to the\nalerts table. A bug was introduced when you try to attach an alert to a\nnew case through the cases modal.\n\nBefore\n\n\n771a5d28
-e279-43d4-b72e-2dfb6689bae6\n\nError in `console`\n\n```\nUncaught (in promise) TypeError: Cannot read properties of undefined (reading 'id')\n at getAttachments (use_bulk_actions.ts💯1)\n at use_cases_add_to_existing_case_modal.tsx:52:1\n at onRowClick (use_cases_add_to_existing_case_modal.tsx:107:1)\n at all_cases_selector_modal.tsx:36:1\n at all_cases_list.tsx:208:1\n at table_filters.tsx:128:1\n at HTMLUnknownElement.callCallback (react-dom.development.js:3945:1)\n at Object.invokeGuardedCallbackDev (react-dom.development.js:3994:1)\n at invokeGuardedCallback (react-dom.development.js:4056:1)\n at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:4070:1)\n```\n\nAfter \n\n\n89e44018
-49cf-41f7-8e07-01c6eb197624\n\n### Checklist\n\nDelete any items that are not applicable to this PR.\n\n- [x] [Unit or functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere updated or added to match the most common scenarios\n\n### For maintainers\n\n- [x] This was checked for breaking API changes and was [labeled\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n\n## Release notes\nFix a bug in the alerts table where you cannot create a new case when\nattaching alerts to a case from the cases modal","sha":"df21ba0e11d24b9e7db70152b6ab421fc10db69c"}}]}] BACKPORT--> Co-authored-by: Christos Nasikas <christos.nasikas@elastic.co>
This commit is contained in:
parent
34a269f8f0
commit
769d6a3885
4 changed files with 57 additions and 1 deletions
|
@ -64,6 +64,7 @@ export const useCasesAddToExistingCaseModal = (props: AddToExistingCaseModalProp
|
|||
getAttachments?: ({ theCase }: { theCase?: CaseUI }) => CaseAttachmentsWithoutOwner
|
||||
) => {
|
||||
const attachments = getAttachments?.({ theCase }) ?? [];
|
||||
|
||||
// when the case is undefined in the modal
|
||||
// the user clicked "create new case"
|
||||
if (theCase === undefined) {
|
||||
|
|
|
@ -43,9 +43,11 @@ describe('bulk action hooks', () => {
|
|||
const refresh = jest.fn();
|
||||
const clearSelection = jest.fn();
|
||||
const openNewCase = jest.fn();
|
||||
|
||||
const openExistingCase = jest.fn().mockImplementation(({ getAttachments }) => {
|
||||
getAttachments({ theCase: { id: caseId } });
|
||||
});
|
||||
|
||||
mockCaseService.helpers.canUseCases = jest.fn().mockReturnValue({ create: true, read: true });
|
||||
mockCaseService.ui.getCasesContext = jest.fn().mockReturnValue(() => 'Cases context');
|
||||
|
||||
|
@ -124,6 +126,55 @@ describe('bulk action hooks', () => {
|
|||
expect(openExistingCase).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should open the flyout from the case modal', async () => {
|
||||
openExistingCase.mockImplementationOnce(({ getAttachments }) => {
|
||||
getAttachments({ theCase: undefined });
|
||||
});
|
||||
|
||||
const alerts = [
|
||||
{
|
||||
_id: 'alert0',
|
||||
_index: 'idx0',
|
||||
data: [
|
||||
{
|
||||
field: 'kibana.alert.case_ids',
|
||||
value: [caseId],
|
||||
},
|
||||
],
|
||||
ecs: {
|
||||
_id: 'alert0',
|
||||
_index: 'idx0',
|
||||
},
|
||||
},
|
||||
{
|
||||
_id: 'alert1',
|
||||
_index: 'idx1',
|
||||
data: [
|
||||
{
|
||||
field: 'kibana.alert.case_ids',
|
||||
value: ['test-case-2'],
|
||||
},
|
||||
],
|
||||
ecs: {
|
||||
_id: 'alert1',
|
||||
_index: 'idx1',
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const { result } = renderHook(
|
||||
() => useBulkAddToCaseActions({ casesConfig, refresh, clearSelection }),
|
||||
{
|
||||
wrapper: appMockRender.AppWrapper,
|
||||
}
|
||||
);
|
||||
|
||||
// @ts-expect-error: cases do not need all arguments
|
||||
result.current[1].onClick(alerts);
|
||||
|
||||
expect(mockCaseService.helpers.groupAlertsByRule).toHaveBeenCalledWith(alerts);
|
||||
});
|
||||
|
||||
it('should remove alerts that are already attached to the case', async () => {
|
||||
const { result } = renderHook(
|
||||
() => useBulkAddToCaseActions({ casesConfig, refresh, clearSelection }),
|
||||
|
|
|
@ -146,6 +146,10 @@ export const useBulkAddToCaseActions = ({
|
|||
onClick: (alerts?: TimelineItem[]) => {
|
||||
selectCaseModal.open({
|
||||
getAttachments: ({ theCase }) => {
|
||||
if (theCase == null) {
|
||||
return alerts ? casesService?.helpers.groupAlertsByRule(alerts) ?? [] : [];
|
||||
}
|
||||
|
||||
return getCaseAttachments({
|
||||
alerts,
|
||||
caseId: theCase.id,
|
||||
|
|
|
@ -48,7 +48,7 @@ type UseCasesAddToExistingCaseModal = (props?: Record<string, unknown>) => {
|
|||
open: ({
|
||||
getAttachments,
|
||||
}: {
|
||||
getAttachments: ({ theCase }: { theCase: { id: string } }) => any[];
|
||||
getAttachments: ({ theCase }: { theCase?: { id: string } }) => any[];
|
||||
}) => void;
|
||||
close: () => void;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue