From 28142609cc1d8f8d8f374a43954f6019ac3b8cf0 Mon Sep 17 00:00:00 2001 From: Christos Nasikas Date: Fri, 5 Nov 2021 17:03:55 +0200 Subject: [PATCH] [Cases] Fix cases navigation after attaching an alert to a case. (#117633) --- .../public/pages/alerts/alerts_table_t_grid.tsx | 3 +++ .../timeline_actions/use_add_to_case_actions.tsx | 5 +++-- .../timeline/cases/add_to_case_action.test.tsx | 3 ++- .../actions/timeline/cases/add_to_case_action.tsx | 12 +++++++----- .../timeline/cases/add_to_case_action_button.tsx | 3 ++- .../timeline/cases/add_to_existing_case_button.tsx | 2 ++ .../timeline/cases/add_to_new_case_button.tsx | 2 ++ .../actions/timeline/cases/create/flyout.test.tsx | 2 +- .../actions/timeline/cases/create/flyout.tsx | 8 ++++---- .../public/components/t_grid/standalone/index.tsx | 5 ++++- .../timelines/public/hooks/use_add_to_case.ts | 7 ++++--- .../public/applications/timelines_test/index.tsx | 1 + 12 files changed, 35 insertions(+), 18 deletions(-) diff --git a/x-pack/plugins/observability/public/pages/alerts/alerts_table_t_grid.tsx b/x-pack/plugins/observability/public/pages/alerts/alerts_table_t_grid.tsx index 9ffc12274675..8c973dfb730f 100644 --- a/x-pack/plugins/observability/public/pages/alerts/alerts_table_t_grid.tsx +++ b/x-pack/plugins/observability/public/pages/alerts/alerts_table_t_grid.tsx @@ -227,12 +227,14 @@ function ObservabilityActions({ event, casePermissions, appId: observabilityFeatureId, + owner: observabilityFeatureId, onClose: afterCaseSelection, }), timelines.getAddToNewCaseButton({ event, casePermissions, appId: observabilityFeatureId, + owner: observabilityFeatureId, onClose: afterCaseSelection, }), ] @@ -364,6 +366,7 @@ export function AlertsTableTGrid(props: AlertsTableTGridProps) { const sortDirection: SortDirection = 'desc'; return { appId: observabilityFeatureId, + casesOwner: observabilityFeatureId, casePermissions, type, columns, diff --git a/x-pack/plugins/security_solution/public/detections/components/alerts_table/timeline_actions/use_add_to_case_actions.tsx b/x-pack/plugins/security_solution/public/detections/components/alerts_table/timeline_actions/use_add_to_case_actions.tsx index a342b01b038c..708c3c396d0d 100644 --- a/x-pack/plugins/security_solution/public/detections/components/alerts_table/timeline_actions/use_add_to_case_actions.tsx +++ b/x-pack/plugins/security_solution/public/detections/components/alerts_table/timeline_actions/use_add_to_case_actions.tsx @@ -8,7 +8,7 @@ import { useMemo } from 'react'; import { useGetUserCasesPermissions, useKibana } from '../../../../common/lib/kibana'; import { TimelineId, TimelineNonEcsData } from '../../../../../common'; -import { APP_ID } from '../../../../../common/constants'; +import { APP_ID, APP_UI_ID } from '../../../../../common/constants'; import { useInsertTimeline } from '../../../../cases/components/use_insert_timeline'; import { Ecs } from '../../../../../common/ecs'; @@ -39,7 +39,8 @@ export const useAddToCaseActions = ({ event: { data: nonEcsData ?? [], ecs: ecsData, _id: ecsData?._id }, useInsertTimeline: insertTimelineHook, casePermissions, - appId: APP_ID, + appId: APP_UI_ID, + owner: APP_ID, onClose: afterCaseSelection, } : null, diff --git a/x-pack/plugins/timelines/public/components/actions/timeline/cases/add_to_case_action.test.tsx b/x-pack/plugins/timelines/public/components/actions/timeline/cases/add_to_case_action.test.tsx index 19206c40d18c..fb0a5ebcbbf9 100644 --- a/x-pack/plugins/timelines/public/components/actions/timeline/cases/add_to_case_action.test.tsx +++ b/x-pack/plugins/timelines/public/components/actions/timeline/cases/add_to_case_action.test.tsx @@ -35,7 +35,8 @@ describe('AddToCaseAction', () => { crud: true, read: true, }, - appId: 'securitySolution', + appId: 'securitySolutionUI', + owner: 'securitySolution', onClose: () => null, }; diff --git a/x-pack/plugins/timelines/public/components/actions/timeline/cases/add_to_case_action.tsx b/x-pack/plugins/timelines/public/components/actions/timeline/cases/add_to_case_action.tsx index 73be0c13faf5..c8517a26f629 100644 --- a/x-pack/plugins/timelines/public/components/actions/timeline/cases/add_to_case_action.tsx +++ b/x-pack/plugins/timelines/public/components/actions/timeline/cases/add_to_case_action.tsx @@ -25,6 +25,7 @@ export interface AddToCaseActionProps { read: boolean; } | null; appId: string; + owner: string; onClose?: Function; disableAlerts?: boolean; } @@ -35,6 +36,7 @@ const AddToCaseActionComponent: React.FC = ({ useInsertTimeline, casePermissions, appId, + owner, onClose, disableAlerts, }) => { @@ -50,7 +52,7 @@ const AddToCaseActionComponent: React.FC = ({ createCaseUrl, isAllCaseModalOpen, isCreateCaseFlyoutOpen, - } = useAddToCase({ event, useInsertTimeline, casePermissions, appId, onClose }); + } = useAddToCase({ event, useInsertTimeline, casePermissions, appId, owner, onClose }); const getAllCasesSelectorModalProps = useMemo(() => { const { ruleId, ruleName } = normalizedEventFields(event); @@ -62,7 +64,7 @@ const AddToCaseActionComponent: React.FC = ({ id: ruleId, name: ruleName, }, - owner: appId, + owner, }, createCaseNavigation: { href: createCaseUrl, @@ -75,7 +77,7 @@ const AddToCaseActionComponent: React.FC = ({ onRowClick: onCaseClicked, updateCase: onCaseSuccess, userCanCrud: casePermissions?.crud ?? false, - owner: [appId], + owner: [owner], onClose: () => dispatch(tGridActions.setOpenAddToExistingCase({ id: eventId, isOpen: false })), }; @@ -87,8 +89,8 @@ const AddToCaseActionComponent: React.FC = ({ goToCreateCase, eventId, eventIndex, - appId, dispatch, + owner, useInsertTimeline, event, ]); @@ -105,7 +107,7 @@ const AddToCaseActionComponent: React.FC = ({ onCloseFlyout={closeCaseFlyoutOpen} onSuccess={onCaseSuccess} useInsertTimeline={useInsertTimeline} - appId={appId} + owner={owner} disableAlerts={disableAlerts} /> )} diff --git a/x-pack/plugins/timelines/public/components/actions/timeline/cases/add_to_case_action_button.tsx b/x-pack/plugins/timelines/public/components/actions/timeline/cases/add_to_case_action_button.tsx index 28821028af3c..460f22d55061 100644 --- a/x-pack/plugins/timelines/public/components/actions/timeline/cases/add_to_case_action_button.tsx +++ b/x-pack/plugins/timelines/public/components/actions/timeline/cases/add_to_case_action_button.tsx @@ -25,6 +25,7 @@ const AddToCaseActionButtonComponent: React.FC = ({ useInsertTimeline, casePermissions, appId, + owner, onClose, }) => { const { @@ -36,7 +37,7 @@ const AddToCaseActionButtonComponent: React.FC = ({ openPopover, closePopover, isPopoverOpen, - } = useAddToCase({ event, useInsertTimeline, casePermissions, appId, onClose }); + } = useAddToCase({ event, useInsertTimeline, casePermissions, appId, owner, onClose }); const tooltipContext = userCanCrud ? isEventSupported ? i18n.ACTION_ADD_TO_CASE_TOOLTIP diff --git a/x-pack/plugins/timelines/public/components/actions/timeline/cases/add_to_existing_case_button.tsx b/x-pack/plugins/timelines/public/components/actions/timeline/cases/add_to_existing_case_button.tsx index 30181a96aa70..a1fdfe1e8dfa 100644 --- a/x-pack/plugins/timelines/public/components/actions/timeline/cases/add_to_existing_case_button.tsx +++ b/x-pack/plugins/timelines/public/components/actions/timeline/cases/add_to_existing_case_button.tsx @@ -18,6 +18,7 @@ const AddToCaseActionComponent: React.FC = ({ useInsertTimeline, casePermissions, appId, + owner, onClose, }) => { const { addExistingCaseClick, isDisabled, userCanCrud } = useAddToCase({ @@ -25,6 +26,7 @@ const AddToCaseActionComponent: React.FC = ({ useInsertTimeline, casePermissions, appId, + owner, onClose, }); return ( diff --git a/x-pack/plugins/timelines/public/components/actions/timeline/cases/add_to_new_case_button.tsx b/x-pack/plugins/timelines/public/components/actions/timeline/cases/add_to_new_case_button.tsx index 82ce3d1ff8dc..5c4be89f56d8 100644 --- a/x-pack/plugins/timelines/public/components/actions/timeline/cases/add_to_new_case_button.tsx +++ b/x-pack/plugins/timelines/public/components/actions/timeline/cases/add_to_new_case_button.tsx @@ -18,6 +18,7 @@ const AddToCaseActionComponent: React.FC = ({ useInsertTimeline, casePermissions, appId, + owner, onClose, }) => { const { addNewCaseClick, isDisabled, userCanCrud } = useAddToCase({ @@ -25,6 +26,7 @@ const AddToCaseActionComponent: React.FC = ({ useInsertTimeline, casePermissions, appId, + owner, onClose, }); diff --git a/x-pack/plugins/timelines/public/components/actions/timeline/cases/create/flyout.test.tsx b/x-pack/plugins/timelines/public/components/actions/timeline/cases/create/flyout.test.tsx index bbfdef803493..f1176f612725 100644 --- a/x-pack/plugins/timelines/public/components/actions/timeline/cases/create/flyout.test.tsx +++ b/x-pack/plugins/timelines/public/components/actions/timeline/cases/create/flyout.test.tsx @@ -16,7 +16,7 @@ const onSuccess = jest.fn(); const defaultProps = { onCloseFlyout, onSuccess, - appId: 'securitySolution', + owner: 'securitySolution', }; describe('CreateCaseFlyout', () => { diff --git a/x-pack/plugins/timelines/public/components/actions/timeline/cases/create/flyout.tsx b/x-pack/plugins/timelines/public/components/actions/timeline/cases/create/flyout.tsx index 727d85399022..c91c50c61fcf 100644 --- a/x-pack/plugins/timelines/public/components/actions/timeline/cases/create/flyout.tsx +++ b/x-pack/plugins/timelines/public/components/actions/timeline/cases/create/flyout.tsx @@ -19,7 +19,7 @@ export interface CreateCaseModalProps { onCloseFlyout: () => void; onSuccess: (theCase: Case) => Promise; useInsertTimeline?: Function; - appId: string; + owner: string; disableAlerts?: boolean; } @@ -70,7 +70,7 @@ const CreateCaseFlyoutComponent: React.FC = ({ afterCaseCreated, onCloseFlyout, onSuccess, - appId, + owner, disableAlerts, }) => { const { cases } = useKibana().services; @@ -80,10 +80,10 @@ const CreateCaseFlyoutComponent: React.FC = ({ onCancel: onCloseFlyout, onSuccess, withSteps: false, - owner: [appId], + owner: [owner], disableAlerts, }; - }, [afterCaseCreated, onCloseFlyout, onSuccess, appId, disableAlerts]); + }, [afterCaseCreated, onCloseFlyout, onSuccess, owner, disableAlerts]); return ( <> diff --git a/x-pack/plugins/timelines/public/components/t_grid/standalone/index.tsx b/x-pack/plugins/timelines/public/components/t_grid/standalone/index.tsx index 4ae8e1e191d8..1cb13a9d6cbb 100644 --- a/x-pack/plugins/timelines/public/components/t_grid/standalone/index.tsx +++ b/x-pack/plugins/timelines/public/components/t_grid/standalone/index.tsx @@ -80,6 +80,7 @@ const ScrollableFlexItem = styled(EuiFlexItem)` export interface TGridStandaloneProps { appId: string; + casesOwner: string; casePermissions: { crud: boolean; read: boolean; @@ -123,6 +124,7 @@ export interface TGridStandaloneProps { const TGridStandaloneComponent: React.FC = ({ afterCaseSelection, appId, + casesOwner, casePermissions, columns, defaultCellActions, @@ -275,9 +277,10 @@ const TGridStandaloneComponent: React.FC = ({ event: selectedEvent, casePermissions: casePermissions ?? null, appId, + owner: casesOwner, onClose: afterCaseSelection, }; - }, [appId, casePermissions, afterCaseSelection, selectedEvent]); + }, [appId, casePermissions, afterCaseSelection, selectedEvent, casesOwner]); const nonDeletedEvents = useMemo( () => events.filter((e) => !deletedEventIds.includes(e._id)), diff --git a/x-pack/plugins/timelines/public/hooks/use_add_to_case.ts b/x-pack/plugins/timelines/public/hooks/use_add_to_case.ts index 34622423781f..a9804eb1277c 100644 --- a/x-pack/plugins/timelines/public/hooks/use_add_to_case.ts +++ b/x-pack/plugins/timelines/public/hooks/use_add_to_case.ts @@ -81,6 +81,7 @@ export const useAddToCase = ({ useInsertTimeline, casePermissions, appId, + owner, onClose, }: AddToCaseActionProps): UseAddToCase => { const eventId = event?.ecs._id ?? ''; @@ -167,13 +168,13 @@ export const useAddToCase = ({ id: ruleId, name: ruleName, }, - owner: appId, + owner, }, updateCase, }); } }, - [eventId, eventIndex, appId, dispatch, event] + [eventId, eventIndex, owner, dispatch, event] ); const onCaseSuccess = useCallback( async (theCase: Case) => { @@ -187,7 +188,7 @@ export const useAddToCase = ({ async (ev) => { ev.preventDefault(); return navigateToApp(appId, { - deepLinkId: appId === 'securitySolution' ? 'case' : 'cases', + deepLinkId: appId === 'securitySolutionUI' ? 'case' : 'cases', path: getCreateCaseUrl(urlSearch), }); }, diff --git a/x-pack/test/plugin_functional/plugins/timelines_test/public/applications/timelines_test/index.tsx b/x-pack/test/plugin_functional/plugins/timelines_test/public/applications/timelines_test/index.tsx index 48a17dc98500..1c04ca83f18d 100644 --- a/x-pack/test/plugin_functional/plugins/timelines_test/public/applications/timelines_test/index.tsx +++ b/x-pack/test/plugin_functional/plugins/timelines_test/public/applications/timelines_test/index.tsx @@ -66,6 +66,7 @@ const AppRoot = React.memo( timelinesPluginSetup.getTGrid && timelinesPluginSetup.getTGrid<'standalone'>({ appId: 'securitySolution', + casesOwner: 'securitySolutionUI', type: 'standalone', casePermissions: { read: true,