diff --git a/x-pack/plugins/canvas/storybook/decorators/index.ts b/x-pack/plugins/canvas/storybook/decorators/index.ts index a4ea3226b7760..68481e27ae48b 100644 --- a/x-pack/plugins/canvas/storybook/decorators/index.ts +++ b/x-pack/plugins/canvas/storybook/decorators/index.ts @@ -21,6 +21,6 @@ export const addDecorators = () => { addDecorator(kibanaContextDecorator); addDecorator(routerContextDecorator); - addDecorator(servicesContextDecorator); addDecorator(legacyContextDecorator()); + addDecorator(servicesContextDecorator()); }; diff --git a/x-pack/plugins/canvas/storybook/decorators/services_decorator.tsx b/x-pack/plugins/canvas/storybook/decorators/services_decorator.tsx index fbc3f140bffcc..23dcc7b21a8b8 100644 --- a/x-pack/plugins/canvas/storybook/decorators/services_decorator.tsx +++ b/x-pack/plugins/canvas/storybook/decorators/services_decorator.tsx @@ -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( 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 ( - - {story()} - - ); + pluginServices.setRegistry(pluginServiceRegistry.start(storybook.args)); + const ContextProvider = pluginServices.getContextProvider(); + + return ( + + {story()} + + ); + }; }; -export const legacyContextDecorator = () => (story: Function) => ( - {story()} -); +export const legacyContextDecorator = () => { + startServices(); + return (story: Function) => {story()}; +}; diff --git a/x-pack/plugins/canvas/storybook/preview.ts b/x-pack/plugins/canvas/storybook/preview.ts index 8eae76abaf415..040e1c3de1494 100644 --- a/x-pack/plugins/canvas/storybook/preview.ts +++ b/x-pack/plugins/canvas/storybook/preview.ts @@ -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 },