Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix eslint #49595

Merged
merged 14 commits into from
Oct 30, 2019
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -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<PersistedLog | undefined>(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<HTMLButtonElement>) {
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() });
Expand Down Expand Up @@ -184,7 +184,7 @@ function QueryBarTopRowUI(props: Props) {
screenTitle={props.screenTitle}
onChange={onQueryChange}
onSubmit={onInputSubmit}
persistedLog={persistedLog}
persistedLog={persistedLog.current}
/>
</EuiFlexItem>
);
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 @@ -33,14 +33,14 @@ const timefilterSetupMock = timefilterServiceMock.createSetupContract();

jest.mock('../../../../../data/public', () => {
return {
FilterBar: () => <div className="filterBar"></div>,
QueryBarInput: () => <div className="queryBar"></div>,
FilterBar: () => <div className="filterBar" />,
QueryBarInput: () => <div className="queryBar" />,
};
});

jest.mock('../../../query/query_bar', () => {
return {
QueryBarTopRow: () => <div className="queryBar"></div>,
QueryBarTopRow: () => <div className="queryBar" />,
};
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ class SearchBarUI extends Component<SearchBarProps, State> {
onLoad={this.onLoadSavedQuery}
savedQueryService={this.savedQueryService}
onClearSavedQuery={this.props.onClearSavedQuery}
></SavedQueryManagementComponent>
/>
);

let queryBar;
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jest.mock('ui/new_platform');

const dataShim = {
ui: {
SearchBar: () => <div className="searchBar"></div>,
SearchBar: () => <div className="searchBar" />,
},
};

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: 1 addition & 1 deletion src/plugins/kibana_react/public/util/use_unmount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
import { useEffect } from 'react';

export function useUnmount(fn: () => void): void {
useEffect(() => fn, []);
useEffect(() => fn, [fn]);
}
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