diff --git a/x-pack/plugins/security_solution/public/common/components/sourcerer/index.test.tsx b/x-pack/plugins/security_solution/public/common/components/sourcerer/index.test.tsx index f16c2b68c3ff7..c330bb073b146 100644 --- a/x-pack/plugins/security_solution/public/common/components/sourcerer/index.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/sourcerer/index.test.tsx @@ -6,7 +6,7 @@ import React from 'react'; import { mount } from 'enzyme'; -import { SOURCE_GROUPS } from '../../containers/sourcerer/constants'; +import { SecurityPageName } from '../../containers/sourcerer/constants'; import { mockPatterns, mockSourceGroup } from '../../containers/sourcerer/mocks'; import { MaybeSourcerer } from './index'; import * as i18n from './translations'; @@ -14,10 +14,10 @@ import { ADD_INDEX_PATH } from '../../../../common/constants'; const updateSourceGroupIndicies = jest.fn(); const mockManageSource = { - activeSourceGroupId: SOURCE_GROUPS.default, + activeSourceGroupId: SecurityPageName.default, availableIndexPatterns: mockPatterns, - availableSourceGroupIds: [SOURCE_GROUPS.default], - getManageSourceGroupById: jest.fn().mockReturnValue(mockSourceGroup(SOURCE_GROUPS.default)), + availableSourceGroupIds: [SecurityPageName.default], + getManageSourceGroupById: jest.fn().mockReturnValue(mockSourceGroup(SecurityPageName.default)), initializeSourceGroup: jest.fn(), isIndexPatternsLoading: false, setActiveSourceGroupId: jest.fn(), @@ -76,7 +76,7 @@ describe('Sourcerer component', () => { .prop('onChange'); // @ts-ignore switcherOnChange([mockOptions[0], mockOptions[1]]); - expect(updateSourceGroupIndicies).toHaveBeenCalledWith(SOURCE_GROUPS.default, [ + expect(updateSourceGroupIndicies).toHaveBeenCalledWith(SecurityPageName.default, [ mockOptions[0].value, mockOptions[1].value, ]); diff --git a/x-pack/plugins/security_solution/public/common/components/sourcerer/index.tsx b/x-pack/plugins/security_solution/public/common/components/sourcerer/index.tsx index 98699bc9b7a40..23a021c84c7b8 100644 --- a/x-pack/plugins/security_solution/public/common/components/sourcerer/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/sourcerer/index.tsx @@ -47,6 +47,7 @@ export const MaybeSourcerer = React.memo(() => { ); const [isPopoverOpen, setPopoverIsOpen] = useState(false); + const setPopoverIsOpenCb = useCallback((isOpen) => setPopoverIsOpen(isOpen), []); const trigger = useMemo( () => ( { flush="left" iconSide="right" iconType="indexSettings" - onClick={() => setPopoverIsOpen(!isPopoverOpen)} + onClick={() => setPopoverIsOpenCb(!isPopoverOpen)} size="l" title={i18n.SOURCERER} > {i18n.SOURCERER} ), - [isPopoverOpen] + [isPopoverOpen, setPopoverIsOpenCb] ); const options: EuiSelectableOption[] = useMemo( () => diff --git a/x-pack/plugins/security_solution/public/common/containers/sourcerer/constants.ts b/x-pack/plugins/security_solution/public/common/containers/sourcerer/constants.ts index 5923cf7559ad6..106294ba54f5a 100644 --- a/x-pack/plugins/security_solution/public/common/containers/sourcerer/constants.ts +++ b/x-pack/plugins/security_solution/public/common/containers/sourcerer/constants.ts @@ -6,7 +6,7 @@ export const SOURCERER_FEATURE_FLAG_ON = false; -export enum SOURCE_GROUPS { +export enum SecurityPageName { default = 'default', host = 'host', detections = 'detections', @@ -14,10 +14,10 @@ export enum SOURCE_GROUPS { network = 'network', } -export type SourceGroupsType = keyof typeof SOURCE_GROUPS; +export type SourceGroupsType = keyof typeof SecurityPageName; export const sourceGroups = { - [SOURCE_GROUPS.default]: [ + [SecurityPageName.default]: [ 'apm-*-transaction*', 'auditbeat-*', 'endgame-*', diff --git a/x-pack/plugins/security_solution/public/common/containers/sourcerer/index.test.tsx b/x-pack/plugins/security_solution/public/common/containers/sourcerer/index.test.tsx index 25e868313ea40..38af84e0968f8 100644 --- a/x-pack/plugins/security_solution/public/common/containers/sourcerer/index.test.tsx +++ b/x-pack/plugins/security_solution/public/common/containers/sourcerer/index.test.tsx @@ -14,8 +14,8 @@ import { mockPatterns, mockSource, } from './mocks'; -import { SOURCE_GROUPS } from './constants'; -const mockSourceDefaults = mockSource(SOURCE_GROUPS.default); +import { SecurityPageName } from './constants'; +const mockSourceDefaults = mockSource(SecurityPageName.default); jest.mock('../../lib/kibana', () => ({ useKibana: jest.fn().mockReturnValue({ services: { @@ -34,8 +34,8 @@ jest.mock('../../utils/apollo_context', () => ({ })); describe('Sourcerer Hooks', () => { - const testId = SOURCE_GROUPS.default; - const uninitializedId = SOURCE_GROUPS.host; + const testId = SecurityPageName.default; + const uninitializedId = SecurityPageName.host; beforeEach(() => { jest.clearAllMocks(); jest.restoreAllMocks(); diff --git a/x-pack/plugins/security_solution/public/common/containers/sourcerer/index.tsx b/x-pack/plugins/security_solution/public/common/containers/sourcerer/index.tsx index 567e63e64ebf1..91907b45aa449 100644 --- a/x-pack/plugins/security_solution/public/common/containers/sourcerer/index.tsx +++ b/x-pack/plugins/security_solution/public/common/containers/sourcerer/index.tsx @@ -17,7 +17,7 @@ import { sourceQuery } from '../source/index.gql_query'; import { useApolloClient } from '../../utils/apollo_context'; import { sourceGroups, - SOURCE_GROUPS, + SecurityPageName, SourceGroupsType, SOURCERER_FEATURE_FLAG_ON, } from './constants'; @@ -111,7 +111,7 @@ export const getSourceDefaults = (id: SourceGroupsType, defaultIndex: string[]) }); const initManageSource: ManageSourcerer = { - activeSourceGroupId: SOURCE_GROUPS.default, + activeSourceGroupId: SecurityPageName.default, availableIndexPatterns: [], availableSourceGroupIds: [], isIndexPatternsLoading: true, diff --git a/x-pack/plugins/security_solution/public/common/containers/sourcerer/mocks.ts b/x-pack/plugins/security_solution/public/common/containers/sourcerer/mocks.ts index c63230ddeade0..cde14e54694f0 100644 --- a/x-pack/plugins/security_solution/public/common/containers/sourcerer/mocks.ts +++ b/x-pack/plugins/security_solution/public/common/containers/sourcerer/mocks.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { SOURCE_GROUPS } from './constants'; +import { SecurityPageName } from './constants'; import { getSourceDefaults } from './index'; export const mockPatterns = [ @@ -17,7 +17,7 @@ export const mockPatterns = [ ]; export const mockSourceGroups = { - [SOURCE_GROUPS.default]: [ + [SecurityPageName.default]: [ 'apm-*-transaction*', 'auditbeat-*', 'blobbeat-*', @@ -26,7 +26,7 @@ export const mockSourceGroups = { 'logs-*', 'winlogbeat-*', ], - [SOURCE_GROUPS.host]: [ + [SecurityPageName.host]: [ 'apm-*-transaction*', 'endgame-*', 'logs-*', @@ -36,10 +36,10 @@ export const mockSourceGroups = { }; export const mockSourceSelections = { - [SOURCE_GROUPS.default]: ['auditbeat-*', 'endgame-*', 'filebeat-*', 'logs-*', 'winlogbeat-*'], - [SOURCE_GROUPS.host]: ['endgame-*', 'logs-*', 'packetbeat-*', 'winlogbeat-*'], + [SecurityPageName.default]: ['auditbeat-*', 'endgame-*', 'filebeat-*', 'logs-*', 'winlogbeat-*'], + [SecurityPageName.host]: ['endgame-*', 'logs-*', 'packetbeat-*', 'winlogbeat-*'], }; -export const mockSource = (testId: SOURCE_GROUPS.default | SOURCE_GROUPS.host) => ({ +export const mockSource = (testId: SecurityPageName.default | SecurityPageName.host) => ({ data: { source: { id: 'default', @@ -69,7 +69,7 @@ export const mockSource = (testId: SOURCE_GROUPS.default | SOURCE_GROUPS.host) = stale: false, }); -export const mockSourceGroup = (testId: SOURCE_GROUPS.default | SOURCE_GROUPS.host) => { +export const mockSourceGroup = (testId: SecurityPageName.default | SecurityPageName.host) => { const indexes = mockSourceSelections[testId]; return { ...getSourceDefaults(testId, mockPatterns),