Skip to content

Commit

Permalink
[Observability] Wraps render tree with KibanaThemeProvider (elastic#1…
Browse files Browse the repository at this point in the history
…20400)

* Treats application root

* Treats toMountPoint - part I
  • Loading branch information
claudiopro authored and TinLe committed Dec 22, 2021
1 parent ebbde37 commit 3fe91d8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { createMemoryHistory } from 'history';
import React from 'react';
import { Observable } from 'rxjs';
import { AppMountParameters, CoreStart } from 'src/core/public';
import { themeServiceMock } from '../../../../../src/core/public/mocks';
import { KibanaPageTemplate } from '../../../../../src/plugins/kibana_react/public';
import { ObservabilityPublicPluginsStart } from '../plugin';
import { createObservabilityRuleTypeRegistryMock } from '../rules/observability_rule_type_registry_mock';
Expand Down Expand Up @@ -45,6 +46,7 @@ describe('renderApp', () => {
i18n: { Context: ({ children }: { children: React.ReactNode }) => children },
uiSettings: { get: () => false },
http: { basePath: { prepend: (path: string) => path } },
theme: themeServiceMock.createStartContract(),
} as unknown as CoreStart;
const config = {
unsafe: {
Expand All @@ -57,6 +59,7 @@ describe('renderApp', () => {
element: window.document.createElement('div'),
history: createMemoryHistory(),
setHeaderActionMenu: () => {},
theme$: themeServiceMock.createTheme$(),
} as unknown as AppMountParameters;

expect(() => {
Expand Down
53 changes: 28 additions & 25 deletions x-pack/plugins/observability/public/application/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { AppMountParameters, APP_WRAPPER_CLASS, CoreStart } from '../../../../..
import { EuiThemeProvider } from '../../../../../src/plugins/kibana_react/common';
import {
KibanaContextProvider,
KibanaThemeProvider,
RedirectAppLinks,
} from '../../../../../src/plugins/kibana_react/public';
import { Storage } from '../../../../../src/plugins/kibana_utils/public';
Expand Down Expand Up @@ -58,7 +59,7 @@ export const renderApp = ({
appMountParameters: AppMountParameters;
ObservabilityPageTemplate: React.ComponentType<LazyObservabilityPageTemplateProps>;
}) => {
const { element, history } = appMountParameters;
const { element, history, theme$ } = appMountParameters;
const i18nCore = core.i18n;
const isDarkMode = core.uiSettings.get('theme:darkMode');

Expand All @@ -73,30 +74,32 @@ export const renderApp = ({
element.classList.add(APP_WRAPPER_CLASS);

ReactDOM.render(
<KibanaContextProvider services={{ ...core, ...plugins, storage: new Storage(localStorage) }}>
<PluginContext.Provider
value={{
appMountParameters,
config,
core,
plugins,
observabilityRuleTypeRegistry,
ObservabilityPageTemplate,
}}
>
<Router history={history}>
<EuiThemeProvider darkMode={isDarkMode}>
<i18nCore.Context>
<RedirectAppLinks application={core.application} className={APP_WRAPPER_CLASS}>
<HasDataContextProvider>
<App />
</HasDataContextProvider>
</RedirectAppLinks>
</i18nCore.Context>
</EuiThemeProvider>
</Router>
</PluginContext.Provider>
</KibanaContextProvider>,
<KibanaThemeProvider theme$={theme$}>
<KibanaContextProvider services={{ ...core, ...plugins, storage: new Storage(localStorage) }}>
<PluginContext.Provider
value={{
appMountParameters,
config,
core,
plugins,
observabilityRuleTypeRegistry,
ObservabilityPageTemplate,
}}
>
<Router history={history}>
<EuiThemeProvider darkMode={isDarkMode}>
<i18nCore.Context>
<RedirectAppLinks application={core.application} className={APP_WRAPPER_CLASS}>
<HasDataContextProvider>
<App />
</HasDataContextProvider>
</RedirectAppLinks>
</i18nCore.Context>
</EuiThemeProvider>
</Router>
</PluginContext.Provider>
</KibanaContextProvider>
</KibanaThemeProvider>,
element
);
return () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export function AddToCaseAction({ lensAttributes, timeRange }: AddToCaseProps) {
const {
cases,
application: { getUrlForApp },
theme,
} = kServices;

const getToastText = useCallback(
Expand All @@ -41,9 +42,10 @@ export function AddToCaseAction({ lensAttributes, timeRange }: AddToCaseProps) {
deepLinkId: CasesDeepLinkId.cases,
path: generateCaseViewPath({ detailName: theCase.id }),
})}
/>
/>,
{ theme$: theme?.theme$ }
),
[getUrlForApp]
[getUrlForApp, theme?.theme$]
);

const absoluteFromDate = parseRelativeDate(timeRange.from);
Expand Down

0 comments on commit 3fe91d8

Please sign in to comment.