From 5eaf2a3a0e3d6a9b52d7663f8a0537b048a8a8ab Mon Sep 17 00:00:00 2001 From: Angela Chuang <6295984+angorayc@users.noreply.github.com> Date: Fri, 20 Mar 2020 10:09:12 +0000 Subject: [PATCH] [SIEM] Export timeline (#58368) * update layout * add utility bars * add icon * adding a route for exporting timeline * organizing data * fix types * fix incorrect props for timeline table * add export timeline to tables action * fix types * add client side unit test * add server-side unit test * fix title for delete timelines * fix unit tests * update snapshot * fix dependency * add table ref * remove custom link * remove custom links * Update x-pack/legacy/plugins/siem/common/constants.ts Co-Authored-By: Xavier Mouligneau <189600+XavierM@users.noreply.github.com> * remove type ExportTimelineIds * reduce props * Get notes and pinned events by timeline id * combine notes and pinned events data * fix unit test * fix type error * fix type error * fix unit tests * fix for review * clean up generic downloader * review with angela * review utils * fix for code review * fix for review * fix tests * review * fix title of delete modal * remove an extra bracket Co-authored-by: Xavier Mouligneau <189600+XavierM@users.noreply.github.com> Co-authored-by: Elastic Machine --- .../legacy/plugins/siem/common/constants.ts | 3 + .../__snapshots__/index.test.tsx.snap | 3 + .../generic_downloader}/index.test.tsx | 10 +- .../generic_downloader}/index.tsx | 56 +- .../generic_downloader}/translations.ts | 0 .../delete_timeline_modal.test.tsx | 8 +- .../delete_timeline_modal.tsx | 42 +- .../delete_timeline_modal/index.test.tsx | 112 +--- .../delete_timeline_modal/index.tsx | 67 +- .../open_timeline/edit_timeline_actions.tsx | 58 ++ .../edit_timeline_batch_actions.tsx | 116 ++++ .../export_timeline/export_timeline.test.tsx | 90 +++ .../export_timeline/export_timeline.tsx | 59 ++ .../export_timeline/index.test.tsx | 35 + .../open_timeline/export_timeline/index.tsx | 73 +++ .../open_timeline/export_timeline/mocks.ts | 99 +++ .../components/open_timeline/index.test.tsx | 5 - .../public/components/open_timeline/index.tsx | 3 +- .../open_timeline/open_timeline.test.tsx | 266 ++++++++ .../open_timeline/open_timeline.tsx | 193 ++++-- .../open_timeline_modal_body.tsx | 1 - .../open_timeline/search_row/index.test.tsx | 151 ----- .../open_timeline/search_row/index.tsx | 74 +-- .../timelines_table/actions_columns.test.tsx | 192 ++---- .../timelines_table/actions_columns.tsx | 98 +-- .../timelines_table/common_columns.test.tsx | 613 ++++-------------- .../timelines_table/extended_columns.test.tsx | 72 +- .../icon_header_columns.test.tsx | 240 ++----- .../timelines_table/index.test.tsx | 359 ++-------- .../open_timeline/timelines_table/index.tsx | 55 +- .../open_timeline/timelines_table/mocks.ts | 32 + .../open_timeline/title_row/index.test.tsx | 116 +--- .../open_timeline/title_row/index.tsx | 53 +- .../components/open_timeline/translations.ts | 40 +- .../public/components/open_timeline/types.ts | 22 +- .../utility_bar/utility_bar_text.tsx | 2 +- .../detection_engine/rules/api.test.ts | 10 +- .../containers/detection_engine/rules/api.ts | 10 +- .../detection_engine/rules/types.ts | 4 +- .../public/containers/timeline/all/api.ts | 30 + .../public/containers/timeline/all/index.tsx | 14 +- .../detection_engine/rules/all/index.tsx | 10 +- .../__snapshots__/index.test.tsx.snap | 7 +- .../rule_actions_overflow/index.tsx | 11 +- .../__snapshots__/index.test.tsx.snap | 3 - .../public/pages/timelines/timelines_page.tsx | 38 +- .../public/pages/timelines/translations.ts | 7 + .../server/graphql/timeline/schema.gql.ts | 2 +- .../routes/rules/utils.test.ts | 12 +- .../detection_engine/routes/rules/utils.ts | 8 +- .../detection_engine/rules/get_export_all.ts | 4 +- .../rules/get_export_by_object_ids.ts | 4 +- .../siem/server/lib/note/saved_object.ts | 2 +- .../server/lib/pinned_event/saved_object.ts | 2 +- .../routes/__mocks__/request_responses.ts | 250 +++++++ .../routes/export_timelines_route.test.ts | 97 +++ .../timeline/routes/export_timelines_route.ts | 75 +++ .../routes/schemas/export_timelines_schema.ts | 20 + .../lib/timeline/routes/schemas/schemas.ts | 13 + .../siem/server/lib/timeline/routes/utils.ts | 187 ++++++ .../siem/server/lib/timeline/saved_object.ts | 6 +- .../plugins/siem/server/lib/timeline/types.ts | 59 +- .../plugins/siem/server/routes/index.ts | 3 + 63 files changed, 2425 insertions(+), 1881 deletions(-) create mode 100644 x-pack/legacy/plugins/siem/public/components/generic_downloader/__snapshots__/index.test.tsx.snap rename x-pack/legacy/plugins/siem/public/{pages/detection_engine/rules/components/rule_downloader => components/generic_downloader}/index.test.tsx (63%) rename x-pack/legacy/plugins/siem/public/{pages/detection_engine/rules/components/rule_downloader => components/generic_downloader}/index.tsx (62%) rename x-pack/legacy/plugins/siem/public/{pages/detection_engine/rules/components/rule_downloader => components/generic_downloader}/translations.ts (100%) create mode 100644 x-pack/legacy/plugins/siem/public/components/open_timeline/edit_timeline_actions.tsx create mode 100644 x-pack/legacy/plugins/siem/public/components/open_timeline/edit_timeline_batch_actions.tsx create mode 100644 x-pack/legacy/plugins/siem/public/components/open_timeline/export_timeline/export_timeline.test.tsx create mode 100644 x-pack/legacy/plugins/siem/public/components/open_timeline/export_timeline/export_timeline.tsx create mode 100644 x-pack/legacy/plugins/siem/public/components/open_timeline/export_timeline/index.test.tsx create mode 100644 x-pack/legacy/plugins/siem/public/components/open_timeline/export_timeline/index.tsx create mode 100644 x-pack/legacy/plugins/siem/public/components/open_timeline/export_timeline/mocks.ts create mode 100644 x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/mocks.ts create mode 100644 x-pack/legacy/plugins/siem/public/containers/timeline/all/api.ts delete mode 100644 x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/rule_downloader/__snapshots__/index.test.tsx.snap create mode 100644 x-pack/legacy/plugins/siem/server/lib/timeline/routes/__mocks__/request_responses.ts create mode 100644 x-pack/legacy/plugins/siem/server/lib/timeline/routes/export_timelines_route.test.ts create mode 100644 x-pack/legacy/plugins/siem/server/lib/timeline/routes/export_timelines_route.ts create mode 100644 x-pack/legacy/plugins/siem/server/lib/timeline/routes/schemas/export_timelines_schema.ts create mode 100644 x-pack/legacy/plugins/siem/server/lib/timeline/routes/schemas/schemas.ts create mode 100644 x-pack/legacy/plugins/siem/server/lib/timeline/routes/utils.ts diff --git a/x-pack/legacy/plugins/siem/common/constants.ts b/x-pack/legacy/plugins/siem/common/constants.ts index 2a30293c244afd..c3fc4aea77863f 100644 --- a/x-pack/legacy/plugins/siem/common/constants.ts +++ b/x-pack/legacy/plugins/siem/common/constants.ts @@ -72,6 +72,9 @@ export const DETECTION_ENGINE_TAGS_URL = `${DETECTION_ENGINE_URL}/tags`; export const DETECTION_ENGINE_RULES_STATUS_URL = `${DETECTION_ENGINE_RULES_URL}/_find_statuses`; export const DETECTION_ENGINE_PREPACKAGED_RULES_STATUS_URL = `${DETECTION_ENGINE_RULES_URL}/prepackaged/_status`; +export const TIMELINE_URL = '/api/timeline'; +export const TIMELINE_EXPORT_URL = `${TIMELINE_URL}/_export`; + /** * Default signals index key for kibana.dev.yml */ diff --git a/x-pack/legacy/plugins/siem/public/components/generic_downloader/__snapshots__/index.test.tsx.snap b/x-pack/legacy/plugins/siem/public/components/generic_downloader/__snapshots__/index.test.tsx.snap new file mode 100644 index 00000000000000..219be8cbda311f --- /dev/null +++ b/x-pack/legacy/plugins/siem/public/components/generic_downloader/__snapshots__/index.test.tsx.snap @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`GenericDownloader renders correctly against snapshot 1`] = ``; diff --git a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/rule_downloader/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/generic_downloader/index.test.tsx similarity index 63% rename from x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/rule_downloader/index.test.tsx rename to x-pack/legacy/plugins/siem/public/components/generic_downloader/index.test.tsx index 6306260dfc872f..a70772911ba605 100644 --- a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/rule_downloader/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/generic_downloader/index.test.tsx @@ -6,12 +6,16 @@ import { shallow } from 'enzyme'; import React from 'react'; -import { RuleDownloaderComponent } from './index'; +import { GenericDownloaderComponent } from './index'; -describe('RuleDownloader', () => { +describe('GenericDownloader', () => { test('renders correctly against snapshot', () => { const wrapper = shallow( - + ); expect(wrapper).toMatchSnapshot(); }); diff --git a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/rule_downloader/index.tsx b/x-pack/legacy/plugins/siem/public/components/generic_downloader/index.tsx similarity index 62% rename from x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/rule_downloader/index.tsx rename to x-pack/legacy/plugins/siem/public/components/generic_downloader/index.tsx index 959864d50747fa..6f08f5c8c381cd 100644 --- a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/rule_downloader/index.tsx +++ b/x-pack/legacy/plugins/siem/public/components/generic_downloader/index.tsx @@ -7,18 +7,28 @@ import React, { useEffect, useRef } from 'react'; import styled from 'styled-components'; import { isFunction } from 'lodash/fp'; -import { exportRules } from '../../../../../containers/detection_engine/rules'; -import { useStateToaster, errorToToaster } from '../../../../../components/toasters'; import * as i18n from './translations'; +import { ExportDocumentsProps } from '../../containers/detection_engine/rules'; +import { useStateToaster, errorToToaster } from '../toasters'; + const InvisibleAnchor = styled.a` display: none; `; -export interface RuleDownloaderProps { +export type ExportSelectedData = ({ + excludeExportDetails, + filename, + ids, + signal, +}: ExportDocumentsProps) => Promise; + +export interface GenericDownloaderProps { filename: string; - ruleIds?: string[]; - onExportComplete: (exportCount: number) => void; + ids?: string[]; + exportSelectedData: ExportSelectedData; + onExportSuccess?: (exportCount: number) => void; + onExportFailure?: () => void; } /** @@ -28,11 +38,14 @@ export interface RuleDownloaderProps { * @param payload Rule[] * */ -export const RuleDownloaderComponent = ({ + +export const GenericDownloaderComponent = ({ + exportSelectedData, filename, - ruleIds, - onExportComplete, -}: RuleDownloaderProps) => { + ids, + onExportSuccess, + onExportFailure, +}: GenericDownloaderProps) => { const anchorRef = useRef(null); const [, dispatchToaster] = useStateToaster(); @@ -40,11 +53,11 @@ export const RuleDownloaderComponent = ({ let isSubscribed = true; const abortCtrl = new AbortController(); - async function exportData() { - if (anchorRef && anchorRef.current && ruleIds != null && ruleIds.length > 0) { + const exportData = async () => { + if (anchorRef && anchorRef.current && ids != null && ids.length > 0) { try { - const exportResponse = await exportRules({ - ruleIds, + const exportResponse = await exportSelectedData({ + ids, signal: abortCtrl.signal, }); @@ -61,15 +74,20 @@ export const RuleDownloaderComponent = ({ window.URL.revokeObjectURL(objectURL); } - onExportComplete(ruleIds.length); + if (onExportSuccess != null) { + onExportSuccess(ids.length); + } } } catch (error) { if (isSubscribed) { + if (onExportFailure != null) { + onExportFailure(); + } errorToToaster({ title: i18n.EXPORT_FAILURE, error, dispatchToaster }); } } } - } + }; exportData(); @@ -77,13 +95,13 @@ export const RuleDownloaderComponent = ({ isSubscribed = false; abortCtrl.abort(); }; - }, [ruleIds]); + }, [ids]); return ; }; -RuleDownloaderComponent.displayName = 'RuleDownloaderComponent'; +GenericDownloaderComponent.displayName = 'GenericDownloaderComponent'; -export const RuleDownloader = React.memo(RuleDownloaderComponent); +export const GenericDownloader = React.memo(GenericDownloaderComponent); -RuleDownloader.displayName = 'RuleDownloader'; +GenericDownloader.displayName = 'GenericDownloader'; diff --git a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/rule_downloader/translations.ts b/x-pack/legacy/plugins/siem/public/components/generic_downloader/translations.ts similarity index 100% rename from x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/rule_downloader/translations.ts rename to x-pack/legacy/plugins/siem/public/components/generic_downloader/translations.ts diff --git a/x-pack/legacy/plugins/siem/public/components/open_timeline/delete_timeline_modal/delete_timeline_modal.test.tsx b/x-pack/legacy/plugins/siem/public/components/open_timeline/delete_timeline_modal/delete_timeline_modal.test.tsx index e061141bf43e78..bb8f9b807c0302 100644 --- a/x-pack/legacy/plugins/siem/public/components/open_timeline/delete_timeline_modal/delete_timeline_modal.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/open_timeline/delete_timeline_modal/delete_timeline_modal.test.tsx @@ -12,10 +12,10 @@ import { DeleteTimelineModal } from './delete_timeline_modal'; import * as i18n from '../translations'; describe('DeleteTimelineModal', () => { - test('it renders the expected title when a title is specified', () => { + test('it renders the expected title when a timeline is selected', () => { const wrapper = mountWithIntl( @@ -29,10 +29,10 @@ describe('DeleteTimelineModal', () => { ).toEqual('Delete "Privilege Escalation"?'); }); - test('it trims leading and trailing whitespace around the title', () => { + test('it trims leading whitespace around the title', () => { const wrapper = mountWithIntl( diff --git a/x-pack/legacy/plugins/siem/public/components/open_timeline/delete_timeline_modal/delete_timeline_modal.tsx b/x-pack/legacy/plugins/siem/public/components/open_timeline/delete_timeline_modal/delete_timeline_modal.tsx index 82fe0d1d162a4b..026c43feeff9b4 100644 --- a/x-pack/legacy/plugins/siem/public/components/open_timeline/delete_timeline_modal/delete_timeline_modal.tsx +++ b/x-pack/legacy/plugins/siem/public/components/open_timeline/delete_timeline_modal/delete_timeline_modal.tsx @@ -6,7 +6,8 @@ import { EuiConfirmModal, EUI_MODAL_CONFIRM_BUTTON } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n/react'; -import React from 'react'; +import React, { useCallback } from 'react'; +import { isEmpty } from 'lodash/fp'; import * as i18n from '../translations'; @@ -21,27 +22,34 @@ export const DELETE_TIMELINE_MODAL_WIDTH = 600; // px /** * Renders a modal that confirms deletion of a timeline */ -export const DeleteTimelineModal = React.memo(({ title, closeModal, onDelete }) => ( - (({ title, closeModal, onDelete }) => { + const getTitle = useCallback(() => { + const trimmedTitle = title != null ? title.trim() : ''; + const titleResult = !isEmpty(trimmedTitle) ? trimmedTitle : i18n.UNTITLED_TIMELINE; + return ( 0 ? title.trim() : i18n.UNTITLED_TIMELINE, + title: titleResult, }} /> - } - onCancel={closeModal} - onConfirm={onDelete} - cancelButtonText={i18n.CANCEL} - confirmButtonText={i18n.DELETE} - buttonColor="danger" - defaultFocusedButton={EUI_MODAL_CONFIRM_BUTTON} - > -
{i18n.DELETE_WARNING}
-
-)); + ); + }, [title]); + return ( + +
{i18n.DELETE_WARNING}
+
+ ); +}); DeleteTimelineModal.displayName = 'DeleteTimelineModal'; diff --git a/x-pack/legacy/plugins/siem/public/components/open_timeline/delete_timeline_modal/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/open_timeline/delete_timeline_modal/index.test.tsx index a3c5371435e52c..6e0ba5ebe24256 100644 --- a/x-pack/legacy/plugins/siem/public/components/open_timeline/delete_timeline_modal/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/open_timeline/delete_timeline_modal/index.test.tsx @@ -4,114 +4,54 @@ * you may not use this file except in compliance with the Elastic License. */ -import { EuiButtonIconProps } from '@elastic/eui'; import { mountWithIntl } from 'test_utils/enzyme_helpers'; import React from 'react'; -import { DeleteTimelineModalButton } from '.'; +import { DeleteTimelineModalOverlay } from '.'; describe('DeleteTimelineModal', () => { const savedObjectId = 'abcd'; + const defaultProps = { + closeModal: jest.fn(), + deleteTimelines: jest.fn(), + isModalOpen: true, + savedObjectIds: [savedObjectId], + title: 'Privilege Escalation', + }; describe('showModalState', () => { - test('it disables the delete icon if deleteTimelines is not provided', () => { - const wrapper = mountWithIntl( - - ); + test('it does NOT render the modal when isModalOpen is false', () => { + const testProps = { + ...defaultProps, + isModalOpen: false, + }; + const wrapper = mountWithIntl(); - const props = wrapper - .find('[data-test-subj="delete-timeline"]') - .first() - .props() as EuiButtonIconProps; - - expect(props.isDisabled).toBe(true); - }); - - test('it disables the delete icon if savedObjectId is null', () => { - const wrapper = mountWithIntl( - - ); - - const props = wrapper - .find('[data-test-subj="delete-timeline"]') - .first() - .props() as EuiButtonIconProps; - - expect(props.isDisabled).toBe(true); - }); - - test('it disables the delete icon if savedObjectId is an empty string', () => { - const wrapper = mountWithIntl( - - ); - - const props = wrapper - .find('[data-test-subj="delete-timeline"]') - .first() - .props() as EuiButtonIconProps; - - expect(props.isDisabled).toBe(true); - }); - - test('it enables the delete icon if savedObjectId is NOT an empty string', () => { - const wrapper = mountWithIntl( - - ); - - const props = wrapper - .find('[data-test-subj="delete-timeline"]') - .first() - .props() as EuiButtonIconProps; - - expect(props.isDisabled).toBe(false); + expect( + wrapper + .find('[data-test-subj="delete-timeline-modal"]') + .first() + .exists() + ).toBe(false); }); - test('it does NOT render the modal when showModal is false', () => { - const wrapper = mountWithIntl( - - ); + test('it renders the modal when isModalOpen is true', () => { + const wrapper = mountWithIntl(); expect( wrapper .find('[data-test-subj="delete-timeline-modal"]') .first() .exists() - ).toBe(false); + ).toBe(true); }); - test('it renders the modal when showModal is clicked', () => { - const wrapper = mountWithIntl( - - ); - - wrapper - .find('[data-test-subj="delete-timeline"]') - .first() - .simulate('click'); + test('it hides popover when isModalOpen is true', () => { + const wrapper = mountWithIntl(); expect( wrapper - .find('[data-test-subj="delete-timeline-modal"]') + .find('[data-test-subj="remove-popover"]') .first() .exists() ).toBe(true); diff --git a/x-pack/legacy/plugins/siem/public/components/open_timeline/delete_timeline_modal/index.tsx b/x-pack/legacy/plugins/siem/public/components/open_timeline/delete_timeline_modal/index.tsx index 982937659c0aaf..df01ebacb1f936 100644 --- a/x-pack/legacy/plugins/siem/public/components/open_timeline/delete_timeline_modal/index.tsx +++ b/x-pack/legacy/plugins/siem/public/components/open_timeline/delete_timeline_modal/index.tsx @@ -4,58 +4,54 @@ * you may not use this file except in compliance with the Elastic License. */ -import { EuiButtonIcon, EuiModal, EuiToolTip, EuiOverlayMask } from '@elastic/eui'; -import React, { useCallback, useState } from 'react'; +import { EuiModal, EuiOverlayMask } from '@elastic/eui'; +import React, { useCallback } from 'react'; +import { createGlobalStyle } from 'styled-components'; import { DeleteTimelineModal, DELETE_TIMELINE_MODAL_WIDTH } from './delete_timeline_modal'; -import * as i18n from '../translations'; import { DeleteTimelines } from '../types'; +const RemovePopover = createGlobalStyle` +div.euiPopover__panel-isOpen { + display: none; +} +`; interface Props { - deleteTimelines?: DeleteTimelines; - savedObjectId?: string | null; - title?: string | null; + deleteTimelines: DeleteTimelines; + onComplete?: () => void; + isModalOpen: boolean; + savedObjectIds: string[]; + title: string | null; } /** * Renders a button that when clicked, displays the `Delete Timeline` modal */ -export const DeleteTimelineModalButton = React.memo( - ({ deleteTimelines, savedObjectId, title }) => { - const [showModal, setShowModal] = useState(false); - - const openModal = useCallback(() => setShowModal(true), [setShowModal]); - const closeModal = useCallback(() => setShowModal(false), [setShowModal]); - +export const DeleteTimelineModalOverlay = React.memo( + ({ deleteTimelines, isModalOpen, savedObjectIds, title, onComplete }) => { + const internalCloseModal = useCallback(() => { + if (onComplete != null) { + onComplete(); + } + }, [onComplete]); const onDelete = useCallback(() => { - if (deleteTimelines != null && savedObjectId != null) { - deleteTimelines([savedObjectId]); + if (savedObjectIds != null) { + deleteTimelines(savedObjectIds); } - closeModal(); - }, [deleteTimelines, savedObjectId, closeModal]); - + if (onComplete != null) { + onComplete(); + } + }, [deleteTimelines, savedObjectIds, onComplete]); return ( <> - - - - - {showModal ? ( + {isModalOpen && } + {isModalOpen ? ( - + @@ -64,5 +60,4 @@ export const DeleteTimelineModalButton = React.memo( ); } ); - -DeleteTimelineModalButton.displayName = 'DeleteTimelineModalButton'; +DeleteTimelineModalOverlay.displayName = 'DeleteTimelineModalOverlay'; diff --git a/x-pack/legacy/plugins/siem/public/components/open_timeline/edit_timeline_actions.tsx b/x-pack/legacy/plugins/siem/public/components/open_timeline/edit_timeline_actions.tsx new file mode 100644 index 00000000000000..112e73a47ce7df --- /dev/null +++ b/x-pack/legacy/plugins/siem/public/components/open_timeline/edit_timeline_actions.tsx @@ -0,0 +1,58 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { useState, useCallback } from 'react'; +import { OpenTimelineResult } from './types'; + +export const useEditTimelineActions = () => { + const [actionItem, setActionTimeline] = useState(null); + const [isDeleteTimelineModalOpen, setIsDeleteTimelineModalOpen] = useState(false); + const [isEnableDownloader, setIsEnableDownloader] = useState(false); + + // Handle Delete Modal + const onCloseDeleteTimelineModal = useCallback(() => { + setIsDeleteTimelineModalOpen(false); + setActionTimeline(null); + }, [actionItem]); + + const onOpenDeleteTimelineModal = useCallback((selectedActionItem?: OpenTimelineResult) => { + setIsDeleteTimelineModalOpen(true); + if (selectedActionItem != null) { + setActionTimeline(selectedActionItem); + } + }, []); + + // Handle Downloader Modal + const enableExportTimelineDownloader = useCallback((selectedActionItem?: OpenTimelineResult) => { + setIsEnableDownloader(true); + if (selectedActionItem != null) { + setActionTimeline(selectedActionItem); + } + }, []); + + const disableExportTimelineDownloader = useCallback(() => { + setIsEnableDownloader(false); + setActionTimeline(null); + }, []); + + // On Compete every tasks + const onCompleteEditTimelineAction = useCallback(() => { + setIsDeleteTimelineModalOpen(false); + setIsEnableDownloader(false); + setActionTimeline(null); + }, []); + + return { + actionItem, + onCompleteEditTimelineAction, + isDeleteTimelineModalOpen, + onCloseDeleteTimelineModal, + onOpenDeleteTimelineModal, + isEnableDownloader, + enableExportTimelineDownloader, + disableExportTimelineDownloader, + }; +}; diff --git a/x-pack/legacy/plugins/siem/public/components/open_timeline/edit_timeline_batch_actions.tsx b/x-pack/legacy/plugins/siem/public/components/open_timeline/edit_timeline_batch_actions.tsx new file mode 100644 index 00000000000000..74b9a8cad98dc9 --- /dev/null +++ b/x-pack/legacy/plugins/siem/public/components/open_timeline/edit_timeline_batch_actions.tsx @@ -0,0 +1,116 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { EuiContextMenuPanel, EuiContextMenuItem, EuiBasicTable } from '@elastic/eui'; +import React, { useCallback, useMemo } from 'react'; +import { isEmpty } from 'lodash/fp'; +import * as i18n from './translations'; +import { DeleteTimelines, OpenTimelineResult } from './types'; +import { EditTimelineActions } from './export_timeline'; +import { useEditTimelineActions } from './edit_timeline_actions'; + +const getExportedIds = (selectedTimelines: OpenTimelineResult[]) => { + const array = Array.isArray(selectedTimelines) ? selectedTimelines : [selectedTimelines]; + return array.reduce( + (acc, item) => (item.savedObjectId != null ? [...acc, item.savedObjectId] : [...acc]), + [] as string[] + ); +}; + +export const useEditTimelinBatchActions = ({ + deleteTimelines, + selectedItems, + tableRef, +}: { + deleteTimelines?: DeleteTimelines; + selectedItems?: OpenTimelineResult[]; + tableRef: React.MutableRefObject | undefined>; +}) => { + const { + enableExportTimelineDownloader, + disableExportTimelineDownloader, + isEnableDownloader, + isDeleteTimelineModalOpen, + onOpenDeleteTimelineModal, + onCloseDeleteTimelineModal, + } = useEditTimelineActions(); + + const onCompleteBatchActions = useCallback( + (closePopover?: () => void) => { + if (closePopover != null) closePopover(); + if (tableRef != null && tableRef.current != null) { + tableRef.current.changeSelection([]); + } + disableExportTimelineDownloader(); + onCloseDeleteTimelineModal(); + }, + [disableExportTimelineDownloader, onCloseDeleteTimelineModal, tableRef.current] + ); + + const selectedIds = useMemo(() => getExportedIds(selectedItems ?? []), [selectedItems]); + + const handleEnableExportTimelineDownloader = useCallback(() => enableExportTimelineDownloader(), [ + enableExportTimelineDownloader, + ]); + + const handleOnOpenDeleteTimelineModal = useCallback(() => onOpenDeleteTimelineModal(), [ + onOpenDeleteTimelineModal, + ]); + + const getBatchItemsPopoverContent = useCallback( + (closePopover: () => void) => { + const isDisabled = isEmpty(selectedItems); + return ( + <> + + + + {i18n.EXPORT_SELECTED} + , + + {i18n.DELETE_SELECTED} + , + ]} + /> + + ); + }, + [ + deleteTimelines, + isEnableDownloader, + isDeleteTimelineModalOpen, + selectedIds, + selectedItems, + handleEnableExportTimelineDownloader, + handleOnOpenDeleteTimelineModal, + onCompleteBatchActions, + ] + ); + return { onCompleteBatchActions, getBatchItemsPopoverContent }; +}; diff --git a/x-pack/legacy/plugins/siem/public/components/open_timeline/export_timeline/export_timeline.test.tsx b/x-pack/legacy/plugins/siem/public/components/open_timeline/export_timeline/export_timeline.test.tsx new file mode 100644 index 00000000000000..d377b10a55c213 --- /dev/null +++ b/x-pack/legacy/plugins/siem/public/components/open_timeline/export_timeline/export_timeline.test.tsx @@ -0,0 +1,90 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import React from 'react'; +import { TimelineDownloader } from './export_timeline'; +import { mockSelectedTimeline } from './mocks'; +import { ReactWrapper, mount } from 'enzyme'; +import { useExportTimeline } from '.'; + +jest.mock('../translations', () => { + return { + EXPORT_SELECTED: 'EXPORT_SELECTED', + EXPORT_FILENAME: 'TIMELINE', + }; +}); + +jest.mock('.', () => { + return { + useExportTimeline: jest.fn(), + }; +}); + +describe('TimelineDownloader', () => { + let wrapper: ReactWrapper; + const defaultTestProps = { + exportedIds: ['baa20980-6301-11ea-9223-95b6d4dd806c'], + getExportedData: jest.fn(), + isEnableDownloader: true, + onComplete: jest.fn(), + }; + describe('should not render a downloader', () => { + beforeAll(() => { + ((useExportTimeline as unknown) as jest.Mock).mockReturnValue({ + enableDownloader: false, + setEnableDownloader: jest.fn(), + exportedIds: {}, + getExportedData: jest.fn(), + }); + }); + + afterAll(() => { + ((useExportTimeline as unknown) as jest.Mock).mockReset(); + }); + + test('Without exportedIds', () => { + const testProps = { + ...defaultTestProps, + exportedIds: undefined, + }; + wrapper = mount(); + expect(wrapper.find('[data-test-subj="export-timeline-downloader"]').exists()).toBeFalsy(); + }); + + test('With isEnableDownloader is false', () => { + const testProps = { + ...defaultTestProps, + isEnableDownloader: false, + }; + wrapper = mount(); + expect(wrapper.find('[data-test-subj="export-timeline-downloader"]').exists()).toBeFalsy(); + }); + }); + + describe('should render a downloader', () => { + beforeAll(() => { + ((useExportTimeline as unknown) as jest.Mock).mockReturnValue({ + enableDownloader: false, + setEnableDownloader: jest.fn(), + exportedIds: {}, + getExportedData: jest.fn(), + }); + }); + + afterAll(() => { + ((useExportTimeline as unknown) as jest.Mock).mockReset(); + }); + + test('With selectedItems and exportedIds is given and isEnableDownloader is true', () => { + const testProps = { + ...defaultTestProps, + selectedItems: mockSelectedTimeline, + }; + wrapper = mount(); + expect(wrapper.find('[data-test-subj="export-timeline-downloader"]').exists()).toBeTruthy(); + }); + }); +}); diff --git a/x-pack/legacy/plugins/siem/public/components/open_timeline/export_timeline/export_timeline.tsx b/x-pack/legacy/plugins/siem/public/components/open_timeline/export_timeline/export_timeline.tsx new file mode 100644 index 00000000000000..ebfd5c18bd5dc2 --- /dev/null +++ b/x-pack/legacy/plugins/siem/public/components/open_timeline/export_timeline/export_timeline.tsx @@ -0,0 +1,59 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import React, { useCallback } from 'react'; +import uuid from 'uuid'; +import { GenericDownloader, ExportSelectedData } from '../../generic_downloader'; +import * as i18n from '../translations'; +import { useStateToaster } from '../../toasters'; + +const ExportTimeline: React.FC<{ + exportedIds: string[] | undefined; + getExportedData: ExportSelectedData; + isEnableDownloader: boolean; + onComplete?: () => void; +}> = ({ onComplete, isEnableDownloader, exportedIds, getExportedData }) => { + const [, dispatchToaster] = useStateToaster(); + const onExportSuccess = useCallback( + exportCount => { + if (onComplete != null) { + onComplete(); + } + dispatchToaster({ + type: 'addToaster', + toast: { + id: uuid.v4(), + title: i18n.SUCCESSFULLY_EXPORTED_TIMELINES(exportCount), + color: 'success', + iconType: 'check', + }, + }); + }, + [dispatchToaster, onComplete] + ); + const onExportFailure = useCallback(() => { + if (onComplete != null) { + onComplete(); + } + }, [onComplete]); + + return ( + <> + {exportedIds != null && isEnableDownloader && ( + + )} + + ); +}; +ExportTimeline.displayName = 'ExportTimeline'; +export const TimelineDownloader = React.memo(ExportTimeline); diff --git a/x-pack/legacy/plugins/siem/public/components/open_timeline/export_timeline/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/open_timeline/export_timeline/index.test.tsx new file mode 100644 index 00000000000000..674cd6dad5f76f --- /dev/null +++ b/x-pack/legacy/plugins/siem/public/components/open_timeline/export_timeline/index.test.tsx @@ -0,0 +1,35 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import React from 'react'; +import { mount } from 'enzyme'; +import { useExportTimeline, ExportTimeline } from '.'; + +describe('useExportTimeline', () => { + describe('call with selected timelines', () => { + let exportTimelineRes: ExportTimeline; + const TestHook = () => { + exportTimelineRes = useExportTimeline(); + return
; + }; + + beforeAll(() => { + mount(); + }); + + test('Downloader should be disabled by default', () => { + expect(exportTimelineRes.isEnableDownloader).toBeFalsy(); + }); + + test('Should include disableExportTimelineDownloader in return value', () => { + expect(exportTimelineRes).toHaveProperty('disableExportTimelineDownloader'); + }); + + test('Should include enableExportTimelineDownloader in return value', () => { + expect(exportTimelineRes).toHaveProperty('enableExportTimelineDownloader'); + }); + }); +}); diff --git a/x-pack/legacy/plugins/siem/public/components/open_timeline/export_timeline/index.tsx b/x-pack/legacy/plugins/siem/public/components/open_timeline/export_timeline/index.tsx new file mode 100644 index 00000000000000..946c4b3a612dd1 --- /dev/null +++ b/x-pack/legacy/plugins/siem/public/components/open_timeline/export_timeline/index.tsx @@ -0,0 +1,73 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import React, { useState, useCallback } from 'react'; +import { DeleteTimelines } from '../types'; + +import { TimelineDownloader } from './export_timeline'; +import { DeleteTimelineModalOverlay } from '../delete_timeline_modal'; +import { exportSelectedTimeline } from '../../../containers/timeline/all/api'; + +export interface ExportTimeline { + disableExportTimelineDownloader: () => void; + enableExportTimelineDownloader: () => void; + isEnableDownloader: boolean; +} + +export const useExportTimeline = (): ExportTimeline => { + const [isEnableDownloader, setIsEnableDownloader] = useState(false); + + const enableExportTimelineDownloader = useCallback(() => { + setIsEnableDownloader(true); + }, []); + + const disableExportTimelineDownloader = useCallback(() => { + setIsEnableDownloader(false); + }, []); + + return { + disableExportTimelineDownloader, + enableExportTimelineDownloader, + isEnableDownloader, + }; +}; + +const EditTimelineActionsComponent: React.FC<{ + deleteTimelines: DeleteTimelines | undefined; + ids: string[]; + isEnableDownloader: boolean; + isDeleteTimelineModalOpen: boolean; + onComplete: () => void; + title: string; +}> = ({ + deleteTimelines, + ids, + isEnableDownloader, + isDeleteTimelineModalOpen, + onComplete, + title, +}) => ( + <> + + {deleteTimelines != null && ( + + )} + +); + +export const EditTimelineActions = React.memo(EditTimelineActionsComponent); +export const EditOneTimelineAction = React.memo(EditTimelineActionsComponent); diff --git a/x-pack/legacy/plugins/siem/public/components/open_timeline/export_timeline/mocks.ts b/x-pack/legacy/plugins/siem/public/components/open_timeline/export_timeline/mocks.ts new file mode 100644 index 00000000000000..34d763839003c6 --- /dev/null +++ b/x-pack/legacy/plugins/siem/public/components/open_timeline/export_timeline/mocks.ts @@ -0,0 +1,99 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export const mockSelectedTimeline = [ + { + savedObjectId: 'baa20980-6301-11ea-9223-95b6d4dd806c', + version: 'WzExNzAsMV0=', + columns: [ + { + columnHeaderType: 'not-filtered', + indexes: null, + id: '@timestamp', + name: null, + searchable: null, + }, + { + columnHeaderType: 'not-filtered', + indexes: null, + id: 'message', + name: null, + searchable: null, + }, + { + columnHeaderType: 'not-filtered', + indexes: null, + id: 'event.category', + name: null, + searchable: null, + }, + { + columnHeaderType: 'not-filtered', + indexes: null, + id: 'event.action', + name: null, + searchable: null, + }, + { + columnHeaderType: 'not-filtered', + indexes: null, + id: 'host.name', + name: null, + searchable: null, + }, + { + columnHeaderType: 'not-filtered', + indexes: null, + id: 'source.ip', + name: null, + searchable: null, + }, + { + columnHeaderType: 'not-filtered', + indexes: null, + id: 'destination.ip', + name: null, + searchable: null, + }, + { + columnHeaderType: 'not-filtered', + indexes: null, + id: 'user.name', + name: null, + searchable: null, + }, + ], + dataProviders: [], + description: 'with a global note', + eventType: 'raw', + filters: [], + kqlMode: 'filter', + kqlQuery: { + filterQuery: { + kuery: { kind: 'kuery', expression: 'zeek.files.sha1 : * ' }, + serializedQuery: + '{"bool":{"should":[{"exists":{"field":"zeek.files.sha1"}}],"minimum_should_match":1}}', + }, + }, + title: 'duplicate timeline', + dateRange: { start: 1582538951145, end: 1582625351145 }, + savedQueryId: null, + sort: { columnId: '@timestamp', sortDirection: 'desc' }, + created: 1583866966262, + createdBy: 'elastic', + updated: 1583866966262, + updatedBy: 'elastic', + notes: [ + { + noteId: 'noteIdOne', + }, + { + noteId: 'noteIdTwo', + }, + ], + pinnedEventIds: { '23D_e3ABGy2SlgJPuyEh': true, eHD_e3ABGy2SlgJPsh4u: true }, + }, +]; diff --git a/x-pack/legacy/plugins/siem/public/components/open_timeline/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/open_timeline/index.test.tsx index 520e2094fb3364..04f0abe0d00d17 100644 --- a/x-pack/legacy/plugins/siem/public/components/open_timeline/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/open_timeline/index.test.tsx @@ -526,11 +526,6 @@ describe('StatefulOpenTimeline', () => { .first() .simulate('change', { target: { checked: true } }); expect(getSelectedItem().length).toEqual(13); - wrapper - .find('[data-test-subj="delete-selected"]') - .first() - .simulate('click'); - expect(getSelectedItem().length).toEqual(0); }); }); diff --git a/x-pack/legacy/plugins/siem/public/components/open_timeline/index.tsx b/x-pack/legacy/plugins/siem/public/components/open_timeline/index.tsx index 26a7487fee52b5..6d00edf28a88f9 100644 --- a/x-pack/legacy/plugins/siem/public/components/open_timeline/index.tsx +++ b/x-pack/legacy/plugins/siem/public/components/open_timeline/index.tsx @@ -256,7 +256,7 @@ export const StatefulOpenTimelineComponent = React.memo( sort={{ sortField: sortField as SortFieldTimeline, sortOrder: sortDirection as Direction }} onlyUserFavorite={onlyFavorites} > - {({ timelines, loading, totalCount }) => { + {({ timelines, loading, totalCount, refetch }) => { return !isModal ? ( ( pageIndex={pageIndex} pageSize={pageSize} query={search} + refetch={refetch} searchResults={timelines} selectedItems={selectedItems} sortDirection={sortDirection} diff --git a/x-pack/legacy/plugins/siem/public/components/open_timeline/open_timeline.test.tsx b/x-pack/legacy/plugins/siem/public/components/open_timeline/open_timeline.test.tsx index a1ca7812bba340..e010d54d711c3e 100644 --- a/x-pack/legacy/plugins/siem/public/components/open_timeline/open_timeline.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/open_timeline/open_timeline.test.tsx @@ -290,4 +290,270 @@ describe('OpenTimeline', () => { expect(props.actionTimelineToShow).not.toContain('delete'); }); + + test('it renders an empty string when the query is an empty string', () => { + const wrapper = mountWithIntl( + + + + ); + + expect( + wrapper + .find('[data-test-subj="selectable-query-text"]') + .first() + .text() + ).toEqual(''); + }); + + test('it renders the expected message when the query just has spaces', () => { + const wrapper = mountWithIntl( + + + + ); + + expect( + wrapper + .find('[data-test-subj="selectable-query-text"]') + .first() + .text() + ).toEqual(''); + }); + + test('it echos the query when the query has non-whitespace characters', () => { + const wrapper = mountWithIntl( + + + + ); + + expect( + wrapper + .find('[data-test-subj="selectable-query-text"]') + .first() + .text() + ).toContain('Would you like to go to Denver?'); + }); + + test('trims whitespace from the ends of the query', () => { + const wrapper = mountWithIntl( + + + + ); + + expect( + wrapper + .find('[data-test-subj="selectable-query-text"]') + .first() + .text() + ).toContain('Is it starting to feel cramped in here?'); + }); + + test('it renders the expected message when the query is an empty string', () => { + const wrapper = mountWithIntl( + + + + ); + + expect( + wrapper + .find('[data-test-subj="query-message"]') + .first() + .text() + ).toContain(`Showing: ${mockResults.length} timelines `); + }); + + test('it renders the expected message when the query just has whitespace', () => { + const wrapper = mountWithIntl( + + + + ); + + expect( + wrapper + .find('[data-test-subj="query-message"]') + .first() + .text() + ).toContain(`Showing: ${mockResults.length} timelines `); + }); + + test('it includes the word "with" when the query has non-whitespace characters', () => { + const wrapper = mountWithIntl( + + + + ); + + expect( + wrapper + .find('[data-test-subj="query-message"]') + .first() + .text() + ).toContain(`Showing: ${mockResults.length} timelines with "How was your day?"`); + }); }); diff --git a/x-pack/legacy/plugins/siem/public/components/open_timeline/open_timeline.tsx b/x-pack/legacy/plugins/siem/public/components/open_timeline/open_timeline.tsx index 8aab02b495392f..b1b100349eb86f 100644 --- a/x-pack/legacy/plugins/siem/public/components/open_timeline/open_timeline.tsx +++ b/x-pack/legacy/plugins/siem/public/components/open_timeline/open_timeline.tsx @@ -4,15 +4,27 @@ * you may not use this file except in compliance with the Elastic License. */ -import { EuiPanel } from '@elastic/eui'; -import React from 'react'; - +import { EuiPanel, EuiBasicTable } from '@elastic/eui'; +import React, { useCallback, useMemo, useRef } from 'react'; +import { FormattedMessage } from '@kbn/i18n/react'; import { OPEN_TIMELINE_CLASS_NAME } from './helpers'; -import { OpenTimelineProps } from './types'; +import { OpenTimelineProps, OpenTimelineResult } from './types'; import { SearchRow } from './search_row'; import { TimelinesTable } from './timelines_table'; import { TitleRow } from './title_row'; +import * as i18n from './translations'; +import { + UtilityBarGroup, + UtilityBarText, + UtilityBar, + UtilityBarSection, + UtilityBarAction, +} from '../utility_bar'; +import { useEditTimelinBatchActions } from './edit_timeline_batch_actions'; +import { useEditTimelineActions } from './edit_timeline_actions'; +import { EditOneTimelineAction } from './export_timeline'; + export const OpenTimeline = React.memo( ({ deleteTimelines, @@ -31,56 +43,145 @@ export const OpenTimeline = React.memo( pageIndex, pageSize, query, + refetch, searchResults, selectedItems, sortDirection, sortField, title, totalSearchResultsCount, - }) => ( - - + }) => { + const tableRef = useRef>(); + + const { + actionItem, + enableExportTimelineDownloader, + isEnableDownloader, + isDeleteTimelineModalOpen, + onOpenDeleteTimelineModal, + onCompleteEditTimelineAction, + } = useEditTimelineActions(); + + const { getBatchItemsPopoverContent } = useEditTimelinBatchActions({ + deleteTimelines, + selectedItems, + tableRef, + }); + + const nTimelines = useMemo( + () => ( + + {query.trim().length ? `${i18n.WITH} "${query.trim()}"` : ''} + + ), + }} + /> + ), + [totalSearchResultsCount, query] + ); + + const actionItemId = useMemo( + () => + actionItem != null && actionItem.savedObjectId != null ? [actionItem.savedObjectId] : [], + [actionItem] + ); + + const onRefreshBtnClick = useCallback(() => { + if (typeof refetch === 'function') refetch(); + }, [refetch]); + + return ( + <> + + + + + + + + + + + + <> + {i18n.SHOWING} {nTimelines} + + + - + + {i18n.SELECTED_TIMELINES(selectedItems.length)} + + {i18n.BATCH_ACTIONS} + + + {i18n.REFRESH} + + + + - - - ) + + onDeleteSelected != null && deleteTimelines != null + ? ['delete', 'duplicate', 'export', 'selectable'] + : ['duplicate', 'export', 'selectable'], + [onDeleteSelected, deleteTimelines] + )} + data-test-subj="timelines-table" + deleteTimelines={deleteTimelines} + defaultPageSize={defaultPageSize} + loading={isLoading} + itemIdToExpandedNotesRowMap={itemIdToExpandedNotesRowMap} + enableExportTimelineDownloader={enableExportTimelineDownloader} + onOpenDeleteTimelineModal={onOpenDeleteTimelineModal} + onOpenTimeline={onOpenTimeline} + onSelectionChange={onSelectionChange} + onTableChange={onTableChange} + onToggleShowNotes={onToggleShowNotes} + pageIndex={pageIndex} + pageSize={pageSize} + searchResults={searchResults} + showExtendedColumns={true} + sortDirection={sortDirection} + sortField={sortField} + tableRef={tableRef} + totalSearchResultsCount={totalSearchResultsCount} + /> + + + ); + } ); OpenTimeline.displayName = 'OpenTimeline'; diff --git a/x-pack/legacy/plugins/siem/public/components/open_timeline/open_timeline_modal/open_timeline_modal_body.tsx b/x-pack/legacy/plugins/siem/public/components/open_timeline/open_timeline_modal/open_timeline_modal_body.tsx index dcd0b377705830..60ebf2118d556f 100644 --- a/x-pack/legacy/plugins/siem/public/components/open_timeline/open_timeline_modal/open_timeline_modal_body.tsx +++ b/x-pack/legacy/plugins/siem/public/components/open_timeline/open_timeline_modal/open_timeline_modal_body.tsx @@ -58,7 +58,6 @@ export const OpenTimelineModalBody = memo( { expect(onQueryChange).toHaveBeenCalled(); }); }); - - describe('Showing message', () => { - test('it renders the expected message when the query is an empty string', () => { - const wrapper = mountWithIntl( - - - - ); - - expect( - wrapper - .find('[data-test-subj="query-message"]') - .first() - .text() - ).toContain('Showing: 32 timelines '); - }); - - test('it renders the expected message when the query just has whitespace', () => { - const wrapper = mountWithIntl( - - - - ); - - expect( - wrapper - .find('[data-test-subj="query-message"]') - .first() - .text() - ).toContain('Showing: 32 timelines '); - }); - - test('it includes the word "with" when the query has non-whitespace characters', () => { - const wrapper = mountWithIntl( - - - - ); - - expect( - wrapper - .find('[data-test-subj="query-message"]') - .first() - .text() - ).toContain('Showing: 32 timelines with'); - }); - }); - - describe('selectable query text', () => { - test('it renders an empty string when the query is an empty string', () => { - const wrapper = mountWithIntl( - - - - ); - - expect( - wrapper - .find('[data-test-subj="selectable-query-text"]') - .first() - .text() - ).toEqual(''); - }); - - test('it renders the expected message when the query just has spaces', () => { - const wrapper = mountWithIntl( - - - - ); - - expect( - wrapper - .find('[data-test-subj="selectable-query-text"]') - .first() - .text() - ).toEqual(''); - }); - - test('it echos the query when the query has non-whitespace characters', () => { - const wrapper = mountWithIntl( - - - - ); - - expect( - wrapper - .find('[data-test-subj="selectable-query-text"]') - .first() - .text() - ).toContain('Would you like to go to Denver?'); - }); - - test('trims whitespace from the ends of the query', () => { - const wrapper = mountWithIntl( - - - - ); - - expect( - wrapper - .find('[data-test-subj="selectable-query-text"]') - .first() - .text() - ).toContain('Is it starting to feel cramped in here?'); - }); - }); }); diff --git a/x-pack/legacy/plugins/siem/public/components/open_timeline/search_row/index.tsx b/x-pack/legacy/plugins/siem/public/components/open_timeline/search_row/index.tsx index 5765d31078bcf7..55fce1f1c1ed07 100644 --- a/x-pack/legacy/plugins/siem/public/components/open_timeline/search_row/index.tsx +++ b/x-pack/legacy/plugins/siem/public/components/open_timeline/search_row/index.tsx @@ -11,9 +11,7 @@ import { EuiFlexItem, // @ts-ignore EuiSearchBar, - EuiText, } from '@elastic/eui'; -import { FormattedMessage } from '@kbn/i18n/react'; import React from 'react'; import styled from 'styled-components'; @@ -39,56 +37,38 @@ type Props = Pick< 'onlyFavorites' | 'onQueryChange' | 'onToggleOnlyFavorites' | 'query' | 'totalSearchResultsCount' >; +const searchBox = { + placeholder: i18n.SEARCH_PLACEHOLDER, + incremental: false, +}; + /** * Renders the row containing the search input and Only Favorites filter */ export const SearchRow = React.memo( - ({ onlyFavorites, onQueryChange, onToggleOnlyFavorites, query, totalSearchResultsCount }) => ( - - - - - - - - - - {i18n.ONLY_FAVORITES} - - - - + ({ onlyFavorites, onQueryChange, onToggleOnlyFavorites, query, totalSearchResultsCount }) => { + return ( + + + + + - -

- - {query.trim().length ? `${i18n.WITH} "${query.trim()}"` : ''} - - ), - }} - /> -

-
-
- ) + + + + {i18n.ONLY_FAVORITES} + + + + +
+ ); + } ); SearchRow.displayName = 'SearchRow'; diff --git a/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/actions_columns.test.tsx b/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/actions_columns.test.tsx index eec11f571328f5..ca82e30798d824 100644 --- a/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/actions_columns.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/actions_columns.test.tsx @@ -11,14 +11,15 @@ import { mountWithIntl } from 'test_utils/enzyme_helpers'; import React from 'react'; import { ThemeProvider } from 'styled-components'; -import { DEFAULT_SEARCH_RESULTS_PER_PAGE } from '../../../pages/timelines/timelines_page'; import { mockTimelineResults } from '../../../mock/timeline_results'; import { OpenTimelineResult } from '../types'; -import { TimelinesTable } from '.'; -import { DEFAULT_SORT_DIRECTION, DEFAULT_SORT_FIELD } from '../constants'; +import { TimelinesTableProps } from '.'; +import { getMockTimelinesTableProps } from './mocks'; jest.mock('../../../lib/kibana'); +const { TimelinesTable } = jest.requireActual('.'); + describe('#getActionsColumns', () => { const theme = () => ({ eui: euiDarkVars, darkMode: true }); let mockResults: OpenTimelineResult[]; @@ -28,26 +29,13 @@ describe('#getActionsColumns', () => { }); test('it renders the delete timeline (trash icon) when actionTimelineToShow is including the action delete', () => { + const testProps: TimelinesTableProps = { + ...getMockTimelinesTableProps(mockResults), + actionTimelineToShow: ['delete'], + }; const wrapper = mountWithIntl( - + ); @@ -55,26 +43,13 @@ describe('#getActionsColumns', () => { }); test('it does NOT render the delete timeline (trash icon) when actionTimelineToShow is NOT including the action delete', () => { + const testProps: TimelinesTableProps = { + ...getMockTimelinesTableProps(mockResults), + actionTimelineToShow: [], + }; const wrapper = mountWithIntl( - + ); @@ -82,26 +57,13 @@ describe('#getActionsColumns', () => { }); test('it renders the duplicate icon timeline when actionTimelineToShow is including the action duplicate', () => { + const testProps: TimelinesTableProps = { + ...getMockTimelinesTableProps(mockResults), + actionTimelineToShow: ['duplicate'], + }; const wrapper = mountWithIntl( - + ); @@ -109,26 +71,13 @@ describe('#getActionsColumns', () => { }); test('it does NOT render the duplicate timeline when actionTimelineToShow is NOT including the action duplicate)', () => { + const testProps: TimelinesTableProps = { + ...getMockTimelinesTableProps(mockResults), + actionTimelineToShow: [], + }; const wrapper = mountWithIntl( - + ); @@ -136,25 +85,13 @@ describe('#getActionsColumns', () => { }); test('it does NOT render the delete timeline (trash icon) when deleteTimelines is not provided', () => { + const testProps: TimelinesTableProps = { + ...omit('deleteTimelines', getMockTimelinesTableProps(mockResults)), + actionTimelineToShow: ['delete'], + }; const wrapper = mountWithIntl( - + ); @@ -166,56 +103,29 @@ describe('#getActionsColumns', () => { omit('savedObjectId', { ...mockResults[0] }), ]; + const testProps: TimelinesTableProps = { + ...getMockTimelinesTableProps(missingSavedObjectId), + }; const wrapper = mountWithIntl( - + + + ); const props = wrapper .find('[data-test-subj="open-duplicate"]') .first() .props() as EuiButtonIconProps; - expect(props.isDisabled).toBe(true); }); test('it renders an enabled the open duplicate button if the timeline has have a saved object id', () => { + const testProps: TimelinesTableProps = { + ...getMockTimelinesTableProps(mockResults), + }; const wrapper = mountWithIntl( - + ); @@ -229,27 +139,13 @@ describe('#getActionsColumns', () => { test('it invokes onOpenTimeline with the expected params when the button is clicked', () => { const onOpenTimeline = jest.fn(); - + const testProps: TimelinesTableProps = { + ...getMockTimelinesTableProps(mockResults), + onOpenTimeline, + }; const wrapper = mountWithIntl( - + ); diff --git a/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/actions_columns.tsx b/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/actions_columns.tsx index 2b8bd3339cca24..4bbf98dafe38df 100644 --- a/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/actions_columns.tsx +++ b/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/actions_columns.tsx @@ -6,76 +6,78 @@ /* eslint-disable react/display-name */ -import { EuiButtonIcon, EuiToolTip } from '@elastic/eui'; -import React from 'react'; - -import { ACTION_COLUMN_WIDTH } from './common_styles'; -import { DeleteTimelineModalButton } from '../delete_timeline_modal'; -import * as i18n from '../translations'; import { ActionTimelineToShow, DeleteTimelines, + EnableExportTimelineDownloader, OnOpenTimeline, OpenTimelineResult, + OnOpenDeleteTimelineModal, + TimelineActionsOverflowColumns, } from '../types'; +import * as i18n from '../translations'; /** * Returns the action columns (e.g. delete, open duplicate timeline) */ export const getActionsColumns = ({ actionTimelineToShow, - onOpenTimeline, deleteTimelines, + enableExportTimelineDownloader, + onOpenDeleteTimelineModal, + onOpenTimeline, }: { actionTimelineToShow: ActionTimelineToShow[]; deleteTimelines?: DeleteTimelines; + enableExportTimelineDownloader?: EnableExportTimelineDownloader; + onOpenDeleteTimelineModal?: OnOpenDeleteTimelineModal; onOpenTimeline: OnOpenTimeline; -}) => { +}): [TimelineActionsOverflowColumns] => { const openAsDuplicateColumn = { - align: 'center', - field: 'savedObjectId', - name: '', - render: (savedObjectId: string, timelineResult: OpenTimelineResult) => ( - - - onOpenTimeline({ - duplicate: true, - timelineId: `${timelineResult.savedObjectId}`, - }) - } - size="s" - /> - - ), - sortable: false, - width: ACTION_COLUMN_WIDTH, + name: i18n.OPEN_AS_DUPLICATE, + icon: 'copy', + onClick: ({ savedObjectId }: OpenTimelineResult) => { + onOpenTimeline({ + duplicate: true, + timelineId: savedObjectId ?? '', + }); + }, + enabled: ({ savedObjectId }: OpenTimelineResult) => savedObjectId != null, + description: i18n.OPEN_AS_DUPLICATE, + 'data-test-subj': 'open-duplicate', + }; + + const exportTimelineAction = { + name: i18n.EXPORT_SELECTED, + icon: 'exportAction', + onClick: (selectedTimeline: OpenTimelineResult) => { + if (enableExportTimelineDownloader != null) enableExportTimelineDownloader(selectedTimeline); + }, + enabled: ({ savedObjectId }: OpenTimelineResult) => savedObjectId != null, + description: i18n.EXPORT_SELECTED, }; const deleteTimelineColumn = { - align: 'center', - field: 'savedObjectId', - name: '', - render: (savedObjectId: string, { title }: OpenTimelineResult) => ( - - ), - sortable: false, - width: ACTION_COLUMN_WIDTH, + name: i18n.DELETE_SELECTED, + icon: 'trash', + onClick: (selectedTimeline: OpenTimelineResult) => { + if (onOpenDeleteTimelineModal != null) onOpenDeleteTimelineModal(selectedTimeline); + }, + enabled: ({ savedObjectId }: OpenTimelineResult) => savedObjectId != null, + description: i18n.DELETE_SELECTED, + 'data-test-subj': 'delete-timeline', }; return [ - actionTimelineToShow.includes('duplicate') ? openAsDuplicateColumn : null, - actionTimelineToShow.includes('delete') && deleteTimelines != null - ? deleteTimelineColumn - : null, - ].filter(action => action != null); + { + width: '40px', + actions: [ + actionTimelineToShow.includes('duplicate') ? openAsDuplicateColumn : null, + actionTimelineToShow.includes('export') ? exportTimelineAction : null, + actionTimelineToShow.includes('delete') && deleteTimelines != null + ? deleteTimelineColumn + : null, + ].filter(action => action != null), + }, + ]; }; diff --git a/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/common_columns.test.tsx b/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/common_columns.test.tsx index 0f2cda9d79f0b1..093e4a5bab1006 100644 --- a/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/common_columns.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/common_columns.test.tsx @@ -11,15 +11,14 @@ import React from 'react'; import { ThemeProvider } from 'styled-components'; import { mountWithIntl } from 'test_utils/enzyme_helpers'; -import { DEFAULT_SEARCH_RESULTS_PER_PAGE } from '../../../pages/timelines/timelines_page'; import { getEmptyValue } from '../../empty_value'; import { OpenTimelineResult } from '../types'; import { mockTimelineResults } from '../../../mock/timeline_results'; import { NotePreviews } from '../note_previews'; -import { TimelinesTable } from '.'; +import { TimelinesTable, TimelinesTableProps } from '.'; import * as i18n from '../translations'; -import { DEFAULT_SORT_DIRECTION, DEFAULT_SORT_FIELD } from '../constants'; +import { getMockTimelinesTableProps } from './mocks'; jest.mock('../../../lib/kibana'); @@ -35,25 +34,13 @@ describe('#getCommonColumns', () => { test('it renders the expand button when the timelineResult has notes', () => { const hasNotes: OpenTimelineResult[] = [{ ...mockResults[0] }]; + const testProps: TimelinesTableProps = { + ...getMockTimelinesTableProps(hasNotes), + }; const wrapper = mountWithIntl( - + + + ); expect(wrapper.find('[data-test-subj="expand-notes"]').exists()).toBe(true); @@ -62,25 +49,13 @@ describe('#getCommonColumns', () => { test('it does NOT render the expand button when the timelineResult notes are undefined', () => { const missingNotes: OpenTimelineResult[] = [omit('notes', { ...mockResults[0] })]; + const testProps: TimelinesTableProps = { + ...getMockTimelinesTableProps(missingNotes), + }; const wrapper = mountWithIntl( - + + + ); expect(wrapper.find('[data-test-subj="expand-notes"]').exists()).toBe(false); @@ -89,25 +64,13 @@ describe('#getCommonColumns', () => { test('it does NOT render the expand button when the timelineResult notes are null', () => { const nullNotes: OpenTimelineResult[] = [{ ...mockResults[0], notes: null }]; + const testProps: TimelinesTableProps = { + ...getMockTimelinesTableProps(nullNotes), + }; const wrapper = mountWithIntl( - + + + ); expect(wrapper.find('[data-test-subj="expand-notes"]').exists()).toBe(false); @@ -116,25 +79,13 @@ describe('#getCommonColumns', () => { test('it does NOT render the expand button when the notes are empty', () => { const emptylNotes: OpenTimelineResult[] = [{ ...mockResults[0], notes: [] }]; + const testProps: TimelinesTableProps = { + ...getMockTimelinesTableProps(emptylNotes), + }; const wrapper = mountWithIntl( - + + + ); expect(wrapper.find('[data-test-subj="expand-notes"]').exists()).toBe(false); @@ -144,26 +95,13 @@ describe('#getCommonColumns', () => { const missingSavedObjectId: OpenTimelineResult[] = [ omit('savedObjectId', { ...mockResults[0] }), ]; - + const testProps: TimelinesTableProps = { + ...getMockTimelinesTableProps(missingSavedObjectId), + }; const wrapper = mountWithIntl( - + + + ); expect(wrapper.find('[data-test-subj="expand-notes"]').exists()).toBe(false); @@ -172,25 +110,13 @@ describe('#getCommonColumns', () => { test('it does NOT render the expand button when the timelineResult savedObjectId is null', () => { const nullSavedObjectId: OpenTimelineResult[] = [{ ...mockResults[0], savedObjectId: null }]; + const testProps: TimelinesTableProps = { + ...getMockTimelinesTableProps(nullSavedObjectId), + }; const wrapper = mountWithIntl( - + + + ); expect(wrapper.find('[data-test-subj="expand-notes"]').exists()).toBe(false); @@ -199,25 +125,13 @@ describe('#getCommonColumns', () => { test('it renders the right arrow expander when the row is not expanded', () => { const hasNotes: OpenTimelineResult[] = [{ ...mockResults[0] }]; + const testProps: TimelinesTableProps = { + ...getMockTimelinesTableProps(hasNotes), + }; const wrapper = mountWithIntl( - + + + ); const props = wrapper @@ -235,26 +149,13 @@ describe('#getCommonColumns', () => { [mockResults[0].savedObjectId!]: , }; + const testProps: TimelinesTableProps = { + ...getMockTimelinesTableProps(hasNotes), + itemIdToExpandedNotesRowMap, + }; const wrapper = mountWithIntl( - + ); @@ -275,25 +176,15 @@ describe('#getCommonColumns', () => { abc:
, }; + const testProps: TimelinesTableProps = { + ...getMockTimelinesTableProps(hasNotes), + itemIdToExpandedNotesRowMap, + onToggleShowNotes, + }; const wrapper = mountWithIntl( - + + + ); wrapper @@ -317,26 +208,14 @@ describe('#getCommonColumns', () => { 'saved-timeline-11': , }; + const testProps: TimelinesTableProps = { + ...getMockTimelinesTableProps(hasNotes), + itemIdToExpandedNotesRowMap, + onToggleShowNotes, + }; const wrapper = mountWithIntl( - + ); @@ -353,26 +232,12 @@ describe('#getCommonColumns', () => { describe('Timeline Name column', () => { test('it renders the expected column name', () => { + const testProps: TimelinesTableProps = { + ...getMockTimelinesTableProps(mockResults), + }; const wrapper = mountWithIntl( - + ); @@ -385,26 +250,12 @@ describe('#getCommonColumns', () => { }); test('it renders the title when the timeline has a title and a saved object id', () => { + const testProps: TimelinesTableProps = { + ...getMockTimelinesTableProps(mockResults), + }; const wrapper = mountWithIntl( - + ); @@ -421,25 +272,13 @@ describe('#getCommonColumns', () => { omit('savedObjectId', { ...mockResults[0] }), ]; + const testProps: TimelinesTableProps = { + ...getMockTimelinesTableProps(missingSavedObjectId), + }; const wrapper = mountWithIntl( - + + + ); expect( @@ -453,25 +292,13 @@ describe('#getCommonColumns', () => { test('it renders an Untitled Timeline title when the timeline has no title and a saved object id', () => { const missingTitle: OpenTimelineResult[] = [omit('title', { ...mockResults[0] })]; + const testProps: TimelinesTableProps = { + ...getMockTimelinesTableProps(missingTitle), + }; const wrapper = mountWithIntl( - + + + ); expect( @@ -487,25 +314,13 @@ describe('#getCommonColumns', () => { omit(['title', 'savedObjectId'], { ...mockResults[0] }), ]; + const testProps: TimelinesTableProps = { + ...getMockTimelinesTableProps(withMissingSavedObjectIdAndTitle), + }; const wrapper = mountWithIntl( - + + + ); expect( @@ -521,25 +336,13 @@ describe('#getCommonColumns', () => { { ...mockResults[0], title: ' ' }, ]; + const testProps: TimelinesTableProps = { + ...getMockTimelinesTableProps(withJustWhitespaceTitle), + }; const wrapper = mountWithIntl( - + + + ); expect( @@ -555,25 +358,13 @@ describe('#getCommonColumns', () => { omit('savedObjectId', { ...mockResults[0], title: ' ' }), ]; + const testProps: TimelinesTableProps = { + ...getMockTimelinesTableProps(withMissingSavedObjectId), + }; const wrapper = mountWithIntl( - + + + ); expect( @@ -587,24 +378,7 @@ describe('#getCommonColumns', () => { test('it renders a hyperlink when the timeline has a saved object id', () => { const wrapper = mountWithIntl( - + ); @@ -621,25 +395,13 @@ describe('#getCommonColumns', () => { omit('savedObjectId', { ...mockResults[0] }), ]; + const testProps: TimelinesTableProps = { + ...getMockTimelinesTableProps(missingSavedObjectId), + }; const wrapper = mountWithIntl( - + + + ); expect( @@ -653,26 +415,13 @@ describe('#getCommonColumns', () => { test('it invokes `onOpenTimeline` when the hyperlink is clicked', () => { const onOpenTimeline = jest.fn(); + const testProps: TimelinesTableProps = { + ...getMockTimelinesTableProps(mockResults), + onOpenTimeline, + }; const wrapper = mountWithIntl( - + ); @@ -692,24 +441,7 @@ describe('#getCommonColumns', () => { test('it renders the expected column name', () => { const wrapper = mountWithIntl( - + ); @@ -724,24 +456,7 @@ describe('#getCommonColumns', () => { test('it renders the description when the timeline has a description', () => { const wrapper = mountWithIntl( - + ); @@ -758,24 +473,7 @@ describe('#getCommonColumns', () => { const wrapper = mountWithIntl( - + ); expect( @@ -791,26 +489,12 @@ describe('#getCommonColumns', () => { { ...mockResults[0], description: ' ' }, ]; + const testProps: TimelinesTableProps = { + ...getMockTimelinesTableProps(justWhitespaceDescription), + }; const wrapper = mountWithIntl( - + ); expect( @@ -826,24 +510,7 @@ describe('#getCommonColumns', () => { test('it renders the expected column name', () => { const wrapper = mountWithIntl( - + ); @@ -858,24 +525,7 @@ describe('#getCommonColumns', () => { test('it renders the last modified (updated) date when the timeline has an updated property', () => { const wrapper = mountWithIntl( - + ); @@ -893,24 +543,7 @@ describe('#getCommonColumns', () => { const wrapper = mountWithIntl( - + ); expect( diff --git a/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/extended_columns.test.tsx b/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/extended_columns.test.tsx index 4cbe1e45c473b9..3960d087651265 100644 --- a/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/extended_columns.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/extended_columns.test.tsx @@ -10,15 +10,14 @@ import { mountWithIntl } from 'test_utils/enzyme_helpers'; import React from 'react'; import { ThemeProvider } from 'styled-components'; -import { DEFAULT_SEARCH_RESULTS_PER_PAGE } from '../../../pages/timelines/timelines_page'; import { getEmptyValue } from '../../empty_value'; import { mockTimelineResults } from '../../../mock/timeline_results'; import { OpenTimelineResult } from '../types'; -import { TimelinesTable } from '.'; +import { TimelinesTable, TimelinesTableProps } from '.'; import * as i18n from '../translations'; -import { DEFAULT_SORT_DIRECTION, DEFAULT_SORT_FIELD } from '../constants'; +import { getMockTimelinesTableProps } from './mocks'; jest.mock('../../../lib/kibana'); @@ -32,26 +31,12 @@ describe('#getExtendedColumns', () => { describe('Modified By column', () => { test('it renders the expected column name', () => { + const testProps: TimelinesTableProps = { + ...getMockTimelinesTableProps(mockResults), + }; const wrapper = mountWithIntl( - + ); @@ -64,26 +49,12 @@ describe('#getExtendedColumns', () => { }); test('it renders the username when the timeline has an updatedBy property', () => { + const testProps: TimelinesTableProps = { + ...getMockTimelinesTableProps(mockResults), + }; const wrapper = mountWithIntl( - + ); @@ -97,27 +68,12 @@ describe('#getExtendedColumns', () => { test('it renders a placeholder when the timeline is missing the updatedBy property', () => { const missingUpdatedBy: OpenTimelineResult[] = [omit('updatedBy', { ...mockResults[0] })]; - + const testProps: TimelinesTableProps = { + ...getMockTimelinesTableProps(missingUpdatedBy), + }; const wrapper = mountWithIntl( - + ); diff --git a/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/icon_header_columns.test.tsx b/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/icon_header_columns.test.tsx index 31377d176acac9..658dd96faa9864 100644 --- a/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/icon_header_columns.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/icon_header_columns.test.tsx @@ -10,12 +10,10 @@ import { mountWithIntl } from 'test_utils/enzyme_helpers'; import React from 'react'; import { ThemeProvider } from 'styled-components'; -import { DEFAULT_SEARCH_RESULTS_PER_PAGE } from '../../../pages/timelines/timelines_page'; import { mockTimelineResults } from '../../../mock/timeline_results'; -import { TimelinesTable } from '.'; +import { TimelinesTable, TimelinesTableProps } from '.'; import { OpenTimelineResult } from '../types'; -import { DEFAULT_SORT_DIRECTION, DEFAULT_SORT_FIELD } from '../constants'; - +import { getMockTimelinesTableProps } from './mocks'; jest.mock('../../../lib/kibana'); describe('#getActionsColumns', () => { @@ -29,24 +27,7 @@ describe('#getActionsColumns', () => { test('it renders the pinned events header icon', () => { const wrapper = mountWithIntl( - + ); @@ -55,26 +36,13 @@ describe('#getActionsColumns', () => { test('it renders the expected pinned events count', () => { const with6Events = [mockResults[0]]; - + const testProps: TimelinesTableProps = { + ...getMockTimelinesTableProps(with6Events), + }; const wrapper = mountWithIntl( - + + + ); expect(wrapper.find('[data-test-subj="pinned-event-count"]').text()).toEqual('6'); @@ -83,24 +51,7 @@ describe('#getActionsColumns', () => { test('it renders the notes count header icon', () => { const wrapper = mountWithIntl( - + ); @@ -109,26 +60,13 @@ describe('#getActionsColumns', () => { test('it renders the expected notes count', () => { const with4Notes = [mockResults[0]]; - + const testProps: TimelinesTableProps = { + ...getMockTimelinesTableProps(with4Notes), + }; const wrapper = mountWithIntl( - + + + ); expect(wrapper.find('[data-test-subj="notes-count"]').text()).toEqual('4'); @@ -137,24 +75,7 @@ describe('#getActionsColumns', () => { test('it renders the favorites header icon', () => { const wrapper = mountWithIntl( - + ); @@ -163,26 +84,13 @@ describe('#getActionsColumns', () => { test('it renders an empty star when favorite is undefined', () => { const undefinedFavorite: OpenTimelineResult[] = [omit('favorite', { ...mockResults[0] })]; - + const testProps: TimelinesTableProps = { + ...getMockTimelinesTableProps(undefinedFavorite), + }; const wrapper = mountWithIntl( - + + + ); expect(wrapper.find('[data-test-subj="favorite-starEmpty-star"]').exists()).toBe(true); @@ -190,26 +98,13 @@ describe('#getActionsColumns', () => { test('it renders an empty star when favorite is null', () => { const nullFavorite: OpenTimelineResult[] = [{ ...mockResults[0], favorite: null }]; - + const testProps: TimelinesTableProps = { + ...getMockTimelinesTableProps(nullFavorite), + }; const wrapper = mountWithIntl( - + + + ); expect(wrapper.find('[data-test-subj="favorite-starEmpty-star"]').exists()).toBe(true); @@ -217,33 +112,20 @@ describe('#getActionsColumns', () => { test('it renders an empty star when favorite is empty', () => { const emptyFavorite: OpenTimelineResult[] = [{ ...mockResults[0], favorite: [] }]; - + const testProps: TimelinesTableProps = { + ...getMockTimelinesTableProps(emptyFavorite), + }; const wrapper = mountWithIntl( - + + + ); expect(wrapper.find('[data-test-subj="favorite-starEmpty-star"]').exists()).toBe(true); }); test('it renders an filled star when favorite has one entry', () => { - const emptyFavorite: OpenTimelineResult[] = [ + const favorite: OpenTimelineResult[] = [ { ...mockResults[0], favorite: [ @@ -255,32 +137,20 @@ describe('#getActionsColumns', () => { }, ]; + const testProps: TimelinesTableProps = { + ...getMockTimelinesTableProps(favorite), + }; const wrapper = mountWithIntl( - + + + ); expect(wrapper.find('[data-test-subj="favorite-starFilled-star"]').exists()).toBe(true); }); test('it renders an filled star when favorite has more than one entry', () => { - const emptyFavorite: OpenTimelineResult[] = [ + const favorite: OpenTimelineResult[] = [ { ...mockResults[0], favorite: [ @@ -296,25 +166,13 @@ describe('#getActionsColumns', () => { }, ]; + const testProps: TimelinesTableProps = { + ...getMockTimelinesTableProps(favorite), + }; const wrapper = mountWithIntl( - + + + ); expect(wrapper.find('[data-test-subj="favorite-starFilled-star"]').exists()).toBe(true); diff --git a/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/index.test.tsx index 9463bf7de28c1d..e124f58a0c9890 100644 --- a/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/index.test.tsx @@ -10,13 +10,12 @@ import { mountWithIntl } from 'test_utils/enzyme_helpers'; import React from 'react'; import { ThemeProvider } from 'styled-components'; -import { DEFAULT_SEARCH_RESULTS_PER_PAGE } from '../../../pages/timelines/timelines_page'; import { mockTimelineResults } from '../../../mock/timeline_results'; import { OpenTimelineResult } from '../types'; import { TimelinesTable, TimelinesTableProps } from '.'; +import { getMockTimelinesTableProps } from './mocks'; import * as i18n from '../translations'; -import { DEFAULT_SORT_DIRECTION, DEFAULT_SORT_FIELD } from '../constants'; jest.mock('../../../lib/kibana'); @@ -31,24 +30,7 @@ describe('TimelinesTable', () => { test('it renders the select all timelines header checkbox when actionTimelineToShow has the action selectable', () => { const wrapper = mountWithIntl( - + ); @@ -61,26 +43,13 @@ describe('TimelinesTable', () => { }); test('it does NOT render the select all timelines header checkbox when actionTimelineToShow has not the action selectable', () => { + const testProps: TimelinesTableProps = { + ...getMockTimelinesTableProps(mockResults), + actionTimelineToShow: ['delete', 'duplicate'], + }; const wrapper = mountWithIntl( - + ); @@ -93,26 +62,13 @@ describe('TimelinesTable', () => { }); test('it renders the Modified By column when showExtendedColumns is true ', () => { + const testProps: TimelinesTableProps = { + ...getMockTimelinesTableProps(mockResults), + showExtendedColumns: true, + }; const wrapper = mountWithIntl( - + ); @@ -125,33 +81,20 @@ describe('TimelinesTable', () => { }); test('it renders the notes column in the position of the Modified By column when showExtendedColumns is false', () => { + const testProps: TimelinesTableProps = { + ...getMockTimelinesTableProps(mockResults), + showExtendedColumns: false, + }; const wrapper = mountWithIntl( - + ); expect( wrapper .find('thead tr th') - .at(5) + .at(6) .find('[data-test-subj="notes-count-header-icon"]') .first() .exists() @@ -161,24 +104,7 @@ describe('TimelinesTable', () => { test('it renders the delete timeline (trash icon) when actionTimelineToShow has the delete action', () => { const wrapper = mountWithIntl( - + ); @@ -191,26 +117,13 @@ describe('TimelinesTable', () => { }); test('it does NOT render the delete timeline (trash icon) when actionTimelineToShow has NOT the delete action', () => { + const testProps: TimelinesTableProps = { + ...getMockTimelinesTableProps(mockResults), + actionTimelineToShow: ['duplicate', 'selectable'], + }; const wrapper = mountWithIntl( - + ); @@ -225,24 +138,7 @@ describe('TimelinesTable', () => { test('it renders the rows per page selector when showExtendedColumns is true', () => { const wrapper = mountWithIntl( - + ); @@ -255,26 +151,13 @@ describe('TimelinesTable', () => { }); test('it does NOT render the rows per page selector when showExtendedColumns is false', () => { + const testProps: TimelinesTableProps = { + ...getMockTimelinesTableProps(mockResults), + showExtendedColumns: false, + }; const wrapper = mountWithIntl( - + ); @@ -288,27 +171,14 @@ describe('TimelinesTable', () => { test('it renders the default page size specified by the defaultPageSize prop', () => { const defaultPageSize = 123; - + const testProps = { + ...getMockTimelinesTableProps(mockResults), + defaultPageSize, + pageSize: defaultPageSize, + }; const wrapper = mountWithIntl( - + ); @@ -323,24 +193,7 @@ describe('TimelinesTable', () => { test('it sorts the Last Modified column in descending order when showExtendedColumns is true ', () => { const wrapper = mountWithIntl( - + ); @@ -353,26 +206,13 @@ describe('TimelinesTable', () => { }); test('it sorts the Last Modified column in descending order when showExtendedColumns is false ', () => { + const testProps: TimelinesTableProps = { + ...getMockTimelinesTableProps(mockResults), + showExtendedColumns: false, + }; const wrapper = mountWithIntl( - + ); @@ -385,25 +225,14 @@ describe('TimelinesTable', () => { }); test('it displays the expected message when no search results are found', () => { + const testProps: TimelinesTableProps = { + ...getMockTimelinesTableProps(mockResults), + searchResults: [], + }; const wrapper = mountWithIntl( - + + + ); expect( @@ -416,27 +245,13 @@ describe('TimelinesTable', () => { test('it invokes onTableChange with the expected parameters when a table header is clicked to sort it', () => { const onTableChange = jest.fn(); - + const testProps: TimelinesTableProps = { + ...getMockTimelinesTableProps(mockResults), + onTableChange, + }; const wrapper = mountWithIntl( - + ); @@ -455,27 +270,13 @@ describe('TimelinesTable', () => { test('it invokes onSelectionChange when a row is selected', () => { const onSelectionChange = jest.fn(); - + const testProps: TimelinesTableProps = { + ...getMockTimelinesTableProps(mockResults), + onSelectionChange, + }; const wrapper = mountWithIntl( - + ); @@ -490,26 +291,13 @@ describe('TimelinesTable', () => { }); test('it enables the table loading animation when isLoading is true', () => { + const testProps: TimelinesTableProps = { + ...getMockTimelinesTableProps(mockResults), + loading: true, + }; const wrapper = mountWithIntl( - + ); @@ -524,24 +312,7 @@ describe('TimelinesTable', () => { test('it disables the table loading animation when isLoading is false', () => { const wrapper = mountWithIntl( - + ); diff --git a/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/index.tsx b/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/index.tsx index f09a9f6af048b5..7091ef1f0a1f9c 100644 --- a/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/index.tsx +++ b/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/index.tsx @@ -17,6 +17,8 @@ import { OnTableChange, OnToggleShowNotes, OpenTimelineResult, + EnableExportTimelineDownloader, + OnOpenDeleteTimelineModal, } from '../types'; import { getActionsColumns } from './actions_columns'; import { getCommonColumns } from './common_columns'; @@ -46,34 +48,44 @@ const getExtendedColumnsIfEnabled = (showExtendedColumns: boolean) => * view, and the full view shown in the `All Timelines` view of the * `Timelines` page */ -const getTimelinesTableColumns = ({ + +export const getTimelinesTableColumns = ({ actionTimelineToShow, deleteTimelines, + enableExportTimelineDownloader, itemIdToExpandedNotesRowMap, + onOpenDeleteTimelineModal, onOpenTimeline, onToggleShowNotes, showExtendedColumns, }: { actionTimelineToShow: ActionTimelineToShow[]; deleteTimelines?: DeleteTimelines; + enableExportTimelineDownloader?: EnableExportTimelineDownloader; itemIdToExpandedNotesRowMap: Record; + onOpenDeleteTimelineModal?: OnOpenDeleteTimelineModal; onOpenTimeline: OnOpenTimeline; + onSelectionChange: OnSelectionChange; onToggleShowNotes: OnToggleShowNotes; showExtendedColumns: boolean; -}) => [ - ...getCommonColumns({ - itemIdToExpandedNotesRowMap, - onOpenTimeline, - onToggleShowNotes, - }), - ...getExtendedColumnsIfEnabled(showExtendedColumns), - ...getIconHeaderColumns(), - ...getActionsColumns({ - deleteTimelines, - onOpenTimeline, - actionTimelineToShow, - }), -]; +}) => { + return [ + ...getCommonColumns({ + itemIdToExpandedNotesRowMap, + onOpenTimeline, + onToggleShowNotes, + }), + ...getExtendedColumnsIfEnabled(showExtendedColumns), + ...getIconHeaderColumns(), + ...getActionsColumns({ + actionTimelineToShow, + deleteTimelines, + enableExportTimelineDownloader, + onOpenDeleteTimelineModal, + onOpenTimeline, + }), + ]; +}; export interface TimelinesTableProps { actionTimelineToShow: ActionTimelineToShow[]; @@ -81,6 +93,8 @@ export interface TimelinesTableProps { defaultPageSize: number; loading: boolean; itemIdToExpandedNotesRowMap: Record; + enableExportTimelineDownloader?: EnableExportTimelineDownloader; + onOpenDeleteTimelineModal?: OnOpenDeleteTimelineModal; onOpenTimeline: OnOpenTimeline; onSelectionChange: OnSelectionChange; onTableChange: OnTableChange; @@ -91,6 +105,8 @@ export interface TimelinesTableProps { showExtendedColumns: boolean; sortDirection: 'asc' | 'desc'; sortField: string; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + tableRef?: React.MutableRefObject<_EuiBasicTable | undefined>; totalSearchResultsCount: number; } @@ -105,6 +121,8 @@ export const TimelinesTable = React.memo( defaultPageSize, loading: isLoading, itemIdToExpandedNotesRowMap, + enableExportTimelineDownloader, + onOpenDeleteTimelineModal, onOpenTimeline, onSelectionChange, onTableChange, @@ -115,6 +133,7 @@ export const TimelinesTable = React.memo( showExtendedColumns, sortField, sortDirection, + tableRef, totalSearchResultsCount, }) => { const pagination = { @@ -142,14 +161,17 @@ export const TimelinesTable = React.memo( !selectable ? i18n.MISSING_SAVED_OBJECT_ID : undefined, onSelectionChange, }; - + const basicTableProps = tableRef != null ? { ref: tableRef } : {}; return ( ( pagination={pagination} selection={actionTimelineToShow.includes('selectable') ? selection : undefined} sorting={sorting} + {...basicTableProps} /> ); } diff --git a/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/mocks.ts b/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/mocks.ts new file mode 100644 index 00000000000000..519dfc1b66efee --- /dev/null +++ b/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/mocks.ts @@ -0,0 +1,32 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ +import { DEFAULT_SEARCH_RESULTS_PER_PAGE } from '../../../pages/timelines/timelines_page'; +import { DEFAULT_SORT_DIRECTION, DEFAULT_SORT_FIELD } from '../constants'; +import { OpenTimelineResult } from '../types'; +import { TimelinesTableProps } from '.'; + +export const getMockTimelinesTableProps = ( + mockOpenTimelineResults: OpenTimelineResult[] +): TimelinesTableProps => ({ + actionTimelineToShow: ['delete', 'duplicate', 'selectable'], + deleteTimelines: jest.fn(), + defaultPageSize: DEFAULT_SEARCH_RESULTS_PER_PAGE, + enableExportTimelineDownloader: jest.fn(), + itemIdToExpandedNotesRowMap: {}, + loading: false, + onOpenDeleteTimelineModal: jest.fn(), + onOpenTimeline: jest.fn(), + onSelectionChange: jest.fn(), + onTableChange: jest.fn(), + onToggleShowNotes: jest.fn(), + pageIndex: 0, + pageSize: DEFAULT_SEARCH_RESULTS_PER_PAGE, + searchResults: mockOpenTimelineResults, + showExtendedColumns: true, + sortDirection: DEFAULT_SORT_DIRECTION, + sortField: DEFAULT_SORT_FIELD, + totalSearchResultsCount: mockOpenTimelineResults.length, +}); diff --git a/x-pack/legacy/plugins/siem/public/components/open_timeline/title_row/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/open_timeline/title_row/index.test.tsx index 88dfab470ac962..fe49b05ae6275a 100644 --- a/x-pack/legacy/plugins/siem/public/components/open_timeline/title_row/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/open_timeline/title_row/index.test.tsx @@ -19,12 +19,7 @@ describe('TitleRow', () => { test('it renders the title', () => { const wrapper = mountWithIntl( - + ); @@ -42,7 +37,6 @@ describe('TitleRow', () => { @@ -60,7 +54,7 @@ describe('TitleRow', () => { test('it does NOT render the Favorite Selected button when onAddTimelinesToFavorites is NOT provided', () => { const wrapper = mountWithIntl( - + ); @@ -77,7 +71,6 @@ describe('TitleRow', () => { @@ -97,7 +90,6 @@ describe('TitleRow', () => { @@ -119,7 +111,6 @@ describe('TitleRow', () => { @@ -134,107 +125,4 @@ describe('TitleRow', () => { expect(onAddTimelinesToFavorites).toHaveBeenCalled(); }); }); - - describe('Delete Selected button', () => { - test('it renders the Delete Selected button when onDeleteSelected is provided', () => { - const wrapper = mountWithIntl( - - - - ); - - expect( - wrapper - .find('[data-test-subj="delete-selected"]') - .first() - .exists() - ).toBe(true); - }); - - test('it does NOT render the Delete Selected button when onDeleteSelected is NOT provided', () => { - const wrapper = mountWithIntl( - - - - ); - - expect( - wrapper - .find('[data-test-subj="delete-selected"]') - .first() - .exists() - ).toBe(false); - }); - - test('it disables the Delete Selected button when the selectedTimelinesCount is 0', () => { - const wrapper = mountWithIntl( - - - - ); - - const props = wrapper - .find('[data-test-subj="delete-selected"]') - .first() - .props() as EuiButtonProps; - - expect(props.isDisabled).toBe(true); - }); - - test('it enables the Delete Selected button when the selectedTimelinesCount is greater than 0', () => { - const wrapper = mountWithIntl( - - - - ); - - const props = wrapper - .find('[data-test-subj="delete-selected"]') - .first() - .props() as EuiButtonProps; - - expect(props.isDisabled).toBe(false); - }); - - test('it invokes onDeleteSelected when the Delete Selected button is clicked', () => { - const onDeleteSelected = jest.fn(); - - const wrapper = mountWithIntl( - - - - ); - - wrapper - .find('[data-test-subj="delete-selected"]') - .first() - .simulate('click'); - - expect(onDeleteSelected).toHaveBeenCalled(); - }); - }); }); diff --git a/x-pack/legacy/plugins/siem/public/components/open_timeline/title_row/index.tsx b/x-pack/legacy/plugins/siem/public/components/open_timeline/title_row/index.tsx index c7de367e043640..559bbc3eecb824 100644 --- a/x-pack/legacy/plugins/siem/public/components/open_timeline/title_row/index.tsx +++ b/x-pack/legacy/plugins/siem/public/components/open_timeline/title_row/index.tsx @@ -11,9 +11,10 @@ import * as i18n from '../translations'; import { OpenTimelineProps } from '../types'; import { HeaderSection } from '../../header_section'; -type Props = Pick & { +type Props = Pick & { /** The number of timelines currently selected */ selectedTimelinesCount: number; + children?: JSX.Element; }; /** @@ -21,39 +22,25 @@ type Props = Pick( - ({ onAddTimelinesToFavorites, onDeleteSelected, selectedTimelinesCount, title }) => ( - - {(onAddTimelinesToFavorites || onDeleteSelected) && ( - - {onAddTimelinesToFavorites && ( - - - {i18n.FAVORITE_SELECTED} - - - )} + ({ children, onAddTimelinesToFavorites, selectedTimelinesCount, title }) => ( + + + {onAddTimelinesToFavorites && ( + + + {i18n.FAVORITE_SELECTED} + + + )} - {onDeleteSelected && ( - - - {i18n.DELETE_SELECTED} - - - )} - - )} + {children && {children}} + ) ); diff --git a/x-pack/legacy/plugins/siem/public/components/open_timeline/translations.ts b/x-pack/legacy/plugins/siem/public/components/open_timeline/translations.ts index b4e0d9967f2a96..4063b73d9499a3 100644 --- a/x-pack/legacy/plugins/siem/public/components/open_timeline/translations.ts +++ b/x-pack/legacy/plugins/siem/public/components/open_timeline/translations.ts @@ -6,6 +6,14 @@ import { i18n } from '@kbn/i18n'; +export const ALL_ACTIONS = i18n.translate('xpack.siem.open.timeline.allActionsTooltip', { + defaultMessage: 'All actions', +}); + +export const BATCH_ACTIONS = i18n.translate('xpack.siem.open.timeline.batchActionsTitle', { + defaultMessage: 'Bulk actions', +}); + export const CANCEL = i18n.translate('xpack.siem.open.timeline.cancelButton', { defaultMessage: 'Cancel', }); @@ -34,6 +42,14 @@ export const EXPAND = i18n.translate('xpack.siem.open.timeline.expandButton', { defaultMessage: 'Expand', }); +export const EXPORT_FILENAME = i18n.translate('xpack.siem.open.timeline.exportFileNameTitle', { + defaultMessage: 'timelines_export', +}); + +export const EXPORT_SELECTED = i18n.translate('xpack.siem.open.timeline.exportSelectedButton', { + defaultMessage: 'Export selected', +}); + export const FAVORITE_SELECTED = i18n.translate('xpack.siem.open.timeline.favoriteSelectedButton', { defaultMessage: 'Favorite selected', }); @@ -66,7 +82,7 @@ export const ONLY_FAVORITES = i18n.translate('xpack.siem.open.timeline.onlyFavor }); export const OPEN_AS_DUPLICATE = i18n.translate('xpack.siem.open.timeline.openAsDuplicateTooltip', { - defaultMessage: 'Open as a duplicate timeline', + defaultMessage: 'Duplicate timeline', }); export const OPEN_TIMELINE = i18n.translate('xpack.siem.open.timeline.openTimelineButton', { @@ -85,6 +101,10 @@ export const POSTED = i18n.translate('xpack.siem.open.timeline.postedLabel', { defaultMessage: 'Posted:', }); +export const REFRESH = i18n.translate('xpack.siem.open.timeline.refreshTitle', { + defaultMessage: 'Refresh', +}); + export const SEARCH_PLACEHOLDER = i18n.translate('xpack.siem.open.timeline.searchPlaceholder', { defaultMessage: 'e.g. timeline name, or description', }); @@ -107,3 +127,21 @@ export const ZERO_TIMELINES_MATCH = i18n.translate( defaultMessage: '0 timelines match the search criteria', } ); + +export const SELECTED_TIMELINES = (selectedTimelines: number) => + i18n.translate('xpack.siem.open.timeline.selectedTimelinesTitle', { + values: { selectedTimelines }, + defaultMessage: + 'Selected {selectedTimelines} {selectedTimelines, plural, =1 {timeline} other {timelines}}', + }); + +export const SHOWING = i18n.translate('xpack.siem.open.timeline.showingLabel', { + defaultMessage: 'Showing:', +}); + +export const SUCCESSFULLY_EXPORTED_TIMELINES = (totalTimelines: number) => + i18n.translate('xpack.siem.open.timeline.successfullyExportedTimelinesTitle', { + values: { totalTimelines }, + defaultMessage: + 'Successfully exported {totalTimelines, plural, =0 {all timelines} =1 {{totalTimelines} timeline} other {{totalTimelines} timelines}}', + }); diff --git a/x-pack/legacy/plugins/siem/public/components/open_timeline/types.ts b/x-pack/legacy/plugins/siem/public/components/open_timeline/types.ts index b14bb1cf86d318..b466ea32799d9f 100644 --- a/x-pack/legacy/plugins/siem/public/components/open_timeline/types.ts +++ b/x-pack/legacy/plugins/siem/public/components/open_timeline/types.ts @@ -4,9 +4,11 @@ * you may not use this file except in compliance with the Elastic License. */ +import { SetStateAction, Dispatch } from 'react'; import { AllTimelinesVariables } from '../../containers/timeline/all'; import { TimelineModel } from '../../store/timeline/model'; import { NoteResult } from '../../graphql/types'; +import { Refetch } from '../../store/inputs/model'; /** The users who added a timeline to favorites */ export interface FavoriteTimelineResult { @@ -18,10 +20,22 @@ export interface FavoriteTimelineResult { export interface TimelineResultNote { savedObjectId?: string | null; note?: string | null; + noteId?: string | null; updated?: number | null; updatedBy?: string | null; } +export interface TimelineActionsOverflowColumns { + width: string; + actions: Array<{ + name: string; + icon?: string; + onClick?: (timeline: OpenTimelineResult) => void; + description: string; + render?: (timeline: OpenTimelineResult) => JSX.Element; + } | null>; +} + /** The results of the query run by the OpenTimeline component */ export interface OpenTimelineResult { created?: number | null; @@ -65,6 +79,9 @@ export type OnOpenTimeline = ({ timelineId: string; }) => void; +export type OnOpenDeleteTimelineModal = (selectedItem: OpenTimelineResult) => void; +export type SetActionTimeline = Dispatch>; +export type EnableExportTimelineDownloader = (selectedItem: OpenTimelineResult) => void; /** Invoked when the user presses enters to submit the text in the search input */ export type OnQueryChange = (query: EuiSearchBarQuery) => void; @@ -92,7 +109,7 @@ export interface OnTableChangeParams { /** Invoked by the EUI table implementation when the user interacts with the table */ export type OnTableChange = (tableChange: OnTableChangeParams) => void; -export type ActionTimelineToShow = 'duplicate' | 'delete' | 'selectable'; +export type ActionTimelineToShow = 'duplicate' | 'delete' | 'export' | 'selectable'; export interface OpenTimelineProps { /** Invoked when the user clicks the delete (trash) icon on an individual timeline */ @@ -127,6 +144,9 @@ export interface OpenTimelineProps { pageSize: number; /** The currently applied search criteria */ query: string; + /** Refetch timelines data */ + refetch?: Refetch; + /** The results of executing a search */ searchResults: OpenTimelineResult[]; /** the currently-selected timelines in the table */ diff --git a/x-pack/legacy/plugins/siem/public/components/utility_bar/utility_bar_text.tsx b/x-pack/legacy/plugins/siem/public/components/utility_bar/utility_bar_text.tsx index 95e12518155a85..b7815b59f03f58 100644 --- a/x-pack/legacy/plugins/siem/public/components/utility_bar/utility_bar_text.tsx +++ b/x-pack/legacy/plugins/siem/public/components/utility_bar/utility_bar_text.tsx @@ -9,7 +9,7 @@ import React from 'react'; import { BarText } from './styles'; export interface UtilityBarTextProps { - children: string; + children: string | JSX.Element; dataTestSubj?: string; } diff --git a/x-pack/legacy/plugins/siem/public/containers/detection_engine/rules/api.test.ts b/x-pack/legacy/plugins/siem/public/containers/detection_engine/rules/api.test.ts index 3048fc3dc5a02b..8fdc6a67f7d712 100644 --- a/x-pack/legacy/plugins/siem/public/containers/detection_engine/rules/api.test.ts +++ b/x-pack/legacy/plugins/siem/public/containers/detection_engine/rules/api.test.ts @@ -402,7 +402,7 @@ describe('Detections Rules API', () => { test('check parameter url, body and query when exporting rules', async () => { await exportRules({ - ruleIds: ['mySuperRuleId', 'mySuperRuleId_II'], + ids: ['mySuperRuleId', 'mySuperRuleId_II'], signal: abortCtrl.signal, }); expect(fetchMock).toHaveBeenCalledWith('/api/detection_engine/rules/_export', { @@ -419,7 +419,7 @@ describe('Detections Rules API', () => { test('check parameter url, body and query when exporting rules with excludeExportDetails', async () => { await exportRules({ excludeExportDetails: true, - ruleIds: ['mySuperRuleId', 'mySuperRuleId_II'], + ids: ['mySuperRuleId', 'mySuperRuleId_II'], signal: abortCtrl.signal, }); expect(fetchMock).toHaveBeenCalledWith('/api/detection_engine/rules/_export', { @@ -436,7 +436,7 @@ describe('Detections Rules API', () => { test('check parameter url, body and query when exporting rules with fileName', async () => { await exportRules({ filename: 'myFileName.ndjson', - ruleIds: ['mySuperRuleId', 'mySuperRuleId_II'], + ids: ['mySuperRuleId', 'mySuperRuleId_II'], signal: abortCtrl.signal, }); expect(fetchMock).toHaveBeenCalledWith('/api/detection_engine/rules/_export', { @@ -454,7 +454,7 @@ describe('Detections Rules API', () => { await exportRules({ excludeExportDetails: true, filename: 'myFileName.ndjson', - ruleIds: ['mySuperRuleId', 'mySuperRuleId_II'], + ids: ['mySuperRuleId', 'mySuperRuleId_II'], signal: abortCtrl.signal, }); expect(fetchMock).toHaveBeenCalledWith('/api/detection_engine/rules/_export', { @@ -470,7 +470,7 @@ describe('Detections Rules API', () => { test('happy path', async () => { const resp = await exportRules({ - ruleIds: ['mySuperRuleId', 'mySuperRuleId_II'], + ids: ['mySuperRuleId', 'mySuperRuleId_II'], signal: abortCtrl.signal, }); expect(resp).toEqual(blob); diff --git a/x-pack/legacy/plugins/siem/public/containers/detection_engine/rules/api.ts b/x-pack/legacy/plugins/siem/public/containers/detection_engine/rules/api.ts index b52c4964c66956..126de9762a6963 100644 --- a/x-pack/legacy/plugins/siem/public/containers/detection_engine/rules/api.ts +++ b/x-pack/legacy/plugins/siem/public/containers/detection_engine/rules/api.ts @@ -16,7 +16,7 @@ import { FetchRuleProps, BasicFetchProps, ImportRulesProps, - ExportRulesProps, + ExportDocumentsProps, RuleStatusResponse, ImportRulesResponse, PrePackagedRulesStatusResponse, @@ -233,13 +233,11 @@ export const importRules = async ({ export const exportRules = async ({ excludeExportDetails = false, filename = `${i18n.EXPORT_FILENAME}.ndjson`, - ruleIds = [], + ids = [], signal, -}: ExportRulesProps): Promise => { +}: ExportDocumentsProps): Promise => { const body = - ruleIds.length > 0 - ? JSON.stringify({ objects: ruleIds.map(rule => ({ rule_id: rule })) }) - : undefined; + ids.length > 0 ? JSON.stringify({ objects: ids.map(rule => ({ rule_id: rule })) }) : undefined; return KibanaServices.get().http.fetch(`${DETECTION_ENGINE_RULES_URL}/_export`, { method: 'POST', diff --git a/x-pack/legacy/plugins/siem/public/containers/detection_engine/rules/types.ts b/x-pack/legacy/plugins/siem/public/containers/detection_engine/rules/types.ts index 5466ba2203714f..c75d7b78cf92f0 100644 --- a/x-pack/legacy/plugins/siem/public/containers/detection_engine/rules/types.ts +++ b/x-pack/legacy/plugins/siem/public/containers/detection_engine/rules/types.ts @@ -191,8 +191,8 @@ export interface ImportRulesResponse { errors: ImportRulesResponseError[]; } -export interface ExportRulesProps { - ruleIds?: string[]; +export interface ExportDocumentsProps { + ids: string[]; filename?: string; excludeExportDetails?: boolean; signal: AbortSignal; diff --git a/x-pack/legacy/plugins/siem/public/containers/timeline/all/api.ts b/x-pack/legacy/plugins/siem/public/containers/timeline/all/api.ts new file mode 100644 index 00000000000000..edda2e30ea4000 --- /dev/null +++ b/x-pack/legacy/plugins/siem/public/containers/timeline/all/api.ts @@ -0,0 +1,30 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { KibanaServices } from '../../../lib/kibana'; +import { ExportSelectedData } from '../../../components/generic_downloader'; +import { TIMELINE_EXPORT_URL } from '../../../../common/constants'; + +export const exportSelectedTimeline: ExportSelectedData = async ({ + excludeExportDetails = false, + filename = `timelines_export.ndjson`, + ids = [], + signal, +}): Promise => { + const body = ids.length > 0 ? JSON.stringify({ ids }) : undefined; + const response = await KibanaServices.get().http.fetch(`${TIMELINE_EXPORT_URL}`, { + method: 'POST', + body, + query: { + exclude_export_details: excludeExportDetails, + file_name: filename, + }, + signal, + asResponse: true, + }); + + return response.body!; +}; diff --git a/x-pack/legacy/plugins/siem/public/containers/timeline/all/index.tsx b/x-pack/legacy/plugins/siem/public/containers/timeline/all/index.tsx index 22c7b03f34dd58..b5c91ca287f0b8 100644 --- a/x-pack/legacy/plugins/siem/public/containers/timeline/all/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/timeline/all/index.tsx @@ -3,13 +3,13 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ - +import React, { useCallback } from 'react'; import { getOr } from 'lodash/fp'; -import React from 'react'; import memoizeOne from 'memoize-one'; import { Query } from 'react-apollo'; +import { ApolloQueryResult } from 'apollo-client'; import { OpenTimelineResult } from '../../../components/open_timeline/types'; import { GetAllTimeline, @@ -23,6 +23,7 @@ export interface AllTimelinesArgs { timelines: OpenTimelineResult[]; loading: boolean; totalCount: number; + refetch: () => void; } export interface AllTimelinesVariables { @@ -36,6 +37,10 @@ interface OwnProps extends AllTimelinesVariables { children?: (args: AllTimelinesArgs) => React.ReactNode; } +type Refetch = ( + variables: GetAllTimeline.Variables | undefined +) => Promise>; + const getAllTimeline = memoizeOne( (variables: string, timelines: TimelineResult[]): OpenTimelineResult[] => timelines.map(timeline => ({ @@ -84,6 +89,8 @@ const AllTimelinesQueryComponent: React.FC = ({ search, sort, }; + const handleRefetch = useCallback((refetch: Refetch) => refetch(variables), [variables]); + return ( query={allTimelinesQuery} @@ -91,9 +98,10 @@ const AllTimelinesQueryComponent: React.FC = ({ notifyOnNetworkStatusChange variables={variables} > - {({ data, loading }) => + {({ data, loading, refetch }) => children!({ loading, + refetch: handleRefetch.bind(null, refetch), totalCount: getOr(0, 'getAllTimeline.totalCount', data), timelines: getAllTimeline( JSON.stringify(variables), diff --git a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/all/index.tsx b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/all/index.tsx index bb718d80298172..621c70e3913190 100644 --- a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/all/index.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/all/index.tsx @@ -22,6 +22,7 @@ import { FilterOptions, Rule, PaginationOptions, + exportRules, } from '../../../../containers/detection_engine/rules'; import { HeaderSection } from '../../../../components/header_section'; import { @@ -35,7 +36,7 @@ import { useStateToaster } from '../../../../components/toasters'; import { Loader } from '../../../../components/loader'; import { Panel } from '../../../../components/panel'; import { PrePackagedRulesPrompt } from '../components/pre_packaged_rules/load_empty_prompt'; -import { RuleDownloader } from '../components/rule_downloader'; +import { GenericDownloader } from '../../../../components/generic_downloader'; import { getPrePackagedRuleStatus } from '../helpers'; import * as i18n from '../translations'; import { EuiBasicTableOnChange } from '../types'; @@ -244,10 +245,10 @@ export const AllRules = React.memo( return ( <> - { + ids={exportRuleIds} + onExportSuccess={exportCount => { dispatch({ type: 'loadingRuleIds', ids: [], actionType: null }); dispatchToaster({ type: 'addToaster', @@ -259,6 +260,7 @@ export const AllRules = React.memo( }, }); }} + exportSelectedData={exportRules} /> diff --git a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/rule_actions_overflow/__snapshots__/index.test.tsx.snap b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/rule_actions_overflow/__snapshots__/index.test.tsx.snap index 9355d0ae2cccbc..65a606604d4a7c 100644 --- a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/rule_actions_overflow/__snapshots__/index.test.tsx.snap +++ b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/rule_actions_overflow/__snapshots__/index.test.tsx.snap @@ -55,10 +55,11 @@ exports[`RuleActionsOverflow renders correctly against snapshot 1`] = ` } /> - `; diff --git a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/rule_actions_overflow/index.tsx b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/rule_actions_overflow/index.tsx index 7c8926c2064c72..e1ca84ed8cc642 100644 --- a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/rule_actions_overflow/index.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/rule_actions_overflow/index.tsx @@ -16,12 +16,12 @@ import styled from 'styled-components'; import { noop } from 'lodash/fp'; import { useHistory } from 'react-router-dom'; -import { Rule } from '../../../../../containers/detection_engine/rules'; +import { Rule, exportRules } from '../../../../../containers/detection_engine/rules'; import * as i18n from './translations'; import * as i18nActions from '../../../rules/translations'; import { displaySuccessToast, useStateToaster } from '../../../../../components/toasters'; import { deleteRulesAction, duplicateRulesAction } from '../../all/actions'; -import { RuleDownloader } from '../rule_downloader'; +import { GenericDownloader } from '../../../../../components/generic_downloader'; import { DETECTION_ENGINE_PAGE_NAME } from '../../../../../components/link_to/redirect_to_detection_engine'; const MyEuiButtonIcon = styled(EuiButtonIcon)` @@ -129,10 +129,11 @@ const RuleActionsOverflowComponent = ({ > - { + ids={rulesToExport} + exportSelectedData={exportRules} + onExportSuccess={exportCount => { displaySuccessToast( i18nActions.SUCCESSFULLY_EXPORTED_RULES(exportCount), dispatchToaster diff --git a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/rule_downloader/__snapshots__/index.test.tsx.snap b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/rule_downloader/__snapshots__/index.test.tsx.snap deleted file mode 100644 index 4259b68bf14a21..00000000000000 --- a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/rule_downloader/__snapshots__/index.test.tsx.snap +++ /dev/null @@ -1,3 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`RuleDownloader renders correctly against snapshot 1`] = ``; diff --git a/x-pack/legacy/plugins/siem/public/pages/timelines/timelines_page.tsx b/x-pack/legacy/plugins/siem/public/pages/timelines/timelines_page.tsx index 86f702a8ad8a46..6d30ea58089f08 100644 --- a/x-pack/legacy/plugins/siem/public/pages/timelines/timelines_page.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/timelines/timelines_page.tsx @@ -26,23 +26,25 @@ type OwnProps = TimelinesProps; export const DEFAULT_SEARCH_RESULTS_PER_PAGE = 10; -const TimelinesPageComponent: React.FC = ({ apolloClient }) => ( - <> - - - - - - - - - - -); +const TimelinesPageComponent: React.FC = ({ apolloClient }) => { + return ( + <> + + + + + + + + + + + ); +}; export const TimelinesPage = React.memo(TimelinesPageComponent); diff --git a/x-pack/legacy/plugins/siem/public/pages/timelines/translations.ts b/x-pack/legacy/plugins/siem/public/pages/timelines/translations.ts index 5426ccbdb4f9ad..723d164ad2cdd5 100644 --- a/x-pack/legacy/plugins/siem/public/pages/timelines/translations.ts +++ b/x-pack/legacy/plugins/siem/public/pages/timelines/translations.ts @@ -16,3 +16,10 @@ export const ALL_TIMELINES_PANEL_TITLE = i18n.translate( defaultMessage: 'All timelines', } ); + +export const ALL_TIMELINES_IMPORT_TIMELINE_TITLE = i18n.translate( + 'xpack.siem.timelines.allTimelines.importTimelineTitle', + { + defaultMessage: 'Import Timeline', + } +); diff --git a/x-pack/legacy/plugins/siem/server/graphql/timeline/schema.gql.ts b/x-pack/legacy/plugins/siem/server/graphql/timeline/schema.gql.ts index 8b24cea0d6af92..9dd04247b7f47c 100644 --- a/x-pack/legacy/plugins/siem/server/graphql/timeline/schema.gql.ts +++ b/x-pack/legacy/plugins/siem/server/graphql/timeline/schema.gql.ts @@ -150,7 +150,7 @@ export const timelineSchema = gql` updated created } - + input SortTimeline { sortField: SortFieldTimeline! sortOrder: Direction! diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/utils.test.ts b/x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/utils.test.ts index 3a8d068cad38df..3a047f91a0bcbe 100644 --- a/x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/utils.test.ts +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/utils.test.ts @@ -12,7 +12,7 @@ import { transformTags, getIdBulkError, transformOrBulkError, - transformRulesToNdjson, + transformDataToNdjson, transformAlertsToRules, transformOrImportError, getDuplicates, @@ -380,15 +380,15 @@ describe('utils', () => { }); }); - describe('transformRulesToNdjson', () => { + describe('transformDataToNdjson', () => { test('if rules are empty it returns an empty string', () => { - const ruleNdjson = transformRulesToNdjson([]); + const ruleNdjson = transformDataToNdjson([]); expect(ruleNdjson).toEqual(''); }); test('single rule will transform with new line ending character for ndjson', () => { const rule = sampleRule(); - const ruleNdjson = transformRulesToNdjson([rule]); + const ruleNdjson = transformDataToNdjson([rule]); expect(ruleNdjson.endsWith('\n')).toBe(true); }); @@ -399,7 +399,7 @@ describe('utils', () => { result2.rule_id = 'some other id'; result2.name = 'Some other rule'; - const ruleNdjson = transformRulesToNdjson([result1, result2]); + const ruleNdjson = transformDataToNdjson([result1, result2]); // this is how we count characters in JavaScript :-) const count = ruleNdjson.split('\n').length - 1; expect(count).toBe(2); @@ -412,7 +412,7 @@ describe('utils', () => { result2.rule_id = 'some other id'; result2.name = 'Some other rule'; - const ruleNdjson = transformRulesToNdjson([result1, result2]); + const ruleNdjson = transformDataToNdjson([result1, result2]); const ruleStrings = ruleNdjson.split('\n'); const reParsed1 = JSON.parse(ruleStrings[0]); const reParsed2 = JSON.parse(ruleStrings[1]); diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/utils.ts b/x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/utils.ts index fe7618bca0c75b..9bf6a59d528744 100644 --- a/x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/utils.ts +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/utils.ts @@ -147,10 +147,10 @@ export const transformAlertToRule = ( }); }; -export const transformRulesToNdjson = (rules: Array>): string => { - if (rules.length !== 0) { - const rulesString = rules.map(rule => JSON.stringify(rule)).join('\n'); - return `${rulesString}\n`; +export const transformDataToNdjson = (data: unknown[]): string => { + if (data.length !== 0) { + const dataString = data.map(rule => JSON.stringify(rule)).join('\n'); + return `${dataString}\n`; } else { return ''; } diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/get_export_all.ts b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/get_export_all.ts index 434919f80e149b..6a27abb66ce853 100644 --- a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/get_export_all.ts +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/get_export_all.ts @@ -7,7 +7,7 @@ import { AlertsClient } from '../../../../../../../plugins/alerting/server'; import { getNonPackagedRules } from './get_existing_prepackaged_rules'; import { getExportDetailsNdjson } from './get_export_details_ndjson'; -import { transformAlertsToRules, transformRulesToNdjson } from '../routes/rules/utils'; +import { transformAlertsToRules, transformDataToNdjson } from '../routes/rules/utils'; export const getExportAll = async ( alertsClient: AlertsClient @@ -17,7 +17,7 @@ export const getExportAll = async ( }> => { const ruleAlertTypes = await getNonPackagedRules({ alertsClient }); const rules = transformAlertsToRules(ruleAlertTypes); - const rulesNdjson = transformRulesToNdjson(rules); + const rulesNdjson = transformDataToNdjson(rules); const exportDetails = getExportDetailsNdjson(rules); return { rulesNdjson, exportDetails }; }; diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/get_export_by_object_ids.ts b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/get_export_by_object_ids.ts index e3b38a879fc3d6..6f642231ebbafb 100644 --- a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/get_export_by_object_ids.ts +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/get_export_by_object_ids.ts @@ -8,7 +8,7 @@ import { AlertsClient } from '../../../../../../../plugins/alerting/server'; import { getExportDetailsNdjson } from './get_export_details_ndjson'; import { isAlertType } from '../rules/types'; import { readRules } from './read_rules'; -import { transformRulesToNdjson, transformAlertToRule } from '../routes/rules/utils'; +import { transformDataToNdjson, transformAlertToRule } from '../routes/rules/utils'; import { OutputRuleAlertRest } from '../types'; interface ExportSuccesRule { @@ -37,7 +37,7 @@ export const getExportByObjectIds = async ( exportDetails: string; }> => { const rulesAndErrors = await getRulesFromObjects(alertsClient, objects); - const rulesNdjson = transformRulesToNdjson(rulesAndErrors.rules); + const rulesNdjson = transformDataToNdjson(rulesAndErrors.rules); const exportDetails = getExportDetailsNdjson(rulesAndErrors.rules, rulesAndErrors.missingRules); return { rulesNdjson, exportDetails }; }; diff --git a/x-pack/legacy/plugins/siem/server/lib/note/saved_object.ts b/x-pack/legacy/plugins/siem/server/lib/note/saved_object.ts index d825aae1b480bd..b6a43fc523adb9 100644 --- a/x-pack/legacy/plugins/siem/server/lib/note/saved_object.ts +++ b/x-pack/legacy/plugins/siem/server/lib/note/saved_object.ts @@ -194,7 +194,7 @@ export class Note { } } -const convertSavedObjectToSavedNote = ( +export const convertSavedObjectToSavedNote = ( savedObject: unknown, timelineVersion?: string | undefined | null ): NoteSavedObject => diff --git a/x-pack/legacy/plugins/siem/server/lib/pinned_event/saved_object.ts b/x-pack/legacy/plugins/siem/server/lib/pinned_event/saved_object.ts index afa3595a09e1c6..9ea950e8a443b4 100644 --- a/x-pack/legacy/plugins/siem/server/lib/pinned_event/saved_object.ts +++ b/x-pack/legacy/plugins/siem/server/lib/pinned_event/saved_object.ts @@ -180,7 +180,7 @@ export class PinnedEvent { } } -const convertSavedObjectToSavedPinnedEvent = ( +export const convertSavedObjectToSavedPinnedEvent = ( savedObject: unknown, timelineVersion?: string | undefined | null ): PinnedEventSavedObject => diff --git a/x-pack/legacy/plugins/siem/server/lib/timeline/routes/__mocks__/request_responses.ts b/x-pack/legacy/plugins/siem/server/lib/timeline/routes/__mocks__/request_responses.ts new file mode 100644 index 00000000000000..eae1ece7e789d9 --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/timeline/routes/__mocks__/request_responses.ts @@ -0,0 +1,250 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { TIMELINE_EXPORT_URL } from '../../../../../common/constants'; +import { requestMock } from '../../../detection_engine/routes/__mocks__'; + +export const getExportTimelinesRequest = () => + requestMock.create({ + method: 'get', + path: TIMELINE_EXPORT_URL, + body: { + ids: ['f0e58720-57b6-11ea-b88d-3f1a31716be8', '890b8ae0-57df-11ea-a7c9-3976b7f1cb37'], + }, + }); + +export const mockTimelinesSavedObjects = () => ({ + saved_objects: [ + { + id: 'f0e58720-57b6-11ea-b88d-3f1a31716be8', + type: 'fakeType', + attributes: {}, + references: [], + }, + { + id: '890b8ae0-57df-11ea-a7c9-3976b7f1cb37', + type: 'fakeType', + attributes: {}, + references: [], + }, + ], +}); + +export const mockTimelines = () => ({ + saved_objects: [ + { + savedObjectId: 'f0e58720-57b6-11ea-b88d-3f1a31716be8', + version: 'Wzk0OSwxXQ==', + columns: [ + { + indexes: null, + name: null, + columnHeaderType: 'not-filtered', + id: '@timestamp', + searchable: null, + }, + { + indexes: null, + name: null, + columnHeaderType: 'not-filtered', + id: 'message', + searchable: null, + }, + { + indexes: null, + name: null, + columnHeaderType: 'not-filtered', + id: 'event.category', + searchable: null, + }, + { + indexes: null, + name: null, + columnHeaderType: 'not-filtered', + id: 'event.action', + searchable: null, + }, + { + indexes: null, + name: null, + columnHeaderType: 'not-filtered', + id: 'host.name', + searchable: null, + }, + { + indexes: null, + name: null, + columnHeaderType: 'not-filtered', + id: 'source.ip', + searchable: null, + }, + { + indexes: null, + name: null, + columnHeaderType: 'not-filtered', + id: 'destination.ip', + searchable: null, + }, + { + indexes: null, + name: null, + columnHeaderType: 'not-filtered', + id: 'user.name', + searchable: null, + }, + ], + dataProviders: [], + description: 'with a global note', + eventType: 'raw', + filters: [], + kqlMode: 'filter', + kqlQuery: { + filterQuery: { + kuery: { kind: 'kuery', expression: 'zeek.files.sha1 : * ' }, + serializedQuery: + '{"bool":{"should":[{"exists":{"field":"zeek.files.sha1"}}],"minimum_should_match":1}}', + }, + }, + title: 'test no.2', + dateRange: { start: 1582538951145, end: 1582625351145 }, + savedQueryId: null, + sort: { columnId: '@timestamp', sortDirection: 'desc' }, + created: 1582625382448, + createdBy: 'elastic', + updated: 1583741197521, + updatedBy: 'elastic', + }, + { + savedObjectId: '890b8ae0-57df-11ea-a7c9-3976b7f1cb37', + version: 'Wzk0NywxXQ==', + columns: [ + { + indexes: null, + name: null, + columnHeaderType: 'not-filtered', + id: '@timestamp', + searchable: null, + }, + { + indexes: null, + name: null, + columnHeaderType: 'not-filtered', + id: 'message', + searchable: null, + }, + { + indexes: null, + name: null, + columnHeaderType: 'not-filtered', + id: 'event.category', + searchable: null, + }, + { + indexes: null, + name: null, + columnHeaderType: 'not-filtered', + id: 'event.action', + searchable: null, + }, + { + indexes: null, + name: null, + columnHeaderType: 'not-filtered', + id: 'host.name', + searchable: null, + }, + { + indexes: null, + name: null, + columnHeaderType: 'not-filtered', + id: 'source.ip', + searchable: null, + }, + { + indexes: null, + name: null, + columnHeaderType: 'not-filtered', + id: 'destination.ip', + searchable: null, + }, + { + indexes: null, + name: null, + columnHeaderType: 'not-filtered', + id: 'user.name', + searchable: null, + }, + ], + dataProviders: [], + description: 'with an event note', + eventType: 'raw', + filters: [], + kqlMode: 'filter', + kqlQuery: { + filterQuery: { + serializedQuery: + '{"bool":{"should":[{"exists":{"field":"zeek.files.sha1"}}],"minimum_should_match":1}}', + kuery: { expression: 'zeek.files.sha1 : * ', kind: 'kuery' }, + }, + }, + title: 'test no.3', + dateRange: { start: 1582538951145, end: 1582625351145 }, + savedQueryId: null, + sort: { columnId: '@timestamp', sortDirection: 'desc' }, + created: 1582642817439, + createdBy: 'elastic', + updated: 1583741175216, + updatedBy: 'elastic', + }, + ], +}); + +export const mockNotesSavedObjects = () => ({ + saved_objects: [ + { + id: 'eb3f3930-61dc-11ea-8a49-e77254c5b742', + type: 'fakeType', + attributes: {}, + references: [], + }, + { + id: '706e7510-5d52-11ea-8f07-0392944939c1', + type: 'fakeType', + attributes: {}, + references: [], + }, + ], +}); + +export const mockNotes = () => ({ + saved_objects: [ + { + noteId: 'eb3f3930-61dc-11ea-8a49-e77254c5b742', + version: 'Wzk1MCwxXQ==', + note: 'Global note', + timelineId: 'f0e58720-57b6-11ea-b88d-3f1a31716be8', + created: 1583741205473, + createdBy: 'elastic', + updated: 1583741205473, + updatedBy: 'elastic', + }, + { + noteId: '706e7510-5d52-11ea-8f07-0392944939c1', + version: 'WzEwMiwxXQ==', + eventId: '6HW_eHABMQha2n6bHvQ0', + note: 'this is a note!!', + timelineId: '890b8ae0-57df-11ea-a7c9-3976b7f1cb37', + created: 1583241924223, + createdBy: 'elastic', + updated: 1583241924223, + updatedBy: 'elastic', + }, + ], +}); + +export const mockPinnedEvents = () => ({ + saved_objects: [], +}); diff --git a/x-pack/legacy/plugins/siem/server/lib/timeline/routes/export_timelines_route.test.ts b/x-pack/legacy/plugins/siem/server/lib/timeline/routes/export_timelines_route.test.ts new file mode 100644 index 00000000000000..fe434b53992124 --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/timeline/routes/export_timelines_route.test.ts @@ -0,0 +1,97 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { + mockTimelines, + mockNotes, + mockTimelinesSavedObjects, + mockPinnedEvents, + getExportTimelinesRequest, +} from './__mocks__/request_responses'; +import { exportTimelinesRoute } from './export_timelines_route'; +import { + serverMock, + requestContextMock, + requestMock, +} from '../../detection_engine/routes/__mocks__'; +import { TIMELINE_EXPORT_URL } from '../../../../common/constants'; +import { convertSavedObjectToSavedNote } from '../../note/saved_object'; +import { convertSavedObjectToSavedPinnedEvent } from '../../pinned_event/saved_object'; +import { convertSavedObjectToSavedTimeline } from '../convert_saved_object_to_savedtimeline'; +jest.mock('../convert_saved_object_to_savedtimeline', () => { + return { + convertSavedObjectToSavedTimeline: jest.fn(), + }; +}); + +jest.mock('../../note/saved_object', () => { + return { + convertSavedObjectToSavedNote: jest.fn(), + }; +}); + +jest.mock('../../pinned_event/saved_object', () => { + return { + convertSavedObjectToSavedPinnedEvent: jest.fn(), + }; +}); +describe('export timelines', () => { + let server: ReturnType; + let { clients, context } = requestContextMock.createTools(); + const config = jest.fn().mockImplementation(() => { + return { + get: () => { + return 100; + }, + has: jest.fn(), + }; + }); + + beforeEach(() => { + server = serverMock.create(); + ({ clients, context } = requestContextMock.createTools()); + + clients.savedObjectsClient.bulkGet.mockResolvedValue(mockTimelinesSavedObjects()); + + ((convertSavedObjectToSavedTimeline as unknown) as jest.Mock).mockReturnValue(mockTimelines()); + ((convertSavedObjectToSavedNote as unknown) as jest.Mock).mockReturnValue(mockNotes()); + ((convertSavedObjectToSavedPinnedEvent as unknown) as jest.Mock).mockReturnValue( + mockPinnedEvents() + ); + exportTimelinesRoute(server.router, config); + }); + + describe('status codes', () => { + test('returns 200 when finding selected timelines', async () => { + const response = await server.inject(getExportTimelinesRequest(), context); + expect(response.status).toEqual(200); + }); + + test('catch error when status search throws error', async () => { + clients.savedObjectsClient.bulkGet.mockReset(); + clients.savedObjectsClient.bulkGet.mockRejectedValue(new Error('Test error')); + const response = await server.inject(getExportTimelinesRequest(), context); + expect(response.status).toEqual(500); + expect(response.body).toEqual({ + message: 'Test error', + status_code: 500, + }); + }); + }); + + describe('request validation', () => { + test('disallows singular id query param', async () => { + const request = requestMock.create({ + method: 'get', + path: TIMELINE_EXPORT_URL, + body: { id: 'someId' }, + }); + const result = server.validate(request); + + expect(result.badRequest).toHaveBeenCalledWith('"id" is not allowed'); + }); + }); +}); diff --git a/x-pack/legacy/plugins/siem/server/lib/timeline/routes/export_timelines_route.ts b/x-pack/legacy/plugins/siem/server/lib/timeline/routes/export_timelines_route.ts new file mode 100644 index 00000000000000..3ded959aced363 --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/timeline/routes/export_timelines_route.ts @@ -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; + * you may not use this file except in compliance with the Elastic License. + */ + +import { set as _set } from 'lodash/fp'; +import { IRouter } from '../../../../../../../../src/core/server'; +import { LegacyServices } from '../../../types'; +import { ExportTimelineRequestParams } from '../types'; + +import { + transformError, + buildRouteValidation, + buildSiemResponse, +} from '../../detection_engine/routes/utils'; +import { TIMELINE_EXPORT_URL } from '../../../../common/constants'; + +import { + exportTimelinesSchema, + exportTimelinesQuerySchema, +} from './schemas/export_timelines_schema'; + +import { getExportTimelineByObjectIds } from './utils'; + +export const exportTimelinesRoute = (router: IRouter, config: LegacyServices['config']) => { + router.post( + { + path: TIMELINE_EXPORT_URL, + validate: { + query: buildRouteValidation( + exportTimelinesQuerySchema + ), + body: buildRouteValidation(exportTimelinesSchema), + }, + options: { + tags: ['access:siem'], + }, + }, + async (context, request, response) => { + try { + const siemResponse = buildSiemResponse(response); + const savedObjectsClient = context.core.savedObjects.client; + const exportSizeLimit = config().get('savedObjects.maxImportExportSize'); + if (request.body?.ids != null && request.body.ids.length > exportSizeLimit) { + return siemResponse.error({ + statusCode: 400, + body: `Can't export more than ${exportSizeLimit} timelines`, + }); + } + + const responseBody = await getExportTimelineByObjectIds({ + client: savedObjectsClient, + request, + }); + + return response.ok({ + headers: { + 'Content-Disposition': `attachment; filename="${request.query.file_name}"`, + 'Content-Type': 'application/ndjson', + }, + body: responseBody, + }); + } catch (err) { + const error = transformError(err); + const siemResponse = buildSiemResponse(response); + + return siemResponse.error({ + body: error.message, + statusCode: error.statusCode, + }); + } + } + ); +}; diff --git a/x-pack/legacy/plugins/siem/server/lib/timeline/routes/schemas/export_timelines_schema.ts b/x-pack/legacy/plugins/siem/server/lib/timeline/routes/schemas/export_timelines_schema.ts new file mode 100644 index 00000000000000..04edbbd7046c93 --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/timeline/routes/schemas/export_timelines_schema.ts @@ -0,0 +1,20 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import Joi from 'joi'; + +/* eslint-disable @typescript-eslint/camelcase */ +import { ids, exclude_export_details, file_name } from './schemas'; +/* eslint-disable @typescript-eslint/camelcase */ + +export const exportTimelinesSchema = Joi.object({ + ids, +}).min(1); + +export const exportTimelinesQuerySchema = Joi.object({ + file_name: file_name.default('export.ndjson'), + exclude_export_details: exclude_export_details.default(false), +}); diff --git a/x-pack/legacy/plugins/siem/server/lib/timeline/routes/schemas/schemas.ts b/x-pack/legacy/plugins/siem/server/lib/timeline/routes/schemas/schemas.ts new file mode 100644 index 00000000000000..67697c347634e1 --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/timeline/routes/schemas/schemas.ts @@ -0,0 +1,13 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ +import Joi from 'joi'; + +/* eslint-disable @typescript-eslint/camelcase */ + +export const ids = Joi.array().items(Joi.string()); + +export const exclude_export_details = Joi.boolean(); +export const file_name = Joi.string(); diff --git a/x-pack/legacy/plugins/siem/server/lib/timeline/routes/utils.ts b/x-pack/legacy/plugins/siem/server/lib/timeline/routes/utils.ts new file mode 100644 index 00000000000000..066862e025833f --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/timeline/routes/utils.ts @@ -0,0 +1,187 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ +import { set as _set } from 'lodash/fp'; +import { + SavedObjectsFindOptions, + SavedObjectsFindResponse, +} from '../../../../../../../../src/core/server'; + +import { + ExportTimelineSavedObjectsClient, + ExportTimelineRequest, + ExportedNotes, + TimelineSavedObject, + ExportedTimelines, +} from '../types'; +import { + timelineSavedObjectType, + noteSavedObjectType, + pinnedEventSavedObjectType, +} from '../../../saved_objects'; + +import { convertSavedObjectToSavedNote } from '../../note/saved_object'; +import { convertSavedObjectToSavedPinnedEvent } from '../../pinned_event/saved_object'; +import { convertSavedObjectToSavedTimeline } from '../convert_saved_object_to_savedtimeline'; +import { transformDataToNdjson } from '../../detection_engine/routes/rules/utils'; +import { NoteSavedObject } from '../../note/types'; +import { PinnedEventSavedObject } from '../../pinned_event/types'; + +const getAllSavedPinnedEvents = ( + pinnedEventsSavedObjects: SavedObjectsFindResponse +): PinnedEventSavedObject[] => { + return pinnedEventsSavedObjects != null + ? pinnedEventsSavedObjects.saved_objects.map(savedObject => + convertSavedObjectToSavedPinnedEvent(savedObject) + ) + : []; +}; + +const getPinnedEventsByTimelineId = ( + savedObjectsClient: ExportTimelineSavedObjectsClient, + timelineId: string +): Promise> => { + const options: SavedObjectsFindOptions = { + type: pinnedEventSavedObjectType, + search: timelineId, + searchFields: ['timelineId'], + }; + return savedObjectsClient.find(options); +}; + +const getAllSavedNote = ( + noteSavedObjects: SavedObjectsFindResponse +): NoteSavedObject[] => { + return noteSavedObjects != null + ? noteSavedObjects.saved_objects.map(savedObject => convertSavedObjectToSavedNote(savedObject)) + : []; +}; + +const getNotesByTimelineId = ( + savedObjectsClient: ExportTimelineSavedObjectsClient, + timelineId: string +): Promise> => { + const options: SavedObjectsFindOptions = { + type: noteSavedObjectType, + search: timelineId, + searchFields: ['timelineId'], + }; + + return savedObjectsClient.find(options); +}; + +const getGlobalEventNotesByTimelineId = (currentNotes: NoteSavedObject[]): ExportedNotes => { + const initialNotes: ExportedNotes = { + eventNotes: [], + globalNotes: [], + }; + + return ( + currentNotes.reduce((acc, note) => { + if (note.eventId == null) { + return { + ...acc, + globalNotes: [...acc.globalNotes, note], + }; + } else { + return { + ...acc, + eventNotes: [...acc.eventNotes, note], + }; + } + }, initialNotes) ?? initialNotes + ); +}; + +const getPinnedEventsIdsByTimelineId = ( + currentPinnedEvents: PinnedEventSavedObject[] +): string[] => { + return currentPinnedEvents.map(event => event.eventId) ?? []; +}; + +const getTimelines = async ( + savedObjectsClient: ExportTimelineSavedObjectsClient, + timelineIds: string[] +) => { + const savedObjects = await Promise.resolve( + savedObjectsClient.bulkGet( + timelineIds.reduce( + (acc, timelineId) => [...acc, { id: timelineId, type: timelineSavedObjectType }], + [] as Array<{ id: string; type: string }> + ) + ) + ); + + const timelineObjects: TimelineSavedObject[] | undefined = + savedObjects != null + ? savedObjects.saved_objects.map((savedObject: unknown) => { + return convertSavedObjectToSavedTimeline(savedObject); + }) + : []; + + return timelineObjects; +}; + +const getTimelinesFromObjects = async ( + savedObjectsClient: ExportTimelineSavedObjectsClient, + request: ExportTimelineRequest +): Promise => { + const timelines: TimelineSavedObject[] = await getTimelines(savedObjectsClient, request.body.ids); + // To Do for feature freeze + // if (timelines.length !== request.body.ids.length) { + // //figure out which is missing to tell user + // } + + const [notes, pinnedEventIds] = await Promise.all([ + Promise.all( + request.body.ids.map(timelineId => getNotesByTimelineId(savedObjectsClient, timelineId)) + ), + Promise.all( + request.body.ids.map(timelineId => + getPinnedEventsByTimelineId(savedObjectsClient, timelineId) + ) + ), + ]); + + const myNotes = notes.reduce( + (acc, note) => [...acc, ...getAllSavedNote(note)], + [] + ); + + const myPinnedEventIds = pinnedEventIds.reduce( + (acc, pinnedEventId) => [...acc, ...getAllSavedPinnedEvents(pinnedEventId)], + [] + ); + + const myResponse = request.body.ids.reduce((acc, timelineId) => { + const myTimeline = timelines.find(t => t.savedObjectId === timelineId); + if (myTimeline != null) { + const timelineNotes = myNotes.filter(n => n.timelineId === timelineId); + const timelinePinnedEventIds = myPinnedEventIds.filter(p => p.timelineId === timelineId); + return [ + ...acc, + { + ...myTimeline, + ...getGlobalEventNotesByTimelineId(timelineNotes), + pinnedEventIds: getPinnedEventsIdsByTimelineId(timelinePinnedEventIds), + }, + ]; + } + return acc; + }, []); + + return myResponse ?? []; +}; + +export const getExportTimelineByObjectIds = async ({ + client, + request, +}: { + client: ExportTimelineSavedObjectsClient; + request: ExportTimelineRequest; +}) => { + const timeline = await getTimelinesFromObjects(client, request); + return transformDataToNdjson(timeline); +}; diff --git a/x-pack/legacy/plugins/siem/server/lib/timeline/saved_object.ts b/x-pack/legacy/plugins/siem/server/lib/timeline/saved_object.ts index 4b78a7bd3d06d1..88d7fcdb681646 100644 --- a/x-pack/legacy/plugins/siem/server/lib/timeline/saved_object.ts +++ b/x-pack/legacy/plugins/siem/server/lib/timeline/saved_object.ts @@ -271,7 +271,7 @@ export const convertStringToBase64 = (text: string): string => Buffer.from(text) // then this interface does not allow types without index signature // this is limiting us with our type for now so the easy way was to use any -const timelineWithReduxProperties = ( +export const timelineWithReduxProperties = ( notes: NoteSavedObject[], pinnedEvents: PinnedEventSavedObject[], timeline: TimelineSavedObject, @@ -279,7 +279,9 @@ const timelineWithReduxProperties = ( ): TimelineSavedObject => ({ ...timeline, favorite: - timeline.favorite != null ? timeline.favorite.filter(fav => fav.userName === userName) : [], + timeline.favorite != null && userName != null + ? timeline.favorite.filter(fav => fav.userName === userName) + : [], eventIdToNoteIds: notes.filter(note => note.eventId != null), noteIds: notes .filter(note => note.eventId == null && note.noteId != null) diff --git a/x-pack/legacy/plugins/siem/server/lib/timeline/types.ts b/x-pack/legacy/plugins/siem/server/lib/timeline/types.ts index d757ea8049bc18..35bf86c17db7ea 100644 --- a/x-pack/legacy/plugins/siem/server/lib/timeline/types.ts +++ b/x-pack/legacy/plugins/siem/server/lib/timeline/types.ts @@ -9,8 +9,12 @@ import * as runtimeTypes from 'io-ts'; import { unionWithNullType } from '../framework'; -import { NoteSavedObjectToReturnRuntimeType } from '../note/types'; -import { PinnedEventToReturnSavedObjectRuntimeType } from '../pinned_event/types'; +import { NoteSavedObjectToReturnRuntimeType, NoteSavedObject } from '../note/types'; +import { + PinnedEventToReturnSavedObjectRuntimeType, + PinnedEventSavedObject, +} from '../pinned_event/types'; +import { SavedObjectsClient, KibanaRequest } from '../../../../../../../src/core/server'; /* * ColumnHeader Types @@ -199,3 +203,54 @@ export const AllTimelineSavedObjectRuntimeType = runtimeTypes.type({ export interface AllTimelineSavedObject extends runtimeTypes.TypeOf {} + +export interface ExportTimelineRequestParams { + body: { ids: string[] }; + query: { + file_name: string; + exclude_export_details: boolean; + }; +} + +export type ExportTimelineRequest = KibanaRequest< + unknown, + ExportTimelineRequestParams['query'], + ExportTimelineRequestParams['body'], + 'post' +>; + +export type ExportTimelineSavedObjectsClient = Pick< + SavedObjectsClient, + | 'get' + | 'errors' + | 'create' + | 'bulkCreate' + | 'delete' + | 'find' + | 'bulkGet' + | 'update' + | 'bulkUpdate' +>; + +export type ExportedGlobalNotes = Array>; +export type ExportedEventNotes = NoteSavedObject[]; + +export interface ExportedNotes { + eventNotes: ExportedEventNotes; + globalNotes: ExportedGlobalNotes; +} + +export type ExportedTimelines = TimelineSavedObject & + ExportedNotes & { + pinnedEventIds: string[]; + }; + +export interface BulkGetInput { + type: string; + id: string; +} + +export type NotesAndPinnedEventsByTimelineId = Record< + string, + { notes: NoteSavedObject[]; pinnedEvents: PinnedEventSavedObject[] } +>; diff --git a/x-pack/legacy/plugins/siem/server/routes/index.ts b/x-pack/legacy/plugins/siem/server/routes/index.ts index 08bdfc3aa5d4f5..08ff9208ce20bd 100644 --- a/x-pack/legacy/plugins/siem/server/routes/index.ts +++ b/x-pack/legacy/plugins/siem/server/routes/index.ts @@ -29,6 +29,7 @@ import { importRulesRoute } from '../lib/detection_engine/routes/rules/import_ru import { exportRulesRoute } from '../lib/detection_engine/routes/rules/export_rules_route'; import { findRulesStatusesRoute } from '../lib/detection_engine/routes/rules/find_rules_status_route'; import { getPrepackagedRulesStatusRoute } from '../lib/detection_engine/routes/rules/get_prepackaged_rules_status_route'; +import { exportTimelinesRoute } from '../lib/timeline/routes/export_timelines_route'; export const initRoutes = ( router: IRouter, @@ -54,6 +55,8 @@ export const initRoutes = ( importRulesRoute(router, config); exportRulesRoute(router, config); + exportTimelinesRoute(router, config); + findRulesStatusesRoute(router); // Detection Engine Signals routes that have the REST endpoints of /api/detection_engine/signals