From d784e05231cdec444d87551e7b900958abb5ac1d Mon Sep 17 00:00:00 2001 From: Xavier Mouligneau <189600+XavierM@users.noreply.github.com> Date: Mon, 11 May 2020 17:01:50 -0400 Subject: [PATCH] fix types --- x-pack/plugins/siem/public/alerts/index.ts | 5 ++- .../detection_engine/detection_engine.tsx | 6 +--- .../detection_engine/rules/details/index.tsx | 6 +--- x-pack/plugins/siem/public/app/app.tsx | 25 ++++---------- x-pack/plugins/siem/public/app/types.ts | 33 ++++++++++++++++--- x-pack/plugins/siem/public/cases/index.ts | 5 ++- .../components/matrix_histogram/index.tsx | 10 ++---- .../siem/public/common/store/reducer.ts | 8 ++--- .../plugins/siem/public/common/store/store.ts | 2 +- x-pack/plugins/siem/public/hosts/index.ts | 4 +-- .../hosts/pages/details/details_tabs.tsx | 6 +--- .../siem/public/hosts/pages/details/index.tsx | 6 +--- .../plugins/siem/public/hosts/pages/hosts.tsx | 6 +--- .../siem/public/hosts/pages/hosts_tabs.tsx | 6 +--- x-pack/plugins/siem/public/network/index.ts | 4 +-- .../pages/navigation/network_routes.tsx | 6 +--- .../siem/public/network/pages/network.tsx | 6 +--- .../components/signals_by_category/index.tsx | 6 +--- x-pack/plugins/siem/public/overview/index.ts | 5 ++- x-pack/plugins/siem/public/plugin.tsx | 31 ++++++++--------- x-pack/plugins/siem/public/timelines/index.ts | 4 +-- 21 files changed, 75 insertions(+), 115 deletions(-) diff --git a/x-pack/plugins/siem/public/alerts/index.ts b/x-pack/plugins/siem/public/alerts/index.ts index cdf9696634a2..c1501419a1cf 100644 --- a/x-pack/plugins/siem/public/alerts/index.ts +++ b/x-pack/plugins/siem/public/alerts/index.ts @@ -5,15 +5,14 @@ */ import { getAlertsRoutes } from './routes'; -import { SecuritySubPlugins } from '../app/types'; +import { SecuritySubPlugin } from '../app/types'; export class Alerts { public setup() {} - public start(): SecuritySubPlugins { + public start(): SecuritySubPlugin { return { routes: getAlertsRoutes(), - store: {}, }; } } diff --git a/x-pack/plugins/siem/public/alerts/pages/detection_engine/detection_engine.tsx b/x-pack/plugins/siem/public/alerts/pages/detection_engine/detection_engine.tsx index a83a85678bd0..652debf259b0 100644 --- a/x-pack/plugins/siem/public/alerts/pages/detection_engine/detection_engine.tsx +++ b/x-pack/plugins/siem/public/alerts/pages/detection_engine/detection_engine.tsx @@ -82,11 +82,7 @@ export const DetectionEnginePageComponent: React.FC = ({ const [lastSignals] = useSignalInfo({}); const updateDateRangeCallback = useCallback( - ({ x }) => { - if (!x) { - return; - } - const [min, max] = x; + (min: number, max: number) => { setAbsoluteRangeDatePicker({ id: 'global', from: min, to: max }); }, [setAbsoluteRangeDatePicker] diff --git a/x-pack/plugins/siem/public/alerts/pages/detection_engine/rules/details/index.tsx b/x-pack/plugins/siem/public/alerts/pages/detection_engine/rules/details/index.tsx index fd43de726b76..15e63884572f 100644 --- a/x-pack/plugins/siem/public/alerts/pages/detection_engine/rules/details/index.tsx +++ b/x-pack/plugins/siem/public/alerts/pages/detection_engine/rules/details/index.tsx @@ -211,11 +211,7 @@ export const RuleDetailsPageComponent: FC = ({ ]); const updateDateRangeCallback = useCallback( - ({ x }) => { - if (!x) { - return; - } - const [min, max] = x; + (min: number, max: number) => { setAbsoluteRangeDatePicker({ id: 'global', from: min, to: max }); }, [setAbsoluteRangeDatePicker] diff --git a/x-pack/plugins/siem/public/app/app.tsx b/x-pack/plugins/siem/public/app/app.tsx index 5b4bfd5b4bd7..7aef91380b52 100644 --- a/x-pack/plugins/siem/public/app/app.tsx +++ b/x-pack/plugins/siem/public/app/app.tsx @@ -26,13 +26,7 @@ import { compose } from '../common/lib/compose/kibana_compose'; import { AppFrontendLibs, AppApolloClient } from '../common/lib/lib'; import { StartServices } from '../plugin'; import { PageRouter } from './routes'; -import { - createStore, - createInitialState, - SubPluginsInitReducer, - SubPluginsInitState, - SubPluginsState, -} from '../common/store'; +import { createStore, createInitialState } from '../common/store'; import { GlobalToaster, ManageGlobalToaster } from '../common/components/toasters'; import { MlCapabilitiesProvider } from '../common/components/ml/permissions/ml_capabilities_provider'; @@ -74,7 +68,7 @@ const AppPluginRootComponent: React.FC = ({ const AppPluginRoot = memo(AppPluginRootComponent); interface StartAppComponent extends AppFrontendLibs { - subPlugins: SecuritySubPlugins; + subPlugins: SecuritySubPlugins; } const StartAppComponent: FC = ({ subPlugins, ...libs }) => { @@ -83,16 +77,12 @@ const StartAppComponent: FC = ({ subPlugins, ...libs }) => { const history = createHashHistory(); const libs$ = new BehaviorSubject(libs); - const initSubPluginsState = ((subPluginsStore?.initialState ?? - {}) as unknown) as SubPluginsInitState; - const initSubPluginsReducer = ((subPluginsStore?.reducer ?? - {}) as unknown) as SubPluginsInitReducer; - const store = createStore( - createInitialState(initSubPluginsState), - initSubPluginsReducer, + createInitialState(subPluginsStore.initialState), + subPluginsStore.reducer, libs$.pipe(pluck('apolloClient')) ); + const [darkMode] = useUiSetting$(DEFAULT_DARK_MODE); const theme = useMemo( () => ({ @@ -132,10 +122,7 @@ const SiemAppComponent: React.FC = ({ services, subPlugin ...services, }} > - } - {...compose(services)} - /> + ); diff --git a/x-pack/plugins/siem/public/app/types.ts b/x-pack/plugins/siem/public/app/types.ts index 94622ded37f7..5fe4b5a8d822 100644 --- a/x-pack/plugins/siem/public/app/types.ts +++ b/x-pack/plugins/siem/public/app/types.ts @@ -7,6 +7,9 @@ import { Reducer, AnyAction } from 'redux'; import { NavTab } from '../common/components/navigation/types'; +import { HostsState } from '../hosts/store'; +import { NetworkState } from '../network/store'; +import { TimelineState } from '../timelines/store/timeline/types'; export enum SiemPageName { overview = 'overview', @@ -27,12 +30,32 @@ export type SiemNavTabKey = export type SiemNavTab = Record; -export interface SecuritySubPluginStore { - initialState: Record; - reducer: Record>; +export interface SecuritySubPluginStore { + initialState: Record; + reducer: Record>; } -export interface SecuritySubPlugins { +export interface SecuritySubPlugin { routes: React.ReactElement[]; - store: SecuritySubPluginStore | {}; +} + +type SecuritySubPluginKeyStore = 'hosts' | 'network' | 'timeline'; +export interface SecuritySubPluginWithStore + extends SecuritySubPlugin { + store: SecuritySubPluginStore; +} + +export interface SecuritySubPlugins extends SecuritySubPlugin { + store: { + initialState: { + hosts: HostsState; + network: NetworkState; + timeline: TimelineState; + }; + reducer: { + hosts: Reducer; + network: Reducer; + timeline: Reducer; + }; + }; } diff --git a/x-pack/plugins/siem/public/cases/index.ts b/x-pack/plugins/siem/public/cases/index.ts index b58216b8f039..1eb8c82532e2 100644 --- a/x-pack/plugins/siem/public/cases/index.ts +++ b/x-pack/plugins/siem/public/cases/index.ts @@ -4,16 +4,15 @@ * you may not use this file except in compliance with the Elastic License. */ -import { SecuritySubPlugins } from '../app/types'; +import { SecuritySubPlugin } from '../app/types'; import { getCasesRoutes } from './routes'; export class Cases { public setup() {} - public start(): SecuritySubPlugins { + public start(): SecuritySubPlugin { return { routes: getCasesRoutes(), - store: {}, }; } } diff --git a/x-pack/plugins/siem/public/common/components/matrix_histogram/index.tsx b/x-pack/plugins/siem/public/common/components/matrix_histogram/index.tsx index d0d6649f8560..d5d4973fd8c0 100644 --- a/x-pack/plugins/siem/public/common/components/matrix_histogram/index.tsx +++ b/x-pack/plugins/siem/public/common/components/matrix_histogram/index.tsx @@ -110,15 +110,11 @@ export const MatrixHistogramComponent: React.FC { - if (!x) { - return; - } - const [from, to] = x; + onBrushEnd: (min: number, max: number) => { dispatchSetAbsoluteRangeDatePicker({ id: setAbsoluteRangeDatePickerTarget, - from, - to, + from: min, + to: max, }); }, yTickFormatter, diff --git a/x-pack/plugins/siem/public/common/store/reducer.ts b/x-pack/plugins/siem/public/common/store/reducer.ts index 641520eb248c..da1dcd3ea9e7 100644 --- a/x-pack/plugins/siem/public/common/store/reducer.ts +++ b/x-pack/plugins/siem/public/common/store/reducer.ts @@ -10,12 +10,10 @@ import { appReducer, AppState, initialAppState } from './app'; import { dragAndDropReducer, DragAndDropState, initialDragAndDropState } from './drag_and_drop'; import { createInitialInputsState, initialInputsState, inputsReducer, InputsState } from './inputs'; -import { HostsPluginState, HostsPluginReducer, HostsState } from '../../hosts/store'; +import { HostsPluginState, HostsPluginReducer } from '../../hosts/store'; import { NetworkPluginState, NetworkPluginReducer } from '../../network/store'; import { TimelinePluginState, TimelinePluginReducer } from '../../timelines/store/timeline'; -export type SubPluginsState = HostsState; - export interface State extends HostsPluginState, NetworkPluginState, TimelinePluginState { app: AppState; dragAndDrop: DragAndDropState; @@ -28,7 +26,7 @@ export const initialState: Pick = { inputs: initialInputsState, }; -export type SubPluginsInitState = HostsPluginState & NetworkPluginState & TimelinePluginState; +type SubPluginsInitState = HostsPluginState & NetworkPluginState & TimelinePluginState; export type SubPluginsInitReducer = HostsPluginReducer & NetworkPluginReducer & TimelinePluginReducer; @@ -39,7 +37,7 @@ export const createInitialState = (pluginsInitState: SubPluginsInitState): State inputs: createInitialInputsState(), }); -export const createReducer = (pluginsReducer: SubPluginsInitReducer | {}) => +export const createReducer = (pluginsReducer: SubPluginsInitReducer) => combineReducers({ app: appReducer, dragAndDrop: dragAndDropReducer, diff --git a/x-pack/plugins/siem/public/common/store/store.ts b/x-pack/plugins/siem/public/common/store/store.ts index a14ccb282c39..ea7cb417fb24 100644 --- a/x-pack/plugins/siem/public/common/store/store.ts +++ b/x-pack/plugins/siem/public/common/store/store.ts @@ -27,7 +27,7 @@ let store: Store | null = null; export { SubPluginsInitReducer }; export const createStore = ( state: State, - pluginsReducer: SubPluginsInitReducer | {}, + pluginsReducer: SubPluginsInitReducer, apolloClient: Observable ): Store => { const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose; diff --git a/x-pack/plugins/siem/public/hosts/index.ts b/x-pack/plugins/siem/public/hosts/index.ts index 45708b59bed4..6f27428e71c2 100644 --- a/x-pack/plugins/siem/public/hosts/index.ts +++ b/x-pack/plugins/siem/public/hosts/index.ts @@ -4,14 +4,14 @@ * you may not use this file except in compliance with the Elastic License. */ -import { SecuritySubPlugins } from '../app/types'; +import { SecuritySubPluginWithStore } from '../app/types'; import { getHostsRoutes } from './routes'; import { initialHostsState, hostsReducer, HostsState } from './store'; export class Hosts { public setup() {} - public start(): SecuritySubPlugins { + public start(): SecuritySubPluginWithStore<'hosts', HostsState> { return { routes: getHostsRoutes(), store: { diff --git a/x-pack/plugins/siem/public/hosts/pages/details/details_tabs.tsx b/x-pack/plugins/siem/public/hosts/pages/details/details_tabs.tsx index 505d0f37ca03..204e9261cb75 100644 --- a/x-pack/plugins/siem/public/hosts/pages/details/details_tabs.tsx +++ b/x-pack/plugins/siem/public/hosts/pages/details/details_tabs.tsx @@ -52,11 +52,7 @@ export const HostDetailsTabs = React.memo( ); const updateDateRange = useCallback( - ({ x }) => { - if (!x) { - return; - } - const [min, max] = x; + (min: number, max: number) => { setAbsoluteRangeDatePicker({ id: 'global', from: min, to: max }); }, [setAbsoluteRangeDatePicker] diff --git a/x-pack/plugins/siem/public/hosts/pages/details/index.tsx b/x-pack/plugins/siem/public/hosts/pages/details/index.tsx index 4145c6444c48..fa62519a53d6 100644 --- a/x-pack/plugins/siem/public/hosts/pages/details/index.tsx +++ b/x-pack/plugins/siem/public/hosts/pages/details/index.tsx @@ -73,11 +73,7 @@ const HostDetailsComponent = React.memo( ]); const getFilters = () => [...hostDetailsPageFilters, ...filters]; const narrowDateRange = useCallback( - ({ x }) => { - if (!x) { - return; - } - const [min, max] = x; + (min: number, max: number) => { setAbsoluteRangeDatePicker({ id: 'global', from: min, to: max }); }, [setAbsoluteRangeDatePicker] diff --git a/x-pack/plugins/siem/public/hosts/pages/hosts.tsx b/x-pack/plugins/siem/public/hosts/pages/hosts.tsx index e9063a88eadd..e1d51a01d8b2 100644 --- a/x-pack/plugins/siem/public/hosts/pages/hosts.tsx +++ b/x-pack/plugins/siem/public/hosts/pages/hosts.tsx @@ -67,11 +67,7 @@ export const HostsComponent = React.memo( return filters; }, [tabName, filters]); const narrowDateRange = useCallback( - ({ x }) => { - if (!x) { - return; - } - const [min, max] = x; + (min: number, max: number) => { setAbsoluteRangeDatePicker({ id: 'global', from: min, to: max }); }, [setAbsoluteRangeDatePicker] diff --git a/x-pack/plugins/siem/public/hosts/pages/hosts_tabs.tsx b/x-pack/plugins/siem/public/hosts/pages/hosts_tabs.tsx index 549c198a4352..73e969079515 100644 --- a/x-pack/plugins/siem/public/hosts/pages/hosts_tabs.tsx +++ b/x-pack/plugins/siem/public/hosts/pages/hosts_tabs.tsx @@ -57,11 +57,7 @@ export const HostsTabs = memo( [setAbsoluteRangeDatePicker] ), updateDateRange: useCallback( - ({ x }) => { - if (!x) { - return; - } - const [min, max] = x; + (min: number, max: number) => { setAbsoluteRangeDatePicker({ id: 'global', from: min, to: max }); }, [setAbsoluteRangeDatePicker] diff --git a/x-pack/plugins/siem/public/network/index.ts b/x-pack/plugins/siem/public/network/index.ts index 2bba35dbe842..6590e5ee5161 100644 --- a/x-pack/plugins/siem/public/network/index.ts +++ b/x-pack/plugins/siem/public/network/index.ts @@ -4,14 +4,14 @@ * you may not use this file except in compliance with the Elastic License. */ -import { SecuritySubPlugins } from '../app/types'; +import { SecuritySubPluginWithStore } from '../app/types'; import { getNetworkRoutes } from './routes'; import { initialNetworkState, networkReducer, NetworkState } from './store'; export class Network { public setup() {} - public start(): SecuritySubPlugins { + public start(): SecuritySubPluginWithStore<'network', NetworkState> { return { routes: getNetworkRoutes(), store: { diff --git a/x-pack/plugins/siem/public/network/pages/navigation/network_routes.tsx b/x-pack/plugins/siem/public/network/pages/navigation/network_routes.tsx index 08ed0d9769be..0e7fbfe9b730 100644 --- a/x-pack/plugins/siem/public/network/pages/navigation/network_routes.tsx +++ b/x-pack/plugins/siem/public/network/pages/navigation/network_routes.tsx @@ -48,11 +48,7 @@ export const NetworkRoutes = React.memo( [setAbsoluteRangeDatePicker] ); const updateDateRange = useCallback( - ({ x }) => { - if (!x) { - return; - } - const [min, max] = x; + (min: number, max: number) => { setAbsoluteRangeDatePicker({ id: 'global', from: min, to: max }); }, [setAbsoluteRangeDatePicker] diff --git a/x-pack/plugins/siem/public/network/pages/network.tsx b/x-pack/plugins/siem/public/network/pages/network.tsx index 2f7a97ed3d19..45a6eb020a45 100644 --- a/x-pack/plugins/siem/public/network/pages/network.tsx +++ b/x-pack/plugins/siem/public/network/pages/network.tsx @@ -67,11 +67,7 @@ const NetworkComponent = React.memo( }, [tabName, filters]); const narrowDateRange = useCallback( - ({ x }) => { - if (!x) { - return; - } - const [min, max] = x; + (min: number, max: number) => { setAbsoluteRangeDatePicker({ id: 'global', from: min, to: max }); }, [setAbsoluteRangeDatePicker] diff --git a/x-pack/plugins/siem/public/overview/components/signals_by_category/index.tsx b/x-pack/plugins/siem/public/overview/components/signals_by_category/index.tsx index def7342ff76b..9de37fb1ebea 100644 --- a/x-pack/plugins/siem/public/overview/components/signals_by_category/index.tsx +++ b/x-pack/plugins/siem/public/overview/components/signals_by_category/index.tsx @@ -54,11 +54,7 @@ const SignalsByCategoryComponent: React.FC = ({ }) => { const { signalIndexName } = useSignalIndex(); const updateDateRangeCallback = useCallback( - ({ x }) => { - if (!x) { - return; - } - const [min, max] = x; + (min: number, max: number) => { setAbsoluteRangeDatePicker({ id: setAbsoluteRangeDatePickerTarget, from: min, to: max }); }, [setAbsoluteRangeDatePicker] diff --git a/x-pack/plugins/siem/public/overview/index.ts b/x-pack/plugins/siem/public/overview/index.ts index 35f815b39b57..bdf855b3851c 100644 --- a/x-pack/plugins/siem/public/overview/index.ts +++ b/x-pack/plugins/siem/public/overview/index.ts @@ -4,16 +4,15 @@ * you may not use this file except in compliance with the Elastic License. */ -import { SecuritySubPlugins } from '../app/types'; +import { SecuritySubPlugin } from '../app/types'; import { getOverviewRoutes } from './routes'; export class Overview { public setup() {} - public start(): SecuritySubPlugins { + public start(): SecuritySubPlugin { return { routes: getOverviewRoutes(), - store: {}, }; } } diff --git a/x-pack/plugins/siem/public/plugin.tsx b/x-pack/plugins/siem/public/plugin.tsx index 1a76e52c98e9..cc46025ddc4a 100644 --- a/x-pack/plugins/siem/public/plugin.tsx +++ b/x-pack/plugins/siem/public/plugin.tsx @@ -33,12 +33,6 @@ import { APP_ID, APP_NAME, APP_PATH, APP_ICON } from '../common/constants'; import { initTelemetry } from './common/lib/telemetry'; import { KibanaServices } from './common/lib/kibana/services'; import { serviceNowActionType, jiraActionType } from './common/lib/connectors'; -import { Cases } from './cases'; -import { Alerts } from './alerts'; -import { Hosts } from './hosts'; -import { Network } from './network'; -import { Overview } from './overview'; -import { Timelines } from './timelines'; export interface SetupPlugins { home: HomePublicPluginSetup; @@ -68,12 +62,6 @@ export interface PluginStart {} export class Plugin implements IPlugin { private kibanaVersion: string; - private readonly alertsSubPlugin = new Alerts(); - private readonly casesSubPlugin = new Cases(); - private readonly hostsSubPlugin = new Hosts(); - private readonly networkSubPlugin = new Network(); - private readonly overviewSubPlugin = new Overview(); - private readonly timelinesSubPlugin = new Timelines(); constructor(initializerContext: PluginInitializerContext) { this.kibanaVersion = initializerContext.env.packageInfo.version; @@ -108,12 +96,19 @@ export class Plugin implements IPlugin { + public start(): SecuritySubPluginWithStore<'timeline', TimelineState> { return { routes: getTimelinesRoutes(), store: {