mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[canvas] Fix Storybook service decorator (#104750)
This commit is contained in:
parent
85c93b84e4
commit
dc81d13008
3 changed files with 23 additions and 21 deletions
|
@ -21,6 +21,6 @@ export const addDecorators = () => {
|
|||
|
||||
addDecorator(kibanaContextDecorator);
|
||||
addDecorator(routerContextDecorator);
|
||||
addDecorator(servicesContextDecorator);
|
||||
addDecorator(legacyContextDecorator());
|
||||
addDecorator(servicesContextDecorator());
|
||||
};
|
||||
|
|
|
@ -11,30 +11,35 @@ import { DecoratorFn } from '@storybook/react';
|
|||
import { I18nProvider } from '@kbn/i18n/react';
|
||||
|
||||
import { PluginServiceRegistry } from '../../../../../src/plugins/presentation_util/public';
|
||||
import { pluginServices, LegacyServicesProvider } from '../../public/services';
|
||||
import { CanvasPluginServices } from '../../public/services';
|
||||
import { pluginServices, CanvasPluginServices } from '../../public/services';
|
||||
import { pluginServiceProviders, StorybookParams } from '../../public/services/storybook';
|
||||
import { LegacyServicesProvider } from '../../public/services/legacy';
|
||||
import { startServices } from '../../public/services/legacy/stubs';
|
||||
|
||||
export const servicesContextDecorator: DecoratorFn = (story: Function, storybook) => {
|
||||
if (process.env.JEST_WORKER_ID !== undefined) {
|
||||
storybook.args.useStaticData = true;
|
||||
}
|
||||
|
||||
export const servicesContextDecorator = (): DecoratorFn => {
|
||||
const pluginServiceRegistry = new PluginServiceRegistry<CanvasPluginServices, StorybookParams>(
|
||||
pluginServiceProviders
|
||||
);
|
||||
|
||||
pluginServices.setRegistry(pluginServiceRegistry.start(storybook.args));
|
||||
pluginServices.setRegistry(pluginServiceRegistry.start({}));
|
||||
|
||||
const ContextProvider = pluginServices.getContextProvider();
|
||||
return (story: Function, storybook) => {
|
||||
if (process.env.JEST_WORKER_ID !== undefined) {
|
||||
storybook.args.useStaticData = true;
|
||||
}
|
||||
|
||||
return (
|
||||
<I18nProvider>
|
||||
<ContextProvider>{story()}</ContextProvider>
|
||||
</I18nProvider>
|
||||
);
|
||||
pluginServices.setRegistry(pluginServiceRegistry.start(storybook.args));
|
||||
const ContextProvider = pluginServices.getContextProvider();
|
||||
|
||||
return (
|
||||
<I18nProvider>
|
||||
<ContextProvider>{story()}</ContextProvider>
|
||||
</I18nProvider>
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
export const legacyContextDecorator = () => (story: Function) => (
|
||||
<LegacyServicesProvider>{story()}</LegacyServicesProvider>
|
||||
);
|
||||
export const legacyContextDecorator = () => {
|
||||
startServices();
|
||||
return (story: Function) => <LegacyServicesProvider>{story()}</LegacyServicesProvider>;
|
||||
};
|
||||
|
|
|
@ -7,14 +7,11 @@
|
|||
|
||||
import { addParameters } from '@storybook/react';
|
||||
|
||||
import { startServices } from '../public/services/stubs';
|
||||
import { addDecorators } from './decorators';
|
||||
|
||||
// Import Canvas CSS
|
||||
import '../public/style/index.scss';
|
||||
|
||||
startServices();
|
||||
|
||||
addDecorators();
|
||||
addParameters({
|
||||
controls: { hideNoControlsWarning: true },
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue