Small cleanup

This commit is contained in:
Steph Milovic 2021-11-04 12:51:26 -06:00
parent ac0b022e83
commit 6a687726d5
6 changed files with 28 additions and 178 deletions

View file

@ -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-*'
// );
// });
// });
});
});

View file

@ -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;
@ -16,9 +16,9 @@ export interface GetSourcererDataView {
};
}
interface SecurityDataView {
defaultDataView: SourcererDataView;
kibanaDataViews: SourcererDataView[];
export interface SecurityDataView {
defaultDataView: KibanaDataView;
kibanaDataViews: KibanaDataView[];
}
export const postSourcererDataView = async ({

View file

@ -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');
@ -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;

View file

@ -36,20 +36,10 @@ export interface SourcererScope {
}
export type SourcererScopeById = Record<SourcererScopeName, SourcererScope>;
/**
* DataView from Kibana + timelines/index_fields enhanced field data
*/
export interface SourcererDataView {
/** we need this for @timestamp data */
browserFields: BrowserFields;
/** we need this for @timestamp data */
docValueFields: DocValueFields[];
export interface KibanaDataView {
/** 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[];
/**
@ -58,6 +48,20 @@ export interface SourcererDataView {
* comma separated string
*/
title: string;
}
/**
* DataView from Kibana + timelines/index_fields enhanced field data
*/
export interface SourcererDataView extends KibanaDataView {
/** we need this for @timestamp data */
browserFields: BrowserFields;
/** we need this for @timestamp data */
docValueFields: DocValueFields[];
/** comes from dataView.fields.toSpec() */
indexFields: SecuritySolutionDataViewBase['fields'];
/** set when data view fields are fetched */
loading: boolean;
/**
* Needed to pass to search strategy
* Remove once issue resolved: https://github.com/elastic/kibana/issues/111762

View file

@ -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;
@ -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,
})),
}))

View file

@ -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;
@ -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,
}));