Skip to content

Commit

Permalink
Small cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
stephmilovic committed Nov 4, 2021
1 parent ac0b022 commit 6a68772
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 177 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,155 +136,5 @@ describe('source/index.tsx', () => {
expect(payload.docValueFields).toEqual([{ field: '@timestamp' }]);
});
});

// TODO: Steph/sourcerer make these tests good again
// it('sets source for timelines scope', async () => {
// await act(async () => {
// const { rerender, waitForNextUpdate } = renderHook<string, void>(
// () => useIndexFields(SourcererScopeName.timeline),
// {
// wrapper: ({ children }) => <Provider store={store}>{children}</Provider>,
// }
// );
// await waitForNextUpdate();
// rerender();
// expect(mockDispatch.mock.calls[0][0]).toEqual({
// type: 'x-pack/security_solution/local/sourcerer/SET_SOURCERER_SCOPE_LOADING',
// payload: { id: SourcererScopeName.timeline, loading: true },
// });
// const {
// type: sourceType,
// payload: { payload },
// } = mockDispatch.mock.calls[1][0];
// expect(sourceType).toEqual('x-pack/security_solution/local/sourcerer/SET_SOURCE');
// expect(payload.id).toEqual(SourcererScopeName.timeline);
// expect(payload.indicesExist).toEqual(true);
// expect(payload.indexPattern.title).toEqual(
// `${sourcererState.signalIndexName},apm-*-transaction*,auditbeat-*,endgame-*,filebeat-*,logs-*,packetbeat-*,traces-apm*,winlogbeat-*`
// );
// });
// });
// it('sets source for detections scope when signalIndexName is updated', async () => {
// store = createStore(
// { ...state, sourcerer: { ...state.sourcerer, signalIndexName: null } },
// SUB_PLUGINS_REDUCER,
// kibanaObservable,
// storage
// );
// await act(async () => {
// const { result, rerender, waitForNextUpdate } = renderHook<
// string,
// { indexFieldsSearch: (selectedDataViewId: string, newSignalsIndex?: string) => void }
// >(() => useIndexFields(SourcererScopeName.detections), {
// wrapper: ({ children }) => <Provider store={store}>{children}</Provider>,
// });
// await waitForNextUpdate();
// rerender();
// act(() => {
// result.current.indexFieldsSearch(
// sourcererState.defaultDataView.id,
// `${sourcererState.signalIndexName}`
// );
// });
//
// expect(mockDispatch.mock.calls[0][0]).toEqual({
// type: 'x-pack/security_solution/local/sourcerer/SET_SOURCERER_SCOPE_LOADING',
// payload: { id: SourcererScopeName.detections, loading: true },
// });
// expect(mockDispatch.mock.calls[1][0].payload.payload.indicesExist).toEqual(false);
// expect(mockDispatch.mock.calls[2][0]).toEqual({
// type: 'x-pack/security_solution/local/sourcerer/SET_SOURCERER_SCOPE_LOADING',
// payload: { id: SourcererScopeName.detections, loading: true },
// });
// expect(mockDispatch.mock.calls[3][0].payload.payload.indicesExist).toEqual(true);
// });
// });
// it('when selectedPatterns=[], defaults to the patternList of the selected dataView', async () => {
// await act(async () => {
// store = createStore(
// {
// ...state,
// sourcerer: {
// ...state.sourcerer,
// sourcererScopes: {
// ...state.sourcerer.sourcererScopes,
// [SourcererScopeName.default]: {
// ...state.sourcerer.sourcererScopes[SourcererScopeName.default],
// selectedDataViewId: 'something-random',
// selectedPatterns: [],
// },
// },
// },
// },
// SUB_PLUGINS_REDUCER,
// kibanaObservable,
// storage
// );
// const { rerender, waitForNextUpdate } = renderHook<string, void>(
// () => useIndexFields(SourcererScopeName.default),
// {
// wrapper: ({ children }) => <Provider store={store}>{children}</Provider>,
// }
// );
// await waitForNextUpdate();
// rerender();
// expect(mockDispatch.mock.calls[0][0]).toEqual({
// type: 'x-pack/security_solution/local/sourcerer/SET_SOURCERER_SCOPE_LOADING',
// payload: { id: SourcererScopeName.default, loading: true },
// });
// const {
// type: sourceType,
// payload: { payload },
// } = mockDispatch.mock.calls[1][0];
// expect(sourceType).toEqual('x-pack/security_solution/local/sourcerer/SET_SOURCE');
// expect(payload.id).toEqual(SourcererScopeName.default);
// expect(payload.indicesExist).toEqual(true);
// expect(payload.indexPattern.title).toEqual('random,something');
// });
// });
// it('when selectedPatterns=[] and selectedDataViewId=security-solution, runs getScopePatternListSelection', async () => {
// await act(async () => {
// store = createStore(
// {
// ...state,
// sourcerer: {
// ...state.sourcerer,
// sourcererScopes: {
// ...state.sourcerer.sourcererScopes,
// [SourcererScopeName.default]: {
// ...state.sourcerer.sourcererScopes[SourcererScopeName.default],
// selectedPatterns: [],
// },
// },
// },
// },
// SUB_PLUGINS_REDUCER,
// kibanaObservable,
// storage
// );
// const { rerender, waitForNextUpdate } = renderHook<string, void>(
// () => useIndexFields(SourcererScopeName.default),
// {
// wrapper: ({ children }) => <Provider store={store}>{children}</Provider>,
// }
// );
// await waitForNextUpdate();
// rerender();
// expect(mockDispatch.mock.calls[0][0]).toEqual({
// type: 'x-pack/security_solution/local/sourcerer/SET_SOURCERER_SCOPE_LOADING',
// payload: { id: SourcererScopeName.default, loading: true },
// });
// const {
// type: sourceType,
// payload: { payload },
// } = mockDispatch.mock.calls[1][0];
// expect(sourceType).toEqual('x-pack/security_solution/local/sourcerer/SET_SOURCE');
// expect(payload.id).toEqual(SourcererScopeName.default);
// expect(payload.indicesExist).toEqual(true);
// expect(payload.indexPattern.title).toEqual(
// 'apm-*-transaction*,auditbeat-*,endgame-*,filebeat-*,logs-*,packetbeat-*,traces-apm*,winlogbeat-*'
// );
// });
// });
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { KibanaServices } from '../../lib/kibana';
import { SOURCERER_API_URL } from '../../../../common/constants';
import { SourcererDataView } from '../../store/sourcerer/model';
import { KibanaDataView } from '../../store/sourcerer/model';

export interface GetSourcererDataView {
signal: AbortSignal;
Expand All @@ -16,9 +16,9 @@ export interface GetSourcererDataView {
};
}

interface SecurityDataView {
defaultDataView: SourcererDataView;
kibanaDataViews: SourcererDataView[];
export interface SecurityDataView {
defaultDataView: KibanaDataView;
kibanaDataViews: KibanaDataView[];
}

export const postSourcererDataView = async ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import actionCreatorFactory from 'typescript-fsa';
import { TimelineEventsType } from '../../../../common/types/timeline';

import { SourcererDataView, SourcererScopeName } from './model';
import { SecurityDataView } from '../../containers/sourcerer/api';

const actionCreator = actionCreatorFactory('x-pack/security_solution/local/sourcerer');

Expand All @@ -29,10 +30,7 @@ export const setDataViewLoading = actionCreator<{
export const setSignalIndexName =
actionCreator<{ signalIndexName: string }>('SET_SIGNAL_INDEX_NAME');

export const setSourcererDataViews = actionCreator<{
defaultDataView: SourcererDataView;
kibanaDataViews: SourcererDataView[];
}>('SET_SOURCERER_DATA_VIEWS');
export const setSourcererDataViews = actionCreator<SecurityDataView>('SET_SOURCERER_DATA_VIEWS');

export const setSourcererScopeLoading = actionCreator<{
id?: SourcererScopeName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,32 @@ export interface SourcererScope {
}

export type SourcererScopeById = Record<SourcererScopeName, SourcererScope>;

export interface KibanaDataView {
/** Uniquely identifies a Kibana Data View */
id: string;
/** list of active patterns that return data */
patternList: string[];
/**
* title of Kibana Data View
* title also serves as "all pattern list", including inactive
* comma separated string
*/
title: string;
}

/**
* DataView from Kibana + timelines/index_fields enhanced field data
*/
export interface SourcererDataView {
export interface SourcererDataView extends KibanaDataView {
/** we need this for @timestamp data */
browserFields: BrowserFields;
/** we need this for @timestamp data */
docValueFields: DocValueFields[];
/** Uniquely identifies a Kibana Data View */
id: string;
/** comes from dataView.fields.toSpec() */
indexFields: SecuritySolutionDataViewBase['fields'];
/** set when data view fields are fetched */
loading: boolean;
/** list of active patterns that return data */
patternList: string[];
/**
* title of Kibana Data View
* title also serves as "all pattern list", including inactive
* comma separated string
*/
title: string;
/**
* Needed to pass to search strategy
* Remove once issue resolved: https://github.com/elastic/kibana/issues/111762
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
setDataView,
setDataViewLoading,
} from './actions';
import { initialSourcererState, SourcererModel, SourcererScopeName } from './model';
import { initDataView, initialSourcererState, SourcererModel, SourcererScopeName } from './model';
import { validateSelectedPatterns } from './helpers';

export type SourcererState = SourcererModel;
Expand All @@ -41,7 +41,7 @@ export const sourcererReducer = reducerWithInitialState(initialSourcererState)
...defaultDataView,
},
kibanaDataViews: kibanaDataViews.map((dataView) => ({
...(kibanaDataViews.find(({ id }) => id === dataView.id) ?? {}),
...(state.kibanaDataViews.find(({ id }) => id === dataView.id) ?? initDataView),
...dataView,
})),
}))
Expand Down
10 changes: 4 additions & 6 deletions x-pack/plugins/security_solution/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ import {
} from '../common/experimental_features';
import type { TimelineState } from '../../timelines/public';
import { LazyEndpointCustomAssetsExtension } from './management/pages/policy/view/ingest_manager_integration/lazy_endpoint_custom_assets_extension';
import { initDataView, SourcererModel, SourcererDataView } from './common/store/sourcerer/model';
import { initDataView, SourcererModel, KibanaDataView } from './common/store/sourcerer/model';
import { SecurityDataView } from './common/containers/sourcerer/api';

export class Plugin implements IPlugin<PluginSetup, PluginStart, SetupPlugins, StartPlugins> {
readonly kibanaVersion: string;
Expand Down Expand Up @@ -351,17 +352,14 @@ export class Plugin implements IPlugin<PluginSetup, PluginStart, SetupPlugins, S
let kibanaDataViews: SourcererModel['kibanaDataViews'];
try {
// check for/generate default Security Solution Kibana data view
const sourcererDataViews: {
defaultDataView: SourcererModel['defaultDataView'];
kibanaDataViews: SourcererModel['kibanaDataViews'];
} = await coreStart.http.fetch(SOURCERER_API_URL, {
const sourcererDataViews: SecurityDataView = await coreStart.http.fetch(SOURCERER_API_URL, {
method: 'POST',
body: JSON.stringify({
patternList: [...configPatternList, ...(signal.name != null ? [signal.name] : [])],
}),
});
defaultDataView = { ...initDataView, ...sourcererDataViews.defaultDataView };
kibanaDataViews = sourcererDataViews.kibanaDataViews.map((dataView: SourcererDataView) => ({
kibanaDataViews = sourcererDataViews.kibanaDataViews.map((dataView: KibanaDataView) => ({
...initDataView,
...dataView,
}));
Expand Down

0 comments on commit 6a68772

Please sign in to comment.