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

[Canvas] Added KibanaThemeProvider to expression_reveal_image. #120094

Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

import React from 'react';
import { storiesOf } from '@storybook/react';
import { errorRenderer } from '../error_renderer';
import { getErrorRenderer } from '../error_renderer';
import { Render } from '../../../../presentation_util/public/__stories__';

storiesOf('renderers/error', module).add('default', () => {
const thrownError = new Error('There was an error');
const config = {
error: thrownError,
};
return <Render renderer={errorRenderer} config={config} />;
return <Render renderer={getErrorRenderer()} config={config} />;
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@

import { render, unmountComponentAtNode } from 'react-dom';
import React from 'react';
import { Observable } from 'rxjs';
import { CoreTheme } from 'kibana/public';
import { ExpressionRenderDefinition } from 'src/plugins/expressions/common';
import { i18n } from '@kbn/i18n';
import { withSuspense } from '../../../../../src/plugins/presentation_util/public';
import { CoreSetup } from '../../../../core/public';
import { KibanaThemeProvider } from '../../../kibana_react/public';
import { withSuspense, defaultTheme$ } from '../../../../../src/plugins/presentation_util/public';
import { LazyDebugRenderComponent } from '../components';
import { JSON } from '../../common';

Expand All @@ -30,13 +34,22 @@ const strings = {
}),
};

export const debugRenderer = (): ExpressionRenderDefinition<any> => ({
name: 'debug',
displayName: strings.getDisplayName(),
help: strings.getHelpDescription(),
reuseDomNode: true,
render(domNode, config, handlers) {
handlers.onDestroy(() => unmountComponentAtNode(domNode));
render(<Debug parentNode={domNode} payload={config} onLoaded={handlers.done} />, domNode);
},
});
export const getDebugRenderer =
(theme$: Observable<CoreTheme> = defaultTheme$) =>
(): ExpressionRenderDefinition<any> => ({
name: 'debug',
displayName: strings.getDisplayName(),
help: strings.getHelpDescription(),
reuseDomNode: true,
render(domNode, config, handlers) {
handlers.onDestroy(() => unmountComponentAtNode(domNode));
render(
<KibanaThemeProvider theme$={theme$}>
<Debug parentNode={domNode} payload={config} onLoaded={handlers.done} />
</KibanaThemeProvider>,
domNode
);
},
});

export const debugRendererFactory = (core: CoreSetup) => getDebugRenderer(core.theme.theme$);
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import React from 'react';
import { render, unmountComponentAtNode } from 'react-dom';
import { Observable } from 'rxjs';
import { CoreTheme } from 'kibana/public';
import { I18nProvider } from '@kbn/i18n-react';
import { i18n } from '@kbn/i18n';
import { ExpressionRenderDefinition, IInterpreterRenderHandlers } from 'src/plugins/expressions';
import { withSuspense } from '../../../presentation_util/public';
import { CoreSetup } from '../../../../core/public';
import { KibanaThemeProvider } from '../../../kibana_react/public';
import { withSuspense, defaultTheme$ } from '../../../presentation_util/public';
import { ErrorRendererConfig } from '../../common/types';
import { LazyErrorRenderComponent } from '../components';

Expand All @@ -27,25 +32,31 @@ const errorStrings = {

const ErrorComponent = withSuspense(LazyErrorRenderComponent);

export const errorRenderer = (): ExpressionRenderDefinition<ErrorRendererConfig> => ({
name: 'error',
displayName: errorStrings.getDisplayName(),
help: errorStrings.getHelpDescription(),
reuseDomNode: true,
render: async (
domNode: HTMLElement,
config: ErrorRendererConfig,
handlers: IInterpreterRenderHandlers
) => {
handlers.onDestroy(() => {
unmountComponentAtNode(domNode);
});
export const getErrorRenderer =
(theme$: Observable<CoreTheme> = defaultTheme$) =>
(): ExpressionRenderDefinition<ErrorRendererConfig> => ({
name: 'error',
displayName: errorStrings.getDisplayName(),
help: errorStrings.getHelpDescription(),
reuseDomNode: true,
render: async (
domNode: HTMLElement,
config: ErrorRendererConfig,
handlers: IInterpreterRenderHandlers
) => {
handlers.onDestroy(() => {
unmountComponentAtNode(domNode);
});

render(
<KibanaThemeProvider theme$={theme$}>
<I18nProvider>
<ErrorComponent onLoaded={handlers.done} {...config} parentNode={domNode} />
</I18nProvider>
</KibanaThemeProvider>,
domNode
);
},
});

render(
<I18nProvider>
<ErrorComponent onLoaded={handlers.done} {...config} parentNode={domNode} />
</I18nProvider>,
domNode
);
},
});
export const errorRendererFactory = (core: CoreSetup) => getErrorRenderer(core.theme.theme$);
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,5 @@
* Side Public License, v 1.
*/

import { errorRenderer } from './error_renderer';
import { debugRenderer } from './debug_renderer';

export const renderers = [errorRenderer, debugRenderer];

export { errorRenderer, debugRenderer };
export { getErrorRenderer, errorRendererFactory } from './error_renderer';
export { getDebugRenderer, debugRendererFactory } from './debug_renderer';
11 changes: 7 additions & 4 deletions src/plugins/expression_error/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
* Side Public License, v 1.
*/

// TODO: https://github.com/elastic/kibana/issues/110893
/* eslint-disable @kbn/eslint/no_export_all */

import { ExpressionErrorPlugin } from './plugin';

export type { ExpressionErrorPluginSetup, ExpressionErrorPluginStart } from './plugin';
Expand All @@ -17,5 +14,11 @@ export function plugin() {
return new ExpressionErrorPlugin();
}

export * from './expression_renderers';
export {
getErrorRenderer,
getDebugRenderer,
errorRendererFactory,
debugRendererFactory,
} from './expression_renderers';

export { LazyDebugComponent, LazyErrorComponent } from './components';
6 changes: 3 additions & 3 deletions src/plugins/expression_error/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import { CoreSetup, CoreStart, Plugin } from '../../../core/public';
import { ExpressionsStart, ExpressionsSetup } from '../../expressions/public';
import { errorRenderer, debugRenderer } from './expression_renderers';
import { debugRendererFactory, errorRendererFactory } from './expression_renderers';

interface SetupDeps {
expressions: ExpressionsSetup;
Expand All @@ -25,8 +25,8 @@ export class ExpressionErrorPlugin
implements Plugin<ExpressionErrorPluginSetup, ExpressionErrorPluginStart, SetupDeps, StartDeps>
{
public setup(core: CoreSetup, { expressions }: SetupDeps): ExpressionErrorPluginSetup {
expressions.registerRenderer(errorRenderer);
expressions.registerRenderer(debugRenderer);
expressions.registerRenderer(errorRendererFactory(core));
expressions.registerRenderer(debugRendererFactory(core));
}

public start(core: CoreStart): ExpressionErrorPluginStart {}
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/expression_reveal_image/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
"ui": true,
"requiredPlugins": ["expressions", "presentationUtil"],
"optionalPlugins": [],
"requiredBundles": []
"requiredBundles": ["kibanaReact"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import React from 'react';
import { storiesOf } from '@storybook/react';
import { revealImageRenderer } from '../';
import { getRevealImageRenderer } from '../';
import { getElasticOutline, getElasticLogo } from '../../../../presentation_util/public';
import { Render, waitFor } from '../../../../presentation_util/public/__stories__';
import { Origin } from '../../../common/types/expression_functions';
Expand All @@ -26,7 +26,7 @@ const Renderer = ({
origin: Origin.LEFT,
percent: 0.45,
};
return <Render renderer={revealImageRenderer} config={config} />;
return <Render renderer={getRevealImageRenderer()} config={config} />;
};

storiesOf('renderers/revealImage', module).add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,4 @@
* Side Public License, v 1.
*/

import { revealImageRenderer } from './reveal_image_renderer';

export const renderers = [revealImageRenderer];

export { revealImageRenderer };
export { revealImageRendererFactory, getRevealImageRenderer } from './reveal_image_renderer';
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@
*/
import React, { lazy } from 'react';
import { render, unmountComponentAtNode } from 'react-dom';
import { Observable } from 'rxjs';
import { CoreTheme } from 'kibana/public';
import { I18nProvider } from '@kbn/i18n-react';
import { ExpressionRenderDefinition, IInterpreterRenderHandlers } from 'src/plugins/expressions';
import { i18n } from '@kbn/i18n';
import { withSuspense } from '../../../presentation_util/public';
import { CoreSetup } from '../../../../core/public';
import { KibanaThemeProvider } from '../../../kibana_react/public';
import { withSuspense, defaultTheme$ } from '../../../presentation_util/public';
import { RevealImageRendererConfig } from '../../common/types';

export const strings = {
Expand All @@ -27,25 +31,32 @@ export const strings = {
const LazyRevealImageComponent = lazy(() => import('../components/reveal_image_component'));
const RevealImageComponent = withSuspense(LazyRevealImageComponent, null);

export const revealImageRenderer = (): ExpressionRenderDefinition<RevealImageRendererConfig> => ({
name: 'revealImage',
displayName: strings.getDisplayName(),
help: strings.getHelpDescription(),
reuseDomNode: true,
render: (
domNode: HTMLElement,
config: RevealImageRendererConfig,
handlers: IInterpreterRenderHandlers
) => {
handlers.onDestroy(() => {
unmountComponentAtNode(domNode);
});
export const getRevealImageRenderer =
(theme$: Observable<CoreTheme> = defaultTheme$) =>
(): ExpressionRenderDefinition<RevealImageRendererConfig> => ({
name: 'revealImage',
displayName: strings.getDisplayName(),
help: strings.getHelpDescription(),
reuseDomNode: true,
render: (
domNode: HTMLElement,
config: RevealImageRendererConfig,
handlers: IInterpreterRenderHandlers
) => {
handlers.onDestroy(() => {
unmountComponentAtNode(domNode);
});

render(
<I18nProvider>
<RevealImageComponent onLoaded={handlers.done} {...config} parentNode={domNode} />
</I18nProvider>,
domNode
);
},
});
render(
<KibanaThemeProvider theme$={theme$}>
<I18nProvider>
<RevealImageComponent onLoaded={handlers.done} {...config} parentNode={domNode} />
</I18nProvider>
</KibanaThemeProvider>,
domNode
);
},
});

export const revealImageRendererFactory = (core: CoreSetup) =>
getRevealImageRenderer(core.theme.theme$);
5 changes: 1 addition & 4 deletions src/plugins/expression_reveal_image/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
* Side Public License, v 1.
*/

// TODO: https://github.com/elastic/kibana/issues/110893
/* eslint-disable @kbn/eslint/no_export_all */

import { ExpressionRevealImagePlugin } from './plugin';

export type { ExpressionRevealImagePluginSetup, ExpressionRevealImagePluginStart } from './plugin';
Expand All @@ -17,4 +14,4 @@ export function plugin() {
return new ExpressionRevealImagePlugin();
}

export * from './expression_renderers';
export { revealImageRendererFactory, getRevealImageRenderer } from './expression_renderers';
4 changes: 2 additions & 2 deletions src/plugins/expression_reveal_image/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import { CoreSetup, CoreStart, Plugin } from '../../../core/public';
import { ExpressionsStart, ExpressionsSetup } from '../../expressions/public';
import { revealImageRenderer } from './expression_renderers';
import { revealImageRendererFactory } from './expression_renderers';
import { revealImageFunction } from '../common/expression_functions';

interface SetupDeps {
Expand All @@ -33,7 +33,7 @@ export class ExpressionRevealImagePlugin
{
public setup(core: CoreSetup, { expressions }: SetupDeps): ExpressionRevealImagePluginSetup {
expressions.registerFunction(revealImageFunction);
expressions.registerRenderer(revealImageRenderer);
expressions.registerRenderer(revealImageRendererFactory(core));
}

public start(core: CoreStart): ExpressionRevealImagePluginStart {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* 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.
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { CoreTheme } from 'kibana/public';
import { Observable } from 'rxjs';

Expand Down
1 change: 1 addition & 0 deletions src/plugins/presentation_util/common/lib/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export * from './dataurl';
export * from './httpurl';
export * from './resolve_dataurl';
export * from './url';
export { defaultTheme$ } from './default_theme';

export async function getElasticLogo() {
return await import('./elastic_logo');
Expand Down
16 changes: 10 additions & 6 deletions x-pack/plugins/canvas/canvas_plugin_src/renderers/external.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,27 @@

import { imageRenderer } from '../../../../../src/plugins/expression_image/public';
import { metricRenderer } from '../../../../../src/plugins/expression_metric/public';
import { errorRenderer, debugRenderer } from '../../../../../src/plugins/expression_error/public';
import {
errorRendererFactory,
debugRendererFactory,
} from '../../../../../src/plugins/expression_error/public';
import { repeatImageRenderer } from '../../../../../src/plugins/expression_repeat_image/public';
import { revealImageRenderer } from '../../../../../src/plugins/expression_reveal_image/public';
import { revealImageRendererFactory } from '../../../../../src/plugins/expression_reveal_image/public';
import {
shapeRenderer,
progressRenderer,
} from '../../../../../src/plugins/expression_shape/public';

export const renderFunctions = [
debugRenderer,
errorRenderer,
imageRenderer,
metricRenderer,
revealImageRenderer,
shapeRenderer,
repeatImageRenderer,
progressRenderer,
];

export const renderFunctionFactories = [];
export const renderFunctionFactories = [
debugRendererFactory,
errorRendererFactory,
revealImageRendererFactory,
];
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import ReactDOM from 'react-dom';
import { CoreTheme } from 'kibana/public';
import { Observable } from 'rxjs';
import { KibanaThemeProvider } from '../../../../../../src/plugins/kibana_react/public';
import { defaultTheme$ } from '../../../../../../src/plugins/presentation_util/common/lib';
import { StartInitializer } from '../../plugin';
import { RendererStrings } from '../../../i18n';
import { Return as Config } from '../../functions/browser/markdown';
import { Markdown } from '../../../../../../src/plugins/kibana_react/public';
import { RendererFactory } from '../../../types';
import { defaultTheme$ } from '../../../public/lib/default_theme';

const { markdown: strings } = RendererStrings;

Expand Down
Loading