Skip to content

Commit

Permalink
Move TimelineId to common folder
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Jun 15, 2020
1 parent 1c17b14 commit f81b1c1
Show file tree
Hide file tree
Showing 19 changed files with 116 additions and 104 deletions.
26 changes: 26 additions & 0 deletions x-pack/plugins/security_solution/common/types/timeline/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,32 @@ export interface SavedTimeline extends runtimeTypes.TypeOf<typeof SavedTimelineR

export interface SavedTimelineNote extends runtimeTypes.TypeOf<typeof SavedTimelineRuntimeType> {}

/*
* Timeline IDs
*/

export enum TimelineId {
hostsPageEvents = 'hosts-page-events',
hostsPageExternalAlerts = 'hosts-page-external-alerts',
alertsRulesDetailsPage = 'alerts-rules-details-page',
alertsPage = 'alerts-page',
networkPageExternalAlerts = 'network-page-external-alerts',
active = 'timeline-1',
test = 'test', // Reserved for testing purposes
}

export const TimelineIdLiteralRt = runtimeTypes.union([
runtimeTypes.literal(TimelineId.hostsPageEvents),
runtimeTypes.literal(TimelineId.hostsPageExternalAlerts),
runtimeTypes.literal(TimelineId.alertsRulesDetailsPage),
runtimeTypes.literal(TimelineId.alertsPage),
runtimeTypes.literal(TimelineId.networkPageExternalAlerts),
runtimeTypes.literal(TimelineId.active),
runtimeTypes.literal(TimelineId.test),
]);

export type TimelineIdLiteral = runtimeTypes.TypeOf<typeof TimelineIdLiteralRt>;

/**
* Timeline Saved object type with metadata
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
import React from 'react';
import { shallow } from 'enzyme';

import { TimelineId } from '../../../../common/types/timeline';
import { AlertsTableComponent } from './index';

describe('AlertsTableComponent', () => {
it('renders correctly', () => {
const wrapper = shallow(
<AlertsTableComponent
timelineId="hosts-page-events"
timelineId={TimelineId.test}
canUserCRUD
hasIndexWrite
from={0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { connect, ConnectedProps } from 'react-redux';
import { Dispatch } from 'redux';

import { Filter, esQuery } from '../../../../../../../src/plugins/data/public';
import { TimelineIdLiteral } from '../../../../common/types/timeline';
import { useFetchIndexPatterns } from '../../../alerts/containers/detection_engine/rules/fetch_index_patterns';
import { StatefulEventsViewer } from '../../../common/components/events_viewer';
import { HeaderSection } from '../../../common/components/header_section';
Expand Down Expand Up @@ -47,15 +48,14 @@ import {
UpdateAlertsStatusProps,
} from './types';
import { dispatchUpdateTimeline } from '../../../timelines/components/open_timeline/helpers';
import { TimelineId } from '../../../timelines/containers/local_storage/types';
import {
useStateToaster,
displaySuccessToast,
displayErrorToast,
} from '../../../common/components/toasters';

interface OwnProps {
timelineId: TimelineId;
timelineId: TimelineIdLiteral;
canUserCRUD: boolean;
defaultFilters?: Filter[];
hasIndexWrite: boolean;
Expand Down
9 changes: 4 additions & 5 deletions x-pack/plugins/security_solution/public/alerts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@

import { Storage } from '../../../../../src/plugins/kibana_utils/public';
import { getTimelinesInStorageByIds } from '../timelines/containers/local_storage';
import { TimelineId } from '../timelines/containers/local_storage/types';
import { TimelineIdLiteral, TimelineId } from '../../common/types/timeline';
import { getAlertsRoutes } from './routes';
import { SecuritySubPlugin } from '../app/types';
import { ALERTS_RULES_DETAILS_PAGE_TIMELINE_ID, ALERTS_TIMELINE_ID } from './constants';

const ALERTS_TIMELINE_IDS: TimelineId[] = [
ALERTS_RULES_DETAILS_PAGE_TIMELINE_ID,
ALERTS_TIMELINE_ID,
const ALERTS_TIMELINE_IDS: TimelineIdLiteral[] = [
TimelineId.alertsRulesDetailsPage,
TimelineId.alertsPage,
];

export class Alerts {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import React, { useCallback, useMemo } from 'react';
import { StickyContainer } from 'react-sticky';
import { connect, ConnectedProps } from 'react-redux';

import { TimelineId } from '../../../../common/types/timeline';
import { GlobalTime } from '../../../common/containers/global_time';
import {
indicesExistOrDataTemporarilyUnavailable,
Expand Down Expand Up @@ -36,7 +37,6 @@ import { DetectionEngineNoIndex } from './detection_engine_no_signal_index';
import { DetectionEngineHeaderPage } from '../../components/detection_engine_header_page';
import { DetectionEngineUserUnauthenticated } from './detection_engine_user_unauthenticated';
import * as i18n from './translations';
import { ALERTS_TIMELINE_ID } from '../../constants';

export const DetectionEnginePageComponent: React.FC<PropsFromRedux> = ({
filters,
Expand Down Expand Up @@ -139,7 +139,7 @@ export const DetectionEnginePageComponent: React.FC<PropsFromRedux> = ({
/>
<EuiSpacer size="l" />
<AlertsTable
timelineId={ALERTS_TIMELINE_ID}
timelineId={TimelineId.alertsPage}
loading={loading}
hasIndexWrite={hasIndexWrite ?? false}
canUserCRUD={(canUserCRUD ?? false) && (hasEncryptionKey ?? false)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { Redirect, useParams } from 'react-router-dom';
import { StickyContainer } from 'react-sticky';
import { connect, ConnectedProps } from 'react-redux';

import { TimelineId } from '../../../../../../common/types/timeline';
import { UpdateDateRange } from '../../../../../common/components/charts/common';
import { FiltersGlobal } from '../../../../../common/components/filters_global';
import { FormattedDate } from '../../../../../common/components/formatted_date';
Expand Down Expand Up @@ -74,7 +75,6 @@ import { useMlCapabilities } from '../../../../../common/components/ml_popover/h
import { hasMlAdminPermissions } from '../../../../../../common/machine_learning/has_ml_admin_permissions';
import { ExceptionsViewer } from '../../../../../common/components/exceptions/viewer';
import { ExceptionListType } from '../../../../../common/components/exceptions/types';
import { ALERTS_RULES_DETAILS_PAGE_TIMELINE_ID } from '../../../../constants';

enum RuleDetailTabs {
alerts = 'alerts',
Expand Down Expand Up @@ -387,7 +387,7 @@ export const RuleDetailsPageComponent: FC<PropsFromRedux> = ({
<EuiSpacer />
{ruleId != null && (
<AlertsTable
timelineId={ALERTS_RULES_DETAILS_PAGE_TIMELINE_ID}
timelineId={TimelineId.alertsRulesDetailsPage}
canUserCRUD={canUserCRUD ?? false}
defaultFilters={alertDefaultFilters}
hasIndexWrite={hasIndexWrite ?? false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import React, { useEffect, useMemo } from 'react';

import { Filter } from '../../../../../../../src/plugins/data/public';
import { TimelineIdLiteral } from '../../../../common/types/timeline';
import { StatefulEventsViewer } from '../events_viewer';
import { alertsDefaultModel } from './default_headers';
import { useManageTimeline } from '../../../timelines/components/manage_timeline';
import { TimelineId } from '../../../timelines/containers/local_storage/types';
import * as i18n from './translations';
export interface OwnProps {
end: number;
Expand Down Expand Up @@ -52,7 +52,7 @@ const defaultAlertsFilters: Filter[] = [
];

interface Props {
timelineId: TimelineId;
timelineId: TimelineIdLiteral;
endDate: number;
startDate: number;
pageFilters?: Filter[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
*/

import { Filter } from '../../../../../../../src/plugins/data/public';
import { TimelineIdLiteral } from '../../../../common/types/timeline';
import { HostsComponentsQueryProps } from '../../../hosts/pages/navigation/types';
import { NetworkComponentQueryProps } from '../../../network/pages/navigation/types';
import { TimelineId } from '../../../timelines/containers/local_storage/types';
import { MatrixHistogramOption } from '../matrix_histogram/types';

type CommonQueryProps = HostsComponentsQueryProps | NetworkComponentQueryProps;
Expand All @@ -17,7 +17,7 @@ export interface AlertsComponentsProps
CommonQueryProps,
'deleteQuery' | 'endDate' | 'filterQuery' | 'skip' | 'setQuery' | 'startDate' | 'type'
> {
timelineId: TimelineId;
timelineId: TimelineIdLiteral;
pageFilters: Filter[];
stackByOptions?: MatrixHistogramOption[];
defaultFilters?: Filter[];
Expand Down
8 changes: 0 additions & 8 deletions x-pack/plugins/security_solution/public/hosts/constants.ts

This file was deleted.

8 changes: 5 additions & 3 deletions x-pack/plugins/security_solution/public/hosts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
*/

import { Storage } from '../../../../../src/plugins/kibana_utils/public';
import { TimelineIdLiteral, TimelineId } from '../../common/types/timeline';
import { SecuritySubPluginWithStore } from '../app/types';
import { getTimelinesInStorageByIds } from '../timelines/containers/local_storage';
import { TimelineId } from '../timelines/containers/local_storage/types';
import { getHostsRoutes } from './routes';
import { initialHostsState, hostsReducer, HostsState } from './store';
import { EVENTS_TIMELINE_ID, EXTERNAL_ALERTS_TIMELINE_ID } from './constants';

const HOST_TIMELINE_IDS: TimelineId[] = [EVENTS_TIMELINE_ID, EXTERNAL_ALERTS_TIMELINE_ID];
const HOST_TIMELINE_IDS: TimelineIdLiteral[] = [
TimelineId.hostsPageEvents,
TimelineId.hostsPageExternalAlerts,
];

export class Hosts {
public setup() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
import React, { useMemo } from 'react';

import { Filter } from '../../../../../../../src/plugins/data/public';
import { TimelineId } from '../../../../common/types/timeline';
import { AlertsView } from '../../../common/components/alerts_viewer';
import { AlertsComponentQueryProps } from './types';

const ALERTS_TABLE_ID = 'hosts-page-external-alerts';

export const filterHostData: Filter[] = [
{
query: {
Expand Down Expand Up @@ -50,7 +49,13 @@ export const HostAlertsQueryTabBody = React.memo((alertsProps: AlertsComponentQu
[pageFilters]
);

return <AlertsView timelineId={ALERTS_TABLE_ID} {...rest} pageFilters={hostPageFilters} />;
return (
<AlertsView
timelineId={TimelineId.hostsPageExternalAlerts}
{...rest}
pageFilters={hostPageFilters}
/>
);
});

HostAlertsQueryTabBody.displayName = 'HostAlertsQueryTabBody';
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import React, { useEffect } from 'react';
import { TimelineId } from '../../../../common/types/timeline';
import { StatefulEventsViewer } from '../../../common/components/events_viewer';
import { HostsComponentsQueryProps } from './types';
import { hostsModel } from '../../store';
Expand All @@ -17,7 +18,6 @@ import { MatrixHistogramContainer } from '../../../common/components/matrix_hist
import * as i18n from '../translations';
import { HistogramType } from '../../../graphql/types';

const HOSTS_PAGE_TIMELINE_ID = 'hosts-page-events';
const EVENTS_HISTOGRAM_ID = 'eventsOverTimeQuery';

export const eventsStackByOptions: MatrixHistogramOption[] = [
Expand Down Expand Up @@ -78,7 +78,7 @@ export const EventsQueryTabBody = ({
<StatefulEventsViewer
defaultModel={eventsDefaultModel}
end={endDate}
id={HOSTS_PAGE_TIMELINE_ID}
id={TimelineId.hostsPageEvents}
start={startDate}
pageFilters={pageFilters}
/>
Expand Down
7 changes: 0 additions & 7 deletions x-pack/plugins/security_solution/public/network/constants.ts

This file was deleted.

6 changes: 2 additions & 4 deletions x-pack/plugins/security_solution/public/network/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { Storage } from '../../../../../src/plugins/kibana_utils/public';
import { SecuritySubPluginWithStore } from '../app/types';
import { getNetworkRoutes } from './routes';
import { initialNetworkState, networkReducer, NetworkState } from './store';
import { TimelineId } from '../../common/types/timeline';
import { getTimelinesInStorageByIds } from '../timelines/containers/local_storage';
import { NETWORK_PAGE_EXTERNAL_EVENTS_TIMELINE_ID } from './constants';

export class Network {
public setup() {}
Expand All @@ -18,9 +18,7 @@ export class Network {
return {
routes: getNetworkRoutes(),
storageTimelines: {
timelineById: getTimelinesInStorageByIds(storage, [
NETWORK_PAGE_EXTERNAL_EVENTS_TIMELINE_ID,
]),
timelineById: getTimelinesInStorageByIds(storage, [TimelineId.networkPageExternalAlerts]),
},
store: {
initialState: { network: initialNetworkState },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import React from 'react';

import { Filter } from '../../../../../../../src/plugins/data/common/es_query';
import { TimelineId } from '../../../../common/types/timeline';
import { AlertsView } from '../../../common/components/alerts_viewer';
import { NETWORK_PAGE_EXTERNAL_EVENTS_TIMELINE_ID } from '../../constants';
import { NetworkComponentQueryProps } from './types';

export const filterNetworkData: Filter[] = [
Expand Down Expand Up @@ -64,7 +64,7 @@ export const filterNetworkData: Filter[] = [

export const NetworkAlertsQueryTabBody = React.memo((alertsProps: NetworkComponentQueryProps) => (
<AlertsView
timelineId={NETWORK_PAGE_EXTERNAL_EVENTS_TIMELINE_ID}
timelineId={TimelineId.networkPageExternalAlerts}
{...alertsProps}
pageFilters={filterNetworkData}
/>
Expand Down
Loading

0 comments on commit f81b1c1

Please sign in to comment.