From bde8c429ccebfb0592f08428b59eca84c720b3ce Mon Sep 17 00:00:00 2001 From: patrykkopycinski Date: Thu, 28 Nov 2019 15:49:43 +0100 Subject: [PATCH] [7.x] [SIEM] Fix eslint errors (#49713) (#51875) * [SIEM] Fix eslint errors (#49713) * Update use_kibana_ui_setting.ts --- .eslintrc.js | 9 ++----- .../embeddables/embedded_map.test.tsx | 5 ++++ .../components/flyout/pane/index.test.tsx | 4 +++ .../components/link_to/redirect_wrapper.tsx | 4 +-- .../components/resize_handle/is_resizing.tsx | 2 +- .../components/scroll_to_top/index.test.tsx | 6 ++--- .../public/components/scroll_to_top/index.tsx | 2 +- .../body/column_headers/index.test.tsx | 2 +- .../timeline/body/column_headers/index.tsx | 4 +-- .../endgame_security_event_details_line.tsx | 6 ++--- .../body/renderers/endgame/helpers.test.tsx | 16 ++++++------ .../body/renderers/endgame/helpers.ts | 6 ++--- .../timeline/properties/index.test.tsx | 4 +++ .../public/components/toasters/index.test.tsx | 26 ++++--------------- .../lib/settings/use_kibana_ui_setting.ts | 3 +++ .../settings/use_kibana_ui_settings.test.tsx | 4 +-- 16 files changed, 49 insertions(+), 54 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 9806edb53efc82..fe546ec02a6688 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -202,13 +202,6 @@ module.exports = { 'jsx-a11y/click-events-have-key-events': 'off', }, }, - { - files: ['x-pack/legacy/plugins/siem/**/*.{js,ts,tsx}'], - rules: { - 'react-hooks/exhaustive-deps': 'off', - 'react-hooks/rules-of-hooks': 'off', - }, - }, { files: ['x-pack/legacy/plugins/snapshot_restore/**/*.{js,ts,tsx}'], rules: { @@ -827,6 +820,8 @@ module.exports = { // might be introduced after the other warns are fixed // 'react/jsx-sort-props': 'error', 'react/jsx-tag-spacing': 'error', + // might be introduced after the other warns are fixed + 'react-hooks/exhaustive-deps': 'off', 'require-atomic-updates': 'error', 'rest-spread-spacing': ['error', 'never'], 'symbol-description': 'error', diff --git a/x-pack/legacy/plugins/siem/public/components/embeddables/embedded_map.test.tsx b/x-pack/legacy/plugins/siem/public/components/embeddables/embedded_map.test.tsx index 65382ad7f8d545..1ed1075542f71f 100644 --- a/x-pack/legacy/plugins/siem/public/components/embeddables/embedded_map.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/embeddables/embedded_map.test.tsx @@ -10,6 +10,7 @@ import * as React from 'react'; import { EmbeddedMapComponent } from './embedded_map'; import { SetQuery } from './types'; import { useKibanaCore } from '../../lib/compose/kibana_core'; +import { useIndexPatterns } from '../../hooks/use_index_patterns'; jest.mock('../search_bar', () => ({ siemFilterManager: { @@ -17,6 +18,10 @@ jest.mock('../search_bar', () => ({ }, })); +const mockUseIndexPatterns = useIndexPatterns as jest.Mock; +jest.mock('../../hooks/use_index_patterns'); +mockUseIndexPatterns.mockImplementation(() => [true, []]); + const mockUseKibanaCore = useKibanaCore as jest.Mock; jest.mock('../../lib/compose/kibana_core'); mockUseKibanaCore.mockImplementation(() => ({ diff --git a/x-pack/legacy/plugins/siem/public/components/flyout/pane/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/flyout/pane/index.test.tsx index 323165aae40d3b..65233e55901ff8 100644 --- a/x-pack/legacy/plugins/siem/public/components/flyout/pane/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/flyout/pane/index.test.tsx @@ -24,6 +24,10 @@ mockUseKibanaCore.mockImplementation(() => ({ uiSettings: mockUiSettings, })); +jest.mock('ui/vis/lib/timezone', () => ({ + timezoneProvider: () => () => 'America/New_York', +})); + describe('Pane', () => { test('renders correctly against snapshot', () => { const EmptyComponent = shallow( diff --git a/x-pack/legacy/plugins/siem/public/components/link_to/redirect_wrapper.tsx b/x-pack/legacy/plugins/siem/public/components/link_to/redirect_wrapper.tsx index 2b56dd44c970a9..39f24e8351f63d 100644 --- a/x-pack/legacy/plugins/siem/public/components/link_to/redirect_wrapper.tsx +++ b/x-pack/legacy/plugins/siem/public/components/link_to/redirect_wrapper.tsx @@ -6,13 +6,13 @@ import React from 'react'; import { Redirect } from 'react-router-dom'; -import { scrollToTop } from '../scroll_to_top'; +import { useScrollToTop } from '../scroll_to_top'; export interface RedirectWrapperProps { to: string; } export const RedirectWrapper = ({ to }: RedirectWrapperProps) => { - scrollToTop(); + useScrollToTop(); return ; }; diff --git a/x-pack/legacy/plugins/siem/public/components/resize_handle/is_resizing.tsx b/x-pack/legacy/plugins/siem/public/components/resize_handle/is_resizing.tsx index 409c7cb85e1d1b..5eb2d397b4c989 100644 --- a/x-pack/legacy/plugins/siem/public/components/resize_handle/is_resizing.tsx +++ b/x-pack/legacy/plugins/siem/public/components/resize_handle/is_resizing.tsx @@ -6,7 +6,7 @@ import { useState } from 'react'; -export const isContainerResizing = () => { +export const useIsContainerResizing = () => { const [isResizing, setIsResizing] = useState(false); return { diff --git a/x-pack/legacy/plugins/siem/public/components/scroll_to_top/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/scroll_to_top/index.test.tsx index 26006f9b2bc17b..988bb13841fa52 100644 --- a/x-pack/legacy/plugins/siem/public/components/scroll_to_top/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/scroll_to_top/index.test.tsx @@ -8,7 +8,7 @@ import { mount } from 'enzyme'; import * as React from 'react'; import { globalNode, HookWrapper } from '../../mock'; -import { scrollToTop } from '.'; +import { useScrollToTop } from '.'; const spyScroll = jest.fn(); const spyScrollTo = jest.fn(); @@ -21,7 +21,7 @@ describe('Scroll to top', () => { test('scroll have been called', () => { Object.defineProperty(globalNode.window, 'scroll', { value: spyScroll }); - mount( scrollToTop()} />); + mount( useScrollToTop()} />); expect(spyScroll).toHaveBeenCalledWith(0, 0); }); @@ -29,7 +29,7 @@ describe('Scroll to top', () => { test('scrollTo have been called', () => { Object.defineProperty(globalNode.window, 'scroll', { value: null }); Object.defineProperty(globalNode.window, 'scrollTo', { value: spyScrollTo }); - mount( scrollToTop()} />); + mount( useScrollToTop()} />); expect(spyScrollTo).toHaveBeenCalled(); }); }); diff --git a/x-pack/legacy/plugins/siem/public/components/scroll_to_top/index.tsx b/x-pack/legacy/plugins/siem/public/components/scroll_to_top/index.tsx index d696ff02ed6d85..8d4548516fc16d 100644 --- a/x-pack/legacy/plugins/siem/public/components/scroll_to_top/index.tsx +++ b/x-pack/legacy/plugins/siem/public/components/scroll_to_top/index.tsx @@ -6,7 +6,7 @@ import { useEffect } from 'react'; -export const scrollToTop = () => { +export const useScrollToTop = () => { useEffect(() => { // trying to use new API - https://developer.mozilla.org/en-US/docs/Web/API/Window/scrollTo if (window.scroll) { diff --git a/x-pack/legacy/plugins/siem/public/components/timeline/body/column_headers/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/timeline/body/column_headers/index.test.tsx index f54538eed5b263..370f864f51f3c7 100644 --- a/x-pack/legacy/plugins/siem/public/components/timeline/body/column_headers/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/timeline/body/column_headers/index.test.tsx @@ -19,7 +19,7 @@ import { ColumnHeadersComponent } from '.'; jest.mock('../../../resize_handle/is_resizing', () => ({ ...jest.requireActual('../../../resize_handle/is_resizing'), - isContainerResizing: () => ({ + useIsContainerResizing: () => ({ isResizing: true, setIsResizing: jest.fn(), }), diff --git a/x-pack/legacy/plugins/siem/public/components/timeline/body/column_headers/index.tsx b/x-pack/legacy/plugins/siem/public/components/timeline/body/column_headers/index.tsx index f590b1a32f639a..f6562b4db064d4 100644 --- a/x-pack/legacy/plugins/siem/public/components/timeline/body/column_headers/index.tsx +++ b/x-pack/legacy/plugins/siem/public/components/timeline/body/column_headers/index.tsx @@ -18,7 +18,7 @@ import { import { DraggableFieldBadge } from '../../../draggables/field_badge'; import { StatefulFieldsBrowser } from '../../../fields_browser'; import { FIELD_BROWSER_HEIGHT, FIELD_BROWSER_WIDTH } from '../../../fields_browser/helpers'; -import { isContainerResizing } from '../../../resize_handle/is_resizing'; +import { useIsContainerResizing } from '../../../resize_handle/is_resizing'; import { OnColumnRemoved, OnColumnResized, @@ -71,7 +71,7 @@ export const ColumnHeadersComponent = ({ timelineId, toggleColumn, }: Props) => { - const { isResizing, setIsResizing } = isContainerResizing(); + const { isResizing, setIsResizing } = useIsContainerResizing(); return ( diff --git a/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/endgame/endgame_security_event_details_line.tsx b/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/endgame/endgame_security_event_details_line.tsx index 97138580618ba2..185e9c9a8287a2 100644 --- a/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/endgame/endgame_security_event_details_line.tsx +++ b/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/endgame/endgame_security_event_details_line.tsx @@ -18,7 +18,7 @@ import { getHumanReadableLogonType, getUserDomainField, getUserNameField, - useTargetUserAndTargetDomain, + getTargetUserAndTargetDomain, } from './helpers'; import * as i18n from './translations'; @@ -65,10 +65,10 @@ export const EndgameSecurityEventDetailsLine = React.memo( userName, winlogEventId, }) => { - const domain = useTargetUserAndTargetDomain(eventAction) ? endgameTargetDomainName : userDomain; + const domain = getTargetUserAndTargetDomain(eventAction) ? endgameTargetDomainName : userDomain; const eventDetails = getEventDetails(eventAction); const hostNameSeparator = getHostNameSeparator(eventAction); - const user = useTargetUserAndTargetDomain(eventAction) ? endgameTargetUserName : userName; + const user = getTargetUserAndTargetDomain(eventAction) ? endgameTargetUserName : userName; const userDomainField = getUserDomainField(eventAction); const userNameField = getUserNameField(eventAction); diff --git a/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/endgame/helpers.test.tsx b/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/endgame/helpers.test.tsx index 06a24730242a8d..dd57239adc94e3 100644 --- a/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/endgame/helpers.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/endgame/helpers.test.tsx @@ -7,7 +7,7 @@ import { getHostNameSeparator, getHumanReadableLogonType, - useTargetUserAndTargetDomain, + getTargetUserAndTargetDomain, getUserDomainField, getUserNameField, getEventDetails, @@ -102,29 +102,29 @@ describe('helpers', () => { }); }); - describe('#useTargetUserAndTargetDomain', () => { + describe('#getTargetUserAndTargetDomain', () => { test('it returns false when eventAction is undefined', () => { - expect(useTargetUserAndTargetDomain(undefined)).toEqual(false); + expect(getTargetUserAndTargetDomain(undefined)).toEqual(false); }); test('it returns false when eventAction is null', () => { - expect(useTargetUserAndTargetDomain(null)).toEqual(false); + expect(getTargetUserAndTargetDomain(null)).toEqual(false); }); test('it returns false when eventAction is an empty string', () => { - expect(useTargetUserAndTargetDomain('')).toEqual(false); + expect(getTargetUserAndTargetDomain('')).toEqual(false); }); test('it returns false when eventAction is a random value', () => { - expect(useTargetUserAndTargetDomain('a random value')).toEqual(false); + expect(getTargetUserAndTargetDomain('a random value')).toEqual(false); }); test('it returns true when eventAction is "explicit_user_logon"', () => { - expect(useTargetUserAndTargetDomain('explicit_user_logon')).toEqual(true); + expect(getTargetUserAndTargetDomain('explicit_user_logon')).toEqual(true); }); test('it returns true when eventAction is "user_logoff"', () => { - expect(useTargetUserAndTargetDomain('user_logoff')).toEqual(true); + expect(getTargetUserAndTargetDomain('user_logoff')).toEqual(true); }); }); diff --git a/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/endgame/helpers.ts b/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/endgame/helpers.ts index 7470c3618fe5c3..0912238004d5a4 100644 --- a/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/endgame/helpers.ts +++ b/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/endgame/helpers.ts @@ -40,14 +40,14 @@ export const getHumanReadableLogonType = (endgameLogonType: number | null | unde export const getHostNameSeparator = (eventAction: string | null | undefined): string => eventAction === 'explicit_user_logon' ? i18n.TO : '@'; -export const useTargetUserAndTargetDomain = (eventAction: string | null | undefined): boolean => +export const getTargetUserAndTargetDomain = (eventAction: string | null | undefined): boolean => eventAction === 'explicit_user_logon' || eventAction === 'user_logoff'; export const getUserDomainField = (eventAction: string | null | undefined): string => - useTargetUserAndTargetDomain(eventAction) ? 'endgame.target_domain_name' : 'user.domain'; + getTargetUserAndTargetDomain(eventAction) ? 'endgame.target_domain_name' : 'user.domain'; export const getUserNameField = (eventAction: string | null | undefined): string => - useTargetUserAndTargetDomain(eventAction) ? 'endgame.target_user_name' : 'user.name'; + getTargetUserAndTargetDomain(eventAction) ? 'endgame.target_user_name' : 'user.name'; export const getEventDetails = (eventAction: string | null | undefined): string => { switch (eventAction) { diff --git a/x-pack/legacy/plugins/siem/public/components/timeline/properties/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/timeline/properties/index.test.tsx index 8c586cf958417e..eb82241b04124c 100644 --- a/x-pack/legacy/plugins/siem/public/components/timeline/properties/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/timeline/properties/index.test.tsx @@ -21,6 +21,10 @@ mockUseKibanaCore.mockImplementation(() => ({ uiSettings: mockUiSettings, })); +jest.mock('ui/vis/lib/timezone', () => ({ + timezoneProvider: () => () => 'America/New_York', +})); + describe('Properties', () => { const usersViewing = ['elastic']; diff --git a/x-pack/legacy/plugins/siem/public/components/toasters/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/toasters/index.test.tsx index bf98412c2a6394..5ef5a5ab31d4bd 100644 --- a/x-pack/legacy/plugins/siem/public/components/toasters/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/toasters/index.test.tsx @@ -47,7 +47,6 @@ describe('Toaster', () => { ); wrapper.find('[data-test-subj="add-toast"]').simulate('click'); - wrapper.update(); expect(wrapper.find('[data-test-subj="add-toaster-id-super-id"]').exists()).toBe(true); }); test('we can delete a toast in the reducer', () => { @@ -61,7 +60,7 @@ describe('Toaster', () => { return ( <>