From 0ce23d50b0248ee0e4692970d1eb2bfb3e06fcd2 Mon Sep 17 00:00:00 2001 From: Christos Nasikas Date: Wed, 1 Jul 2020 10:06:35 +0300 Subject: [PATCH] [7.x] [SIEM][Timeline] Reset fields based on timeline (#70209) (#70368) --- .../alerts/components/alerts_table/index.tsx | 1 + .../components/alerts_viewer/alerts_table.tsx | 1 + .../navigation/events_query_tab_body.tsx | 10 +++++++ .../components/fields_browser/header.tsx | 27 ++++--------------- .../components/manage_timeline/index.tsx | 5 ++++ 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/x-pack/plugins/security_solution/public/alerts/components/alerts_table/index.tsx b/x-pack/plugins/security_solution/public/alerts/components/alerts_table/index.tsx index ec088c111e3bb..98bb6434ddafd 100644 --- a/x-pack/plugins/security_solution/public/alerts/components/alerts_table/index.tsx +++ b/x-pack/plugins/security_solution/public/alerts/components/alerts_table/index.tsx @@ -333,6 +333,7 @@ export const AlertsTableComponent: React.FC = ({ initializeTimeline({ id: timelineId, documentType: i18n.ALERTS_DOCUMENT_TYPE, + defaultModel: alertsDefaultModel, footerText: i18n.TOTAL_COUNT_OF_ALERTS, loadingText: i18n.LOADING_ALERTS, title: i18n.ALERTS_TABLE_TITLE, diff --git a/x-pack/plugins/security_solution/public/common/components/alerts_viewer/alerts_table.tsx b/x-pack/plugins/security_solution/public/common/components/alerts_viewer/alerts_table.tsx index 6d5471404ab4d..6783fcbd17582 100644 --- a/x-pack/plugins/security_solution/public/common/components/alerts_viewer/alerts_table.tsx +++ b/x-pack/plugins/security_solution/public/common/components/alerts_viewer/alerts_table.tsx @@ -75,6 +75,7 @@ const AlertsTableComponent: React.FC = ({ initializeTimeline({ id: timelineId, documentType: i18n.ALERTS_DOCUMENT_TYPE, + defaultModel: alertsDefaultModel, footerText: i18n.TOTAL_COUNT_OF_ALERTS, title: i18n.ALERTS_TABLE_TITLE, unit: i18n.UNIT, diff --git a/x-pack/plugins/security_solution/public/hosts/pages/navigation/events_query_tab_body.tsx b/x-pack/plugins/security_solution/public/hosts/pages/navigation/events_query_tab_body.tsx index 574e2ec4ae250..64cfacaeaf6dc 100644 --- a/x-pack/plugins/security_solution/public/hosts/pages/navigation/events_query_tab_body.tsx +++ b/x-pack/plugins/security_solution/public/hosts/pages/navigation/events_query_tab_body.tsx @@ -17,6 +17,7 @@ import { import { MatrixHistogramContainer } from '../../../common/components/matrix_histogram'; import * as i18n from '../translations'; import { HistogramType } from '../../../graphql/types'; +import { useManageTimeline } from '../../../timelines/components/manage_timeline'; const EVENTS_HISTOGRAM_ID = 'eventsOverTimeQuery'; @@ -55,6 +56,15 @@ export const EventsQueryTabBody = ({ setQuery, startDate, }: HostsComponentsQueryProps) => { + const { initializeTimeline } = useManageTimeline(); + + useEffect(() => { + initializeTimeline({ + id: TimelineId.hostsPageEvents, + defaultModel: eventsDefaultModel, + }); + }, [initializeTimeline]); + useEffect(() => { return () => { if (deleteQuery) { diff --git a/x-pack/plugins/security_solution/public/timelines/components/fields_browser/header.tsx b/x-pack/plugins/security_solution/public/timelines/components/fields_browser/header.tsx index eab06ef50b3b5..9ad460db4c7b7 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/fields_browser/header.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/fields_browser/header.tsx @@ -12,14 +12,10 @@ import { EuiText, EuiTitle, } from '@elastic/eui'; -import React, { useCallback, useMemo } from 'react'; +import React, { useCallback } from 'react'; import styled from 'styled-components'; import { BrowserFields } from '../../../common/containers/source'; -import { alertsHeaders } from '../../../alerts/components/alerts_table/default_config'; -import { alertsHeaders as externalAlertsHeaders } from '../../../common/components/alerts_viewer/default_headers'; -import { defaultHeaders as eventsDefaultHeaders } from '../../../common/components/events_viewer/default_headers'; -import { defaultHeaders } from '../timeline/body/column_headers/default_headers'; import { OnUpdateColumns } from '../timeline/events'; import { getFieldBrowserSearchInputClassName, getFieldCount, SEARCH_INPUT_WIDTH } from './helpers'; @@ -100,26 +96,13 @@ const TitleRow = React.memo<{ isEventViewer?: boolean; onOutsideClick: () => void; onUpdateColumns: OnUpdateColumns; -}>(({ id, isEventViewer, onOutsideClick, onUpdateColumns }) => { +}>(({ id, onOutsideClick, onUpdateColumns }) => { const { getManageTimelineById } = useManageTimeline(); - const documentType = useMemo(() => getManageTimelineById(id).documentType, [ - getManageTimelineById, - id, - ]); const handleResetColumns = useCallback(() => { - let resetDefaultHeaders = defaultHeaders; - if (isEventViewer) { - if (documentType.toLocaleLowerCase() === 'externalAlerts') { - resetDefaultHeaders = externalAlertsHeaders; - } else if (documentType.toLocaleLowerCase() === 'alerts') { - resetDefaultHeaders = alertsHeaders; - } else { - resetDefaultHeaders = eventsDefaultHeaders; - } - } - onUpdateColumns(resetDefaultHeaders); + const timeline = getManageTimelineById(id); + onUpdateColumns(timeline.defaultModel.columns); onOutsideClick(); - }, [isEventViewer, onOutsideClick, onUpdateColumns, documentType]); + }, [id, onUpdateColumns, onOutsideClick, getManageTimelineById]); return (