Skip to content

Commit

Permalink
fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
XavierM committed May 11, 2020
1 parent 39bed1b commit d784e05
Show file tree
Hide file tree
Showing 21 changed files with 75 additions and 115 deletions.
5 changes: 2 additions & 3 deletions x-pack/plugins/siem/public/alerts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,7 @@ export const DetectionEnginePageComponent: React.FC<PropsFromRedux> = ({
const [lastSignals] = useSignalInfo({});

const updateDateRangeCallback = useCallback<UpdateDateRange>(
({ x }) => {
if (!x) {
return;
}
const [min, max] = x;
(min: number, max: number) => {
setAbsoluteRangeDatePicker({ id: 'global', from: min, to: max });
},
[setAbsoluteRangeDatePicker]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,7 @@ export const RuleDetailsPageComponent: FC<PropsFromRedux> = ({
]);

const updateDateRangeCallback = useCallback<UpdateDateRange>(
({ x }) => {
if (!x) {
return;
}
const [min, max] = x;
(min: number, max: number) => {
setAbsoluteRangeDatePicker({ id: 'global', from: min, to: max });
},
[setAbsoluteRangeDatePicker]
Expand Down
25 changes: 6 additions & 19 deletions x-pack/plugins/siem/public/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -74,7 +68,7 @@ const AppPluginRootComponent: React.FC<AppPluginRootComponentProps> = ({
const AppPluginRoot = memo(AppPluginRootComponent);

interface StartAppComponent extends AppFrontendLibs {
subPlugins: SecuritySubPlugins<SubPluginsState>;
subPlugins: SecuritySubPlugins;
}

const StartAppComponent: FC<StartAppComponent> = ({ subPlugins, ...libs }) => {
Expand All @@ -83,16 +77,12 @@ const StartAppComponent: FC<StartAppComponent> = ({ 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$<boolean>(DEFAULT_DARK_MODE);
const theme = useMemo(
() => ({
Expand Down Expand Up @@ -132,10 +122,7 @@ const SiemAppComponent: React.FC<SiemAppComponentProps> = ({ services, subPlugin
...services,
}}
>
<StartApp
subPlugins={subPlugins as SecuritySubPlugins<SubPluginsState>}
{...compose(services)}
/>
<StartApp subPlugins={subPlugins} {...compose(services)} />
</KibanaContextProvider>
);

Expand Down
33 changes: 28 additions & 5 deletions x-pack/plugins/siem/public/app/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -27,12 +30,32 @@ export type SiemNavTabKey =

export type SiemNavTab = Record<SiemNavTabKey, NavTab>;

export interface SecuritySubPluginStore<T = unknown> {
initialState: Record<string, T>;
reducer: Record<string, Reducer<T, AnyAction>>;
export interface SecuritySubPluginStore<K extends SecuritySubPluginKeyStore, T> {
initialState: Record<K, T>;
reducer: Record<K, Reducer<T, AnyAction>>;
}

export interface SecuritySubPlugins<T = unknown> {
export interface SecuritySubPlugin {
routes: React.ReactElement[];
store: SecuritySubPluginStore<T> | {};
}

type SecuritySubPluginKeyStore = 'hosts' | 'network' | 'timeline';
export interface SecuritySubPluginWithStore<K extends SecuritySubPluginKeyStore, T>
extends SecuritySubPlugin {
store: SecuritySubPluginStore<K, T>;
}

export interface SecuritySubPlugins extends SecuritySubPlugin {
store: {
initialState: {
hosts: HostsState;
network: NetworkState;
timeline: TimelineState;
};
reducer: {
hosts: Reducer<HostsState, AnyAction>;
network: Reducer<NetworkState, AnyAction>;
timeline: Reducer<TimelineState, AnyAction>;
};
};
}
5 changes: 2 additions & 3 deletions x-pack/plugins/siem/public/cases/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,11 @@ export const MatrixHistogramComponent: React.FC<MatrixHistogramProps &
from: startDate,
legendPosition,
to: endDate,
onBrushEnd: ({ x }) => {
if (!x) {
return;
}
const [from, to] = x;
onBrushEnd: (min: number, max: number) => {
dispatchSetAbsoluteRangeDatePicker({
id: setAbsoluteRangeDatePickerTarget,
from,
to,
from: min,
to: max,
});
},
yTickFormatter,
Expand Down
8 changes: 3 additions & 5 deletions x-pack/plugins/siem/public/common/store/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,7 +26,7 @@ export const initialState: Pick<State, 'app' | 'dragAndDrop' | 'inputs'> = {
inputs: initialInputsState,
};

export type SubPluginsInitState = HostsPluginState & NetworkPluginState & TimelinePluginState;
type SubPluginsInitState = HostsPluginState & NetworkPluginState & TimelinePluginState;
export type SubPluginsInitReducer = HostsPluginReducer &
NetworkPluginReducer &
TimelinePluginReducer;
Expand All @@ -39,7 +37,7 @@ export const createInitialState = (pluginsInitState: SubPluginsInitState): State
inputs: createInitialInputsState(),
});

export const createReducer = (pluginsReducer: SubPluginsInitReducer | {}) =>
export const createReducer = (pluginsReducer: SubPluginsInitReducer) =>
combineReducers<State>({
app: appReducer,
dragAndDrop: dragAndDropReducer,
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/siem/public/common/store/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ let store: Store<State, Action> | null = null;
export { SubPluginsInitReducer };
export const createStore = (
state: State,
pluginsReducer: SubPluginsInitReducer | {},
pluginsReducer: SubPluginsInitReducer,
apolloClient: Observable<AppApolloClient>
): Store<State, Action> => {
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/siem/public/hosts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<HostsState> {
public start(): SecuritySubPluginWithStore<'hosts', HostsState> {
return {
routes: getHostsRoutes(),
store: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,7 @@ export const HostDetailsTabs = React.memo<HostDetailsTabsProps>(
);

const updateDateRange = useCallback<UpdateDateRange>(
({ x }) => {
if (!x) {
return;
}
const [min, max] = x;
(min: number, max: number) => {
setAbsoluteRangeDatePicker({ id: 'global', from: min, to: max });
},
[setAbsoluteRangeDatePicker]
Expand Down
6 changes: 1 addition & 5 deletions x-pack/plugins/siem/public/hosts/pages/details/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,7 @@ const HostDetailsComponent = React.memo<HostDetailsProps & PropsFromRedux>(
]);
const getFilters = () => [...hostDetailsPageFilters, ...filters];
const narrowDateRange = useCallback<UpdateDateRange>(
({ x }) => {
if (!x) {
return;
}
const [min, max] = x;
(min: number, max: number) => {
setAbsoluteRangeDatePicker({ id: 'global', from: min, to: max });
},
[setAbsoluteRangeDatePicker]
Expand Down
6 changes: 1 addition & 5 deletions x-pack/plugins/siem/public/hosts/pages/hosts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,7 @@ export const HostsComponent = React.memo<HostsComponentProps & PropsFromRedux>(
return filters;
}, [tabName, filters]);
const narrowDateRange = useCallback<UpdateDateRange>(
({ x }) => {
if (!x) {
return;
}
const [min, max] = x;
(min: number, max: number) => {
setAbsoluteRangeDatePicker({ id: 'global', from: min, to: max });
},
[setAbsoluteRangeDatePicker]
Expand Down
6 changes: 1 addition & 5 deletions x-pack/plugins/siem/public/hosts/pages/hosts_tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ export const HostsTabs = memo<HostsTabsProps>(
[setAbsoluteRangeDatePicker]
),
updateDateRange: useCallback<UpdateDateRange>(
({ x }) => {
if (!x) {
return;
}
const [min, max] = x;
(min: number, max: number) => {
setAbsoluteRangeDatePicker({ id: 'global', from: min, to: max });
},
[setAbsoluteRangeDatePicker]
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/siem/public/network/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<NetworkState> {
public start(): SecuritySubPluginWithStore<'network', NetworkState> {
return {
routes: getNetworkRoutes(),
store: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,7 @@ export const NetworkRoutes = React.memo<NetworkRoutesProps>(
[setAbsoluteRangeDatePicker]
);
const updateDateRange = useCallback<UpdateDateRange>(
({ x }) => {
if (!x) {
return;
}
const [min, max] = x;
(min: number, max: number) => {
setAbsoluteRangeDatePicker({ id: 'global', from: min, to: max });
},
[setAbsoluteRangeDatePicker]
Expand Down
6 changes: 1 addition & 5 deletions x-pack/plugins/siem/public/network/pages/network.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,7 @@ const NetworkComponent = React.memo<NetworkComponentProps & PropsFromRedux>(
}, [tabName, filters]);

const narrowDateRange = useCallback<UpdateDateRange>(
({ x }) => {
if (!x) {
return;
}
const [min, max] = x;
(min: number, max: number) => {
setAbsoluteRangeDatePicker({ id: 'global', from: min, to: max });
},
[setAbsoluteRangeDatePicker]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,7 @@ const SignalsByCategoryComponent: React.FC<Props> = ({
}) => {
const { signalIndexName } = useSignalIndex();
const updateDateRangeCallback = useCallback<UpdateDateRange>(
({ x }) => {
if (!x) {
return;
}
const [min, max] = x;
(min: number, max: number) => {
setAbsoluteRangeDatePicker({ id: setAbsoluteRangeDatePickerTarget, from: min, to: max });
},
[setAbsoluteRangeDatePicker]
Expand Down
5 changes: 2 additions & 3 deletions x-pack/plugins/siem/public/overview/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
};
}
}
Loading

0 comments on commit d784e05

Please sign in to comment.