From 32e4b5d45c2fb0a4cd9086c12f0745431053b1f8 Mon Sep 17 00:00:00 2001 From: Steph Milovic Date: Tue, 21 Dec 2021 07:40:02 -0700 Subject: [PATCH] [Security Solution] Resolver, revert to default data view (#121711) --- .../components/graph_overlay/index.test.tsx | 85 ++++++++++++++++++- .../components/graph_overlay/index.tsx | 14 ++- 2 files changed, 97 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/security_solution/public/timelines/components/graph_overlay/index.test.tsx b/x-pack/plugins/security_solution/public/timelines/components/graph_overlay/index.test.tsx index c16da16002265..e8d144f07827f 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/graph_overlay/index.test.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/graph_overlay/index.test.tsx @@ -13,9 +13,19 @@ import { useGlobalFullScreen, useTimelineFullScreen, } from '../../../common/containers/use_full_screen'; -import { TestProviders } from '../../../common/mock'; +import { + createSecuritySolutionStorageMock, + kibanaObservable, + mockGlobalState, + mockIndexNames, + SUB_PLUGINS_REDUCER, + TestProviders, +} from '../../../common/mock'; import { TimelineId } from '../../../../common/types/timeline'; import { GraphOverlay } from '.'; +import { createStore } from '../../../common/store'; +import { useStateSyncingActions } from '../../../resolver/view/use_state_syncing_actions'; +import { SourcererScopeName } from '../../../common/store/sourcerer/model'; jest.mock('../../../common/containers/use_full_screen', () => ({ useGlobalFullScreen: jest.fn(), @@ -24,10 +34,15 @@ jest.mock('../../../common/containers/use_full_screen', () => ({ jest.mock('../../../resolver/view/use_resolver_query_params_cleaner'); jest.mock('../../../resolver/view/use_state_syncing_actions'); +const useStateSyncingActionsMock = useStateSyncingActions as jest.Mock; + jest.mock('../../../resolver/view/use_sync_selected_node'); describe('GraphOverlay', () => { + const { storage } = createSecuritySolutionStorageMock(); + beforeEach(() => { + jest.clearAllMocks(); (useGlobalFullScreen as jest.Mock).mockReturnValue({ globalFullScreen: false, setGlobalFullScreen: jest.fn(), @@ -73,6 +88,36 @@ describe('GraphOverlay', () => { expect(overlayContainer).toHaveStyleRule('position', 'fixed'); }); }); + + test('it gets index pattern from default data view', () => { + mount( + + + + ); + + expect(useStateSyncingActionsMock.mock.calls[0][0].indices).toEqual( + mockGlobalState.sourcerer.defaultDataView.patternList + ); + }); }); describe('when used in the active timeline', () => { @@ -112,5 +157,43 @@ describe('GraphOverlay', () => { expect(overlayContainer).toHaveStyleRule('width', '100%'); }); }); + + test('it gets index pattern from Timeline data view', () => { + mount( + + + + ); + + expect(useStateSyncingActionsMock.mock.calls[0][0].indices).toEqual(mockIndexNames); + }); }); }); diff --git a/x-pack/plugins/security_solution/public/timelines/components/graph_overlay/index.tsx b/x-pack/plugins/security_solution/public/timelines/components/graph_overlay/index.tsx index 31a40c46fc0bf..b7b3aa0b33bcb 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/graph_overlay/index.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/graph_overlay/index.tsx @@ -40,6 +40,7 @@ import { import * as i18n from './translations'; import { SourcererScopeName } from '../../../common/store/sourcerer/model'; import { useSourcererDataView } from '../../../common/containers/sourcerer'; +import { sourcererSelectors } from '../../../common/store'; const OverlayContainer = styled.div` display: flex; @@ -181,7 +182,18 @@ const GraphOverlayComponent: React.FC = ({ timelineId }) => { globalFullScreen, ]); - const { selectedPatterns } = useSourcererDataView(SourcererScopeName.timeline); + const getDefaultDataViewSelector = useMemo( + () => sourcererSelectors.defaultDataViewSelector(), + [] + ); + const defaultDataView = useDeepEqualSelector(getDefaultDataViewSelector); + + const { selectedPatterns: timelinePatterns } = useSourcererDataView(SourcererScopeName.timeline); + + const selectedPatterns = useMemo( + () => (isInTimeline ? timelinePatterns : defaultDataView.patternList), + [defaultDataView.patternList, isInTimeline, timelinePatterns] + ); if (fullScreen && !isInTimeline) { return (