Skip to content

Commit

Permalink
[SIEM][Timeline] Reset fields based on timeline (elastic#70209)
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas authored and Bamieh committed Jul 1, 2020
1 parent 09c87e0 commit e10c303
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ export const AlertsTableComponent: React.FC<AlertsTableComponentProps> = ({
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const AlertsTableComponent: React.FC<Props> = ({
initializeTimeline({
id: timelineId,
documentType: i18n.ALERTS_DOCUMENT_TYPE,
defaultModel: alertsDefaultModel,
footerText: i18n.TOTAL_COUNT_OF_ALERTS,
title: i18n.ALERTS_TABLE_TITLE,
unit: i18n.UNIT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 (
<EuiFlexGroup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ import { noop } from 'lodash/fp';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { FilterManager } from '../../../../../../../src/plugins/data/public/query/filter_manager';
import { TimelineRowAction } from '../timeline/body/actions';
import { SubsetTimelineModel } from '../../store/timeline/model';
import * as i18n from '../../../common/components/events_viewer/translations';
import * as i18nF from '../timeline/footer/translations';
import { timelineDefaults as timelineDefaultModel } from '../../store/timeline/defaults';

interface ManageTimelineInit {
documentType?: string;
defaultModel?: SubsetTimelineModel;
footerText?: string;
id: string;
indexToAdd?: string[] | null;
Expand All @@ -25,6 +28,7 @@ interface ManageTimelineInit {

interface ManageTimeline {
documentType: string;
defaultModel: SubsetTimelineModel;
filterManager?: FilterManager;
footerText: string;
id: string;
Expand Down Expand Up @@ -66,6 +70,7 @@ type ActionManageTimeline =

export const timelineDefaults = {
indexToAdd: null,
defaultModel: timelineDefaultModel,
loadingText: i18n.LOADING_EVENTS,
footerText: i18nF.TOTAL_COUNT_OF_EVENTS,
documentType: i18nF.TOTAL_COUNT_OF_EVENTS,
Expand Down

0 comments on commit e10c303

Please sign in to comment.