Skip to content

Commit

Permalink
Fix eslint (#49595) (#49725)
Browse files Browse the repository at this point in the history
* fix: πŸ› fix unused persistedLog object

* chore: πŸ€– ignore ESLint rule

* fix: πŸ› correct dependencies in useUnmount() hook

* fix: πŸ› fix ESLint errors

* chore: πŸ€– disable ESLint rule

* fix: πŸ› add savedQueryService to dependency list

* fix: πŸ› fix ESLint errors in data plugin

* chore: πŸ€– fix self-closing ESLint rule

* test: πŸ’ update Jest snapshot

* refactor: πŸ’‘ memoize persistedLog in more idiomatic way

* chore: πŸ€– remomve unused import

* chore: πŸ€– revert possible test breaker

* fix: πŸ› fix query bar merge errors
  • Loading branch information
streamich authored Oct 30, 2019
1 parent cb9c582 commit af7e9fa
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 29 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -78,12 +78,10 @@ function QueryBarTopRowUI(props: Props) {
const kueryQuerySyntaxLink: string = docLinks!.links.query.kueryQuerySyntax;

const queryLanguage = props.query && props.query.language;
let persistedLog: PersistedLog | undefined;

useEffect(() => {
if (!props.query) return;
persistedLog = getQueryLog(uiSettings!, storage, appName, props.query.language);
}, [queryLanguage]);
const persistedLog: PersistedLog | undefined = React.useMemo(
() => (queryLanguage ? getQueryLog(uiSettings!, storage, appName, queryLanguage) : undefined),
[queryLanguage]
);

function onClickSubmitButton(event: React.MouseEvent<HTMLButtonElement>) {
if (persistedLog && props.query) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export const SaveQueryForm: FunctionComponent<Props> = ({
setSavedQueries(sortedAllSavedQueries);
};
fetchQueries();
}, []);
}, [savedQueryService]);

const savedQueryDescriptionText = i18n.translate(
'data.search.searchBar.savedQueryDescriptionText',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const SavedQueryManagementComponent: FunctionComponent<Props> = ({
if (isOpen) {
fetchCountAndSavedQueries();
}
}, [isOpen, activePage]);
}, [isOpen, activePage, savedQueryService]);

const goToPage = (pageNumber: number) => {
setActivePage(pageNumber);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export const ExpressionRendererImplementation = ({
const [state, setState] = useState<State>({ ...defaultState });

// Re-fetch data automatically when the inputs change
/* eslint-disable react-hooks/exhaustive-deps */
useEffect(() => {
if (handlerRef.current) {
handlerRef.current.update(expression, options);
Expand All @@ -68,6 +69,7 @@ export const ExpressionRendererImplementation = ({
options.variables,
options.disableCaching,
]);
/* eslint-enable react-hooks/exhaustive-deps */

// Initialize the loader only once
useEffect(() => {
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/kibana_react/public/context/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ export const useKibana = <Extra extends object = {}>(): KibanaReactContextValue<
export const withKibana = <Props extends { kibana: KibanaReactContextValue<any> }>(
type: React.ComponentType<Props>
): React.FC<Omit<Props, 'kibana'>> => {
const enhancedType: React.FC<Omit<Props, 'kibana'>> = (props: Omit<Props, 'kibana'>) => {
const EnhancedType: React.FC<Omit<Props, 'kibana'>> = (props: Omit<Props, 'kibana'>) => {
const kibana = useKibana();
return React.createElement(type, { ...props, kibana } as Props);
};
return enhancedType;
return EnhancedType;
};

export const UseKibana: React.FC<{
Expand All @@ -69,7 +69,7 @@ export const createKibanaReactContext = <Services extends KibanaServices>(
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<any>, {
value: newValue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ describe('useUiSetting', () => {
});

describe('useUiSetting$', () => {
const TestConsumer: React.FC<{
const TestConsumerX: React.FC<{
setting: string;
newValue?: string;
}> = ({ setting, newValue = '' }) => {
Expand All @@ -126,7 +126,7 @@ describe('useUiSetting$', () => {

ReactDOM.render(
<Provider>
<TestConsumer setting="foo" />
<TestConsumerX setting="foo" />
</Provider>,
container
);
Expand All @@ -143,7 +143,7 @@ describe('useUiSetting$', () => {

ReactDOM.render(
<Provider>
<TestConsumer setting="non_existing" />
<TestConsumerX setting="non_existing" />
</Provider>,
container
);
Expand All @@ -159,7 +159,7 @@ describe('useUiSetting$', () => {

ReactDOM.render(
<Provider>
<TestConsumer setting="theme:darkMode" />
<TestConsumerX setting="theme:darkMode" />
</Provider>,
container
);
Expand All @@ -174,7 +174,7 @@ describe('useUiSetting$', () => {

ReactDOM.render(
<Provider>
<TestConsumer setting="a" newValue="c" />
<TestConsumerX setting="a" newValue="c" />
</Provider>,
container
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export const useUiSetting$ = <T>(key: string, defaultValue?: T): [T, Setter<T>]
const observable$ = useMemo(() => services.uiSettings!.get$(key, defaultValue), [
key,
defaultValue,
services.uiSettings,
]);
const value = useObservable<T>(observable$, services.uiSettings!.get(key, defaultValue));
const set = useCallback((newValue: T) => services.uiSettings!.set(key, newValue), [key]);
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/kibana_utils/public/store/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,12 @@ export const createContext = <
comparator?: Comparator<Result>
): 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;
Expand Down

0 comments on commit af7e9fa

Please sign in to comment.