From ae0667faebeb40f38de38eda09d9d0365238b075 Mon Sep 17 00:00:00 2001 From: streamich Date: Tue, 29 Oct 2019 09:11:00 +0100 Subject: [PATCH 01/13] =?UTF-8?q?fix:=20=F0=9F=90=9B=20fix=20unused=20pers?= =?UTF-8?q?istedLog=20object?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../query/query_bar/components/query_bar_top_row.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/legacy/core_plugins/data/public/query/query_bar/components/query_bar_top_row.tsx b/src/legacy/core_plugins/data/public/query/query_bar/components/query_bar_top_row.tsx index 9a846ab82f47c..9beb7e78e95ff 100644 --- a/src/legacy/core_plugins/data/public/query/query_bar/components/query_bar_top_row.tsx +++ b/src/legacy/core_plugins/data/public/query/query_bar/components/query_bar_top_row.tsx @@ -78,16 +78,16 @@ function QueryBarTopRowUI(props: Props) { const kueryQuerySyntaxLink: string = docLinks!.links.query.kueryQuerySyntax; const queryLanguage = props.query && props.query.language; - let persistedLog: PersistedLog | undefined; + const persistedLog = React.useRef(undefined); useEffect(() => { if (!props.query) return; - persistedLog = getQueryLog(uiSettings!, store, appName, props.query.language); + persistedLog.current = getQueryLog(uiSettings!, store, appName, props.query.language); }, [queryLanguage]); function onClickSubmitButton(event: React.MouseEvent) { - if (persistedLog && props.query) { - persistedLog.add(props.query.query); + if (persistedLog.current && props.query) { + persistedLog.current.add(props.query.query); } event.preventDefault(); onSubmit({ query: props.query, dateRange: getDateRange() }); @@ -184,7 +184,7 @@ function QueryBarTopRowUI(props: Props) { screenTitle={props.screenTitle} onChange={onQueryChange} onSubmit={onInputSubmit} - persistedLog={persistedLog} + persistedLog={persistedLog.current} /> ); From 3e0a97152eb1d6205060d65644abccc054066c7e Mon Sep 17 00:00:00 2001 From: streamich Date: Tue, 29 Oct 2019 09:11:36 +0100 Subject: [PATCH 02/13] =?UTF-8?q?chore:=20=F0=9F=A4=96=20ignore=20ESLint?= =?UTF-8?q?=20rule?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/kibana_utils/public/store/react.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/plugins/kibana_utils/public/store/react.ts b/src/plugins/kibana_utils/public/store/react.ts index d561f9bb3cf34..00861b2b0b8fe 100644 --- a/src/plugins/kibana_utils/public/store/react.ts +++ b/src/plugins/kibana_utils/public/store/react.ts @@ -86,10 +86,12 @@ export const createContext = < comparator?: Comparator ): Result => { const { state$, get } = useStore(); + /* eslint-disable react-hooks/exhaustive-deps */ const [observable$, unsubscribe] = useMemo( () => observableSelector(get(), state$, selector, comparator), [state$] ); + /* eslint-enable react-hooks/exhaustive-deps */ useLayoutEffect(() => unsubscribe, [observable$, unsubscribe]); const value = useObservable(observable$, selector(get())); return value; From 3af2256718ec670827cf89ea636cf996082a48d1 Mon Sep 17 00:00:00 2001 From: streamich Date: Tue, 29 Oct 2019 09:14:17 +0100 Subject: [PATCH 03/13] =?UTF-8?q?fix:=20=F0=9F=90=9B=20correct=20dependenc?= =?UTF-8?q?ies=20in=20useUnmount()=20hook?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/kibana_react/public/util/use_unmount.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/kibana_react/public/util/use_unmount.ts b/src/plugins/kibana_react/public/util/use_unmount.ts index 009bf8c4caa1c..f5ce163be6e6e 100644 --- a/src/plugins/kibana_react/public/util/use_unmount.ts +++ b/src/plugins/kibana_react/public/util/use_unmount.ts @@ -20,5 +20,5 @@ import { useEffect } from 'react'; export function useUnmount(fn: () => void): void { - useEffect(() => fn, []); + useEffect(() => fn, [fn]); } From 640247f973673aaf7ef7ef9fae8941391f7150a9 Mon Sep 17 00:00:00 2001 From: streamich Date: Tue, 29 Oct 2019 09:21:56 +0100 Subject: [PATCH 04/13] =?UTF-8?q?fix:=20=F0=9F=90=9B=20fix=20ESLint=20erro?= =?UTF-8?q?rs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/kibana_react/public/context/context.tsx | 6 +++--- .../public/ui_settings/use_ui_setting.test.tsx | 10 +++++----- .../kibana_react/public/ui_settings/use_ui_setting.ts | 1 + 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/plugins/kibana_react/public/context/context.tsx b/src/plugins/kibana_react/public/context/context.tsx index 630348017106a..cbae5c4638ca2 100644 --- a/src/plugins/kibana_react/public/context/context.tsx +++ b/src/plugins/kibana_react/public/context/context.tsx @@ -42,11 +42,11 @@ export const useKibana = (): KibanaReactContextValue< export const withKibana = }>( type: React.ComponentType ): React.FC> => { - const enhancedType: React.FC> = (props: Omit) => { + const EnhancedType: React.FC> = (props: Omit) => { const kibana = useKibana(); return React.createElement(type, { ...props, kibana } as Props); }; - return enhancedType; + return EnhancedType; }; export const UseKibana: React.FC<{ @@ -69,7 +69,7 @@ export const createKibanaReactContext = ( const oldValue = useKibana(); const { value: newValue } = useMemo( () => createKibanaReactContext({ ...services, ...oldValue.services, ...newServices }), - Object.keys(services) + [services, oldValue, newServices] ); return createElement(context.Provider as React.ComponentType, { value: newValue, diff --git a/src/plugins/kibana_react/public/ui_settings/use_ui_setting.test.tsx b/src/plugins/kibana_react/public/ui_settings/use_ui_setting.test.tsx index cc2a8c3fbe1fc..0879b0cb3f36a 100644 --- a/src/plugins/kibana_react/public/ui_settings/use_ui_setting.test.tsx +++ b/src/plugins/kibana_react/public/ui_settings/use_ui_setting.test.tsx @@ -106,7 +106,7 @@ describe('useUiSetting', () => { }); describe('useUiSetting$', () => { - const TestConsumer$: React.FC<{ + const TestConsumerX: React.FC<{ setting: string; newValue?: string; }> = ({ setting, newValue = '' }) => { @@ -126,7 +126,7 @@ describe('useUiSetting$', () => { ReactDOM.render( - + , container ); @@ -143,7 +143,7 @@ describe('useUiSetting$', () => { ReactDOM.render( - + , container ); @@ -159,7 +159,7 @@ describe('useUiSetting$', () => { ReactDOM.render( - + , container ); @@ -174,7 +174,7 @@ describe('useUiSetting$', () => { ReactDOM.render( - + , container ); diff --git a/src/plugins/kibana_react/public/ui_settings/use_ui_setting.ts b/src/plugins/kibana_react/public/ui_settings/use_ui_setting.ts index ddc8b2a684728..295515bfa51af 100644 --- a/src/plugins/kibana_react/public/ui_settings/use_ui_setting.ts +++ b/src/plugins/kibana_react/public/ui_settings/use_ui_setting.ts @@ -65,6 +65,7 @@ export const useUiSetting$ = (key: string, defaultValue?: T): [T, Setter] const observable$ = useMemo(() => services.uiSettings!.get$(key, defaultValue), [ key, defaultValue, + services.uiSettings, ]); const value = useObservable(observable$, services.uiSettings!.get(key, defaultValue)); const set = useCallback((newValue: T) => services.uiSettings!.set(key, newValue), [key]); From 96fc4aa6d720ac513db7af6eb89d8005ce9f68f7 Mon Sep 17 00:00:00 2001 From: streamich Date: Tue, 29 Oct 2019 09:23:54 +0100 Subject: [PATCH 05/13] =?UTF-8?q?chore:=20=F0=9F=A4=96=20disable=20ESLint?= =?UTF-8?q?=20rule?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../expressions/public/np_ready/public/expression_renderer.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/legacy/core_plugins/expressions/public/np_ready/public/expression_renderer.tsx b/src/legacy/core_plugins/expressions/public/np_ready/public/expression_renderer.tsx index 8359663610f29..c7635017caef2 100644 --- a/src/legacy/core_plugins/expressions/public/np_ready/public/expression_renderer.tsx +++ b/src/legacy/core_plugins/expressions/public/np_ready/public/expression_renderer.tsx @@ -57,6 +57,7 @@ export const ExpressionRendererImplementation = ({ const [state, setState] = useState({ ...defaultState }); // Re-fetch data automatically when the inputs change + /* eslint-disable react-hooks/exhaustive-deps */ useEffect(() => { if (handlerRef.current) { handlerRef.current.update(expression, options); @@ -68,6 +69,7 @@ export const ExpressionRendererImplementation = ({ options.variables, options.disableCaching, ]); + /* eslint-enable react-hooks/exhaustive-deps */ // Initialize the loader only once useEffect(() => { From 90ad79dd4ab2bd4ed31aae2e3228560b1bc9b1dd Mon Sep 17 00:00:00 2001 From: streamich Date: Tue, 29 Oct 2019 09:25:05 +0100 Subject: [PATCH 06/13] =?UTF-8?q?fix:=20=F0=9F=90=9B=20add=20savedQuerySer?= =?UTF-8?q?vice=20to=20dependency=20list?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/saved_query_management/save_query_form.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/legacy/core_plugins/data/public/search/search_bar/components/saved_query_management/save_query_form.tsx b/src/legacy/core_plugins/data/public/search/search_bar/components/saved_query_management/save_query_form.tsx index 6fd5274d09ec6..7a9786f5f9ce8 100644 --- a/src/legacy/core_plugins/data/public/search/search_bar/components/saved_query_management/save_query_form.tsx +++ b/src/legacy/core_plugins/data/public/search/search_bar/components/saved_query_management/save_query_form.tsx @@ -83,7 +83,7 @@ export const SaveQueryForm: FunctionComponent = ({ setSavedQueries(sortedAllSavedQueries); }; fetchQueries(); - }, []); + }, [savedQueryService]); const savedQueryDescriptionText = i18n.translate( 'data.search.searchBar.savedQueryDescriptionText', From b795174d8399b0645e46fa8d0639658c7908a8bb Mon Sep 17 00:00:00 2001 From: streamich Date: Tue, 29 Oct 2019 09:28:16 +0100 Subject: [PATCH 07/13] =?UTF-8?q?fix:=20=F0=9F=90=9B=20fix=20ESLint=20erro?= =?UTF-8?q?rs=20in=20data=20plugin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../saved_query_management_component.tsx | 2 +- .../public/search/search_bar/components/search_bar.test.tsx | 6 +++--- .../data/public/search/search_bar/components/search_bar.tsx | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/legacy/core_plugins/data/public/search/search_bar/components/saved_query_management/saved_query_management_component.tsx b/src/legacy/core_plugins/data/public/search/search_bar/components/saved_query_management/saved_query_management_component.tsx index b2e47e8b4e850..56116e155eb2f 100644 --- a/src/legacy/core_plugins/data/public/search/search_bar/components/saved_query_management/saved_query_management_component.tsx +++ b/src/legacy/core_plugins/data/public/search/search_bar/components/saved_query_management/saved_query_management_component.tsx @@ -75,7 +75,7 @@ export const SavedQueryManagementComponent: FunctionComponent = ({ if (isOpen) { fetchCountAndSavedQueries(); } - }, [isOpen, activePage]); + }, [isOpen, activePage, savedQueryService]); const goToPage = (pageNumber: number) => { setActivePage(pageNumber); diff --git a/src/legacy/core_plugins/data/public/search/search_bar/components/search_bar.test.tsx b/src/legacy/core_plugins/data/public/search/search_bar/components/search_bar.test.tsx index 73e81a38572c3..929b5889db0d1 100644 --- a/src/legacy/core_plugins/data/public/search/search_bar/components/search_bar.test.tsx +++ b/src/legacy/core_plugins/data/public/search/search_bar/components/search_bar.test.tsx @@ -33,14 +33,14 @@ const timefilterSetupMock = timefilterServiceMock.createSetupContract(); jest.mock('../../../../../data/public', () => { return { - FilterBar: () =>
, - QueryBarInput: () =>
, + FilterBar: () =>
, + QueryBarInput: () =>
, }; }); jest.mock('../../../query/query_bar', () => { return { - QueryBarTopRow: () =>
, + QueryBarTopRow: () =>
, }; }); diff --git a/src/legacy/core_plugins/data/public/search/search_bar/components/search_bar.tsx b/src/legacy/core_plugins/data/public/search/search_bar/components/search_bar.tsx index a03019da4e0d7..c7f8b02caf853 100644 --- a/src/legacy/core_plugins/data/public/search/search_bar/components/search_bar.tsx +++ b/src/legacy/core_plugins/data/public/search/search_bar/components/search_bar.tsx @@ -368,7 +368,7 @@ class SearchBarUI extends Component { onLoad={this.onLoadSavedQuery} savedQueryService={this.savedQueryService} onClearSavedQuery={this.props.onClearSavedQuery} - > + /> ); let queryBar; From 30ffbe3532715c3e4f91122245b1f624a424cb2b Mon Sep 17 00:00:00 2001 From: streamich Date: Tue, 29 Oct 2019 09:33:08 +0100 Subject: [PATCH 08/13] =?UTF-8?q?chore:=20=F0=9F=A4=96=20fix=20self-closin?= =?UTF-8?q?g=20ESLint=20rule?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../navigation/public/top_nav_menu/top_nav_menu.test.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/legacy/core_plugins/navigation/public/top_nav_menu/top_nav_menu.test.tsx b/src/legacy/core_plugins/navigation/public/top_nav_menu/top_nav_menu.test.tsx index 803119bdac119..4f8c5d11f1916 100644 --- a/src/legacy/core_plugins/navigation/public/top_nav_menu/top_nav_menu.test.tsx +++ b/src/legacy/core_plugins/navigation/public/top_nav_menu/top_nav_menu.test.tsx @@ -29,7 +29,7 @@ jest.mock('ui/new_platform'); const dataShim = { ui: { - SearchBar: () =>
, + SearchBar: () =>
, }, }; From 71743d3bd11ec42da9c07cd3fa2c7d0ebc5ddf02 Mon Sep 17 00:00:00 2001 From: streamich Date: Tue, 29 Oct 2019 11:35:28 +0100 Subject: [PATCH 09/13] =?UTF-8?q?test:=20=F0=9F=92=8D=20update=20Jest=20sn?= =?UTF-8?q?apshot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../query_bar_input.test.tsx.snap | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/legacy/core_plugins/data/public/query/query_bar/components/__snapshots__/query_bar_input.test.tsx.snap b/src/legacy/core_plugins/data/public/query/query_bar/components/__snapshots__/query_bar_input.test.tsx.snap index 286e60cca9712..106e9339a231c 100644 --- a/src/legacy/core_plugins/data/public/query/query_bar/components/__snapshots__/query_bar_input.test.tsx.snap +++ b/src/legacy/core_plugins/data/public/query/query_bar/components/__snapshots__/query_bar_input.test.tsx.snap @@ -349,7 +349,7 @@ exports[`QueryBarInput Should disable autoFocus on EuiFieldText when disableAuto } } > - - - - + + @@ -1463,7 +1463,7 @@ exports[`QueryBarInput Should pass the query language to the language switcher 1 } } > - - - - + + @@ -2574,7 +2574,7 @@ exports[`QueryBarInput Should render the given query 1`] = ` } } > - - - - + + From b0f9b00fa6fc54c31314026bce576fee8f1d9602 Mon Sep 17 00:00:00 2001 From: streamich Date: Tue, 29 Oct 2019 11:38:14 +0100 Subject: [PATCH 10/13] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20memoize=20pers?= =?UTF-8?q?istedLog=20in=20more=20idiomatic=20way?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../query_bar/components/query_bar_top_row.tsx | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/legacy/core_plugins/data/public/query/query_bar/components/query_bar_top_row.tsx b/src/legacy/core_plugins/data/public/query/query_bar/components/query_bar_top_row.tsx index 9beb7e78e95ff..3a6f94afaa88b 100644 --- a/src/legacy/core_plugins/data/public/query/query_bar/components/query_bar_top_row.tsx +++ b/src/legacy/core_plugins/data/public/query/query_bar/components/query_bar_top_row.tsx @@ -77,17 +77,15 @@ function QueryBarTopRowUI(props: Props) { const kueryQuerySyntaxLink: string = docLinks!.links.query.kueryQuerySyntax; - const queryLanguage = props.query && props.query.language; - const persistedLog = React.useRef(undefined); - - useEffect(() => { - if (!props.query) return; - persistedLog.current = getQueryLog(uiSettings!, store, appName, props.query.language); - }, [queryLanguage]); + const persistedLog: PersistedLog | undefined = React.useMemo( + () => + props.query ? getQueryLog(uiSettings!, store, appName, props.query.language) : undefined, + [props.query] + ); function onClickSubmitButton(event: React.MouseEvent) { - if (persistedLog.current && props.query) { - persistedLog.current.add(props.query.query); + if (persistedLog && props.query) { + persistedLog.add(props.query.query); } event.preventDefault(); onSubmit({ query: props.query, dateRange: getDateRange() }); @@ -184,7 +182,7 @@ function QueryBarTopRowUI(props: Props) { screenTitle={props.screenTitle} onChange={onQueryChange} onSubmit={onInputSubmit} - persistedLog={persistedLog.current} + persistedLog={persistedLog} /> ); From bb2e88a12ef44a12dbbed1b131efe6e6856eeacc Mon Sep 17 00:00:00 2001 From: streamich Date: Tue, 29 Oct 2019 13:15:47 +0100 Subject: [PATCH 11/13] =?UTF-8?q?chore:=20=F0=9F=A4=96=20remomve=20unused?= =?UTF-8?q?=20import?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../public/query/query_bar/components/query_bar_top_row.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/legacy/core_plugins/data/public/query/query_bar/components/query_bar_top_row.tsx b/src/legacy/core_plugins/data/public/query/query_bar/components/query_bar_top_row.tsx index 3a6f94afaa88b..5fd3886e41737 100644 --- a/src/legacy/core_plugins/data/public/query/query_bar/components/query_bar_top_row.tsx +++ b/src/legacy/core_plugins/data/public/query/query_bar/components/query_bar_top_row.tsx @@ -21,7 +21,7 @@ import dateMath from '@elastic/datemath'; import { doesKueryExpressionHaveLuceneSyntaxError } from '@kbn/es-query'; import classNames from 'classnames'; -import React, { useState, useEffect } from 'react'; +import React, { useState } from 'react'; import { EuiButton, From 89b1563718d8c04429acf8b27f5872993f50ac13 Mon Sep 17 00:00:00 2001 From: streamich Date: Tue, 29 Oct 2019 13:58:31 +0100 Subject: [PATCH 12/13] =?UTF-8?q?chore:=20=F0=9F=A4=96=20revert=20possible?= =?UTF-8?q?=20test=20breaker?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/kibana_react/public/util/use_unmount.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/kibana_react/public/util/use_unmount.ts b/src/plugins/kibana_react/public/util/use_unmount.ts index f5ce163be6e6e..009bf8c4caa1c 100644 --- a/src/plugins/kibana_react/public/util/use_unmount.ts +++ b/src/plugins/kibana_react/public/util/use_unmount.ts @@ -20,5 +20,5 @@ import { useEffect } from 'react'; export function useUnmount(fn: () => void): void { - useEffect(() => fn, [fn]); + useEffect(() => fn, []); } From 65042099e2e591d7d436b56ca21c87bbe0a8e6e8 Mon Sep 17 00:00:00 2001 From: streamich Date: Wed, 30 Oct 2019 11:20:17 +0100 Subject: [PATCH 13/13] =?UTF-8?q?fix:=20=F0=9F=90=9B=20fix=20query=20bar?= =?UTF-8?q?=20merge=20errors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../public/query/query_bar/components/query_bar_top_row.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/legacy/core_plugins/data/public/query/query_bar/components/query_bar_top_row.tsx b/src/legacy/core_plugins/data/public/query/query_bar/components/query_bar_top_row.tsx index 2b76a3e0a735c..d2953621d86d1 100644 --- a/src/legacy/core_plugins/data/public/query/query_bar/components/query_bar_top_row.tsx +++ b/src/legacy/core_plugins/data/public/query/query_bar/components/query_bar_top_row.tsx @@ -79,8 +79,7 @@ function QueryBarTopRowUI(props: Props) { const queryLanguage = props.query && props.query.language; const persistedLog: PersistedLog | undefined = React.useMemo( - () => - queryLanguage ? getQueryLog(uiSettings!, store, appName, queryLanguage) : undefined, + () => (queryLanguage ? getQueryLog(uiSettings!, storage, appName, queryLanguage) : undefined), [queryLanguage] );