2021-01-28 08:24:55 +01:00
|
|
|
/*
|
|
|
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
2021-02-04 03:12:39 +01:00
|
|
|
* or more contributor license agreements. Licensed under the Elastic License
|
|
|
|
* 2.0; you may not use this file except in compliance with the Elastic License
|
|
|
|
* 2.0.
|
2021-01-28 08:24:55 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
import { EuiErrorBoundary } from '@elastic/eui';
|
|
|
|
import euiDarkVars from '@elastic/eui/dist/eui_theme_dark.json';
|
|
|
|
import euiLightVars from '@elastic/eui/dist/eui_theme_light.json';
|
|
|
|
import React, { useMemo } from 'react';
|
|
|
|
import ReactDOM from 'react-dom';
|
|
|
|
import { Router } from 'react-router-dom';
|
|
|
|
import { I18nProvider } from '@kbn/i18n/react';
|
|
|
|
import { ThemeProvider } from 'styled-components';
|
2021-04-19 20:10:34 +02:00
|
|
|
import { QueryClientProvider } from 'react-query';
|
2021-03-09 13:25:47 +01:00
|
|
|
import { ReactQueryDevtools } from 'react-query/devtools';
|
2021-01-28 08:24:55 +01:00
|
|
|
|
|
|
|
import { useUiSetting$ } from '../../../../src/plugins/kibana_react/public';
|
|
|
|
import { Storage } from '../../../../src/plugins/kibana_utils/public';
|
|
|
|
import { AppMountParameters, CoreStart } from '../../../../src/core/public';
|
|
|
|
import { AppPluginStartDependencies } from './types';
|
|
|
|
import { OsqueryApp } from './components/app';
|
|
|
|
import { DEFAULT_DARK_MODE, PLUGIN_NAME } from '../common';
|
|
|
|
import { KibanaContextProvider } from './common/lib/kibana';
|
2021-04-19 20:10:34 +02:00
|
|
|
import { queryClient } from './query_client';
|
2021-03-09 13:25:47 +01:00
|
|
|
|
2021-01-28 08:24:55 +01:00
|
|
|
const OsqueryAppContext = () => {
|
|
|
|
const [darkMode] = useUiSetting$<boolean>(DEFAULT_DARK_MODE);
|
|
|
|
const theme = useMemo(
|
|
|
|
() => ({
|
|
|
|
eui: darkMode ? euiDarkVars : euiLightVars,
|
|
|
|
darkMode,
|
|
|
|
}),
|
|
|
|
[darkMode]
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ThemeProvider theme={theme}>
|
|
|
|
<OsqueryApp />
|
|
|
|
</ThemeProvider>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const renderApp = (
|
|
|
|
core: CoreStart,
|
|
|
|
services: AppPluginStartDependencies,
|
|
|
|
{ element, history }: AppMountParameters,
|
|
|
|
storage: Storage,
|
|
|
|
kibanaVersion: string
|
|
|
|
) => {
|
|
|
|
ReactDOM.render(
|
|
|
|
<KibanaContextProvider
|
|
|
|
// eslint-disable-next-line react-perf/jsx-no-new-object-as-prop
|
|
|
|
services={{
|
|
|
|
appName: PLUGIN_NAME,
|
2021-03-09 13:25:47 +01:00
|
|
|
kibanaVersion,
|
2021-01-28 08:24:55 +01:00
|
|
|
...core,
|
|
|
|
...services,
|
|
|
|
storage,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<EuiErrorBoundary>
|
|
|
|
<Router history={history}>
|
|
|
|
<I18nProvider>
|
2021-03-09 13:25:47 +01:00
|
|
|
<QueryClientProvider client={queryClient}>
|
|
|
|
<OsqueryAppContext />
|
|
|
|
<ReactQueryDevtools initialIsOpen={false} />
|
|
|
|
</QueryClientProvider>
|
2021-01-28 08:24:55 +01:00
|
|
|
</I18nProvider>
|
|
|
|
</Router>
|
|
|
|
</EuiErrorBoundary>
|
|
|
|
</KibanaContextProvider>,
|
|
|
|
element
|
|
|
|
);
|
|
|
|
|
|
|
|
return () => ReactDOM.unmountComponentAtNode(element);
|
|
|
|
};
|