Skip to content

Commit

Permalink
[canvas] Relocate Legacy Services; create Workpad Service (#103386) (#…
Browse files Browse the repository at this point in the history
…104010)

Co-authored-by: Kibana Machine <[email protected]>

Co-authored-by: Clint Andrew Hall <[email protected]>
  • Loading branch information
kibanamachine and clintandrewhall authored Jun 30, 2021
1 parent 67835fb commit 7bae1da
Show file tree
Hide file tree
Showing 50 changed files with 1,930 additions and 542 deletions.
10 changes: 10 additions & 0 deletions src/plugins/presentation_util/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ export {
getStubPluginServices,
} from './services';

export {
KibanaPluginServiceFactory,
PluginServiceFactory,
PluginServices,
PluginServiceProviders,
PluginServiceProvider,
PluginServiceRegistry,
KibanaPluginServiceParams,
} from './services/create';

export { PresentationUtilPluginSetup, PresentationUtilPluginStart } from './types';
export { SaveModalDashboardProps } from './components/types';
export { projectIDs, ProjectID, Project } from '../common/labs';
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/canvas/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ module.exports = {
preset: '@kbn/test',
rootDir: '../../..',
roots: ['<rootDir>/x-pack/plugins/canvas'],
transform: {
'^.+\\.stories\\.tsx?$': '@storybook/addon-storyshots/injectFileName',
},
};
57 changes: 35 additions & 22 deletions x-pack/plugins/canvas/public/application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ import { includes, remove } from 'lodash';

import { AppMountParameters, CoreStart, CoreSetup, AppUpdater } from 'kibana/public';

import { KibanaContextProvider } from '../../../../src/plugins/kibana_react/public';
import { PluginServices } from '../../../../src/plugins/presentation_util/public';

import { CanvasStartDeps, CanvasSetupDeps } from './plugin';
import { App } from './components/app';
import { KibanaContextProvider } from '../../../../src/plugins/kibana_react/public';
import { registerLanguage } from './lib/monaco_language_def';
import { SetupRegistries } from './plugin_api';
import { initRegistries, populateRegistries, destroyRegistries } from './registries';
Expand All @@ -30,7 +32,7 @@ import { init as initStatsReporter } from './lib/ui_metric';

import { CapabilitiesStrings } from '../i18n';

import { startServices, services, ServicesProvider } from './services';
import { startServices, services, LegacyServicesProvider, CanvasPluginServices } from './services';
import { initFunctions } from './functions';
// @ts-expect-error untyped local
import { appUnload } from './state/actions/app';
Expand All @@ -44,27 +46,38 @@ import './style/index.scss';

const { ReadOnlyBadge: strings } = CapabilitiesStrings;

export const renderApp = (
coreStart: CoreStart,
plugins: CanvasStartDeps,
{ element }: AppMountParameters,
canvasStore: Store
) => {
const { presentationUtil } = plugins;
export const renderApp = ({
coreStart,
startPlugins,
params,
canvasStore,
pluginServices,
}: {
coreStart: CoreStart;
startPlugins: CanvasStartDeps;
params: AppMountParameters;
canvasStore: Store;
pluginServices: PluginServices<CanvasPluginServices>;
}) => {
const { presentationUtil } = startPlugins;
const { element } = params;
element.classList.add('canvas');
element.classList.add('canvasContainerWrapper');
const ServicesContextProvider = pluginServices.getContextProvider();

ReactDOM.render(
<KibanaContextProvider services={{ ...plugins, ...coreStart }}>
<ServicesProvider providers={services}>
<presentationUtil.ContextProvider>
<I18nProvider>
<Provider store={canvasStore}>
<App />
</Provider>
</I18nProvider>
</presentationUtil.ContextProvider>
</ServicesProvider>
<KibanaContextProvider services={{ ...startPlugins, ...coreStart }}>
<ServicesContextProvider>
<LegacyServicesProvider providers={services}>
<presentationUtil.ContextProvider>
<I18nProvider>
<Provider store={canvasStore}>
<App />
</Provider>
</I18nProvider>
</presentationUtil.ContextProvider>
</LegacyServicesProvider>
</ServicesContextProvider>
</KibanaContextProvider>,
element
);
Expand All @@ -89,7 +102,7 @@ export const initializeCanvas = async (
// of our bundle entry point. Moving them here pushes that load to when canvas is actually loaded.
const canvasFunctions = initFunctions({
timefilter: setupPlugins.data.query.timefilter.timefilter,
prependBasePath: coreSetup.http.basePath.prepend,
prependBasePath: coreStart.http.basePath.prepend,
types: setupPlugins.expressions.getTypes(),
paletteService: await setupPlugins.charts.palettes.getPalettes(),
});
Expand All @@ -99,7 +112,7 @@ export const initializeCanvas = async (
}

// Create Store
const canvasStore = await createStore(coreSetup, setupPlugins);
const canvasStore = await createStore(coreSetup);

registerLanguage(Object.values(services.expressions.getService().getFunctions()));

Expand Down Expand Up @@ -147,7 +160,7 @@ export const initializeCanvas = async (
return canvasStore;
};

export const teardownCanvas = (coreStart: CoreStart, startPlugins: CanvasStartDeps) => {
export const teardownCanvas = (coreStart: CoreStart) => {
destroyRegistries();

// Canvas pollutes the jQuery plot plugins collection with custom plugins that only work in Canvas.
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 8 additions & 15 deletions x-pack/plugins/canvas/public/components/home/home.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,17 @@

import React from 'react';

import {
reduxDecorator,
getAddonPanelParameters,
servicesContextDecorator,
getDisableStoryshotsParameter,
} from '../../../storybook';
import { reduxDecorator } from '../../../storybook';
import { argTypes } from '../../services/storybook';

import { Home } from './home.component';
import { Home } from './home';

export default {
title: 'Home/Home Page',
argTypes: {},
title: 'Home',
component: Home,
argTypes,
decorators: [reduxDecorator()],
parameters: { ...getAddonPanelParameters(), ...getDisableStoryshotsParameter() },
parameters: {},
};

export const NoContent = () => <Home />;
export const HasContent = () => <Home />;

NoContent.decorators = [servicesContextDecorator()];
HasContent.decorators = [servicesContextDecorator({ findWorkpads: 5, findTemplates: true })];
export const HomePage = () => <Home />;

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7bae1da

Please sign in to comment.