kibana/examples/portable_dashboards_example/public/plugin.tsx
Nathan Reese e2380afd7b
[dashboard] Lazy DashboardRenderer (#192754)
Changes
1. expose DashboardRenderer as lazy loaded component to reduce static
page load size
2. Use `onApiAvailable` prop to pass DashboardApi to parent instead of
`forwardRef`
3. Decouple DashboardApi from legacy embeddable system. This changed
functions such as `updateInput` and using redux `select` to access
state.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
2024-09-17 13:15:50 -06:00

64 lines
2.4 KiB
TypeScript
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/
import { AppMountParameters, CoreSetup, CoreStart, Plugin } from '@kbn/core/public';
import { DashboardStart } from '@kbn/dashboard-plugin/public';
import type { DataPublicPluginStart } from '@kbn/data-plugin/public';
import type { DeveloperExamplesSetup } from '@kbn/developer-examples-plugin/public';
import { EmbeddableSetup } from '@kbn/embeddable-plugin/public';
import type { NavigationPublicPluginStart } from '@kbn/navigation-plugin/public';
import { FILTER_DEBUGGER_EMBEDDABLE_ID, PLUGIN_ID } from './constants';
import img from './portable_dashboard_image.png';
interface SetupDeps {
developerExamples: DeveloperExamplesSetup;
embeddable: EmbeddableSetup;
}
export interface StartDeps {
dashboard: DashboardStart;
data: DataPublicPluginStart;
navigation: NavigationPublicPluginStart;
}
export class PortableDashboardsExamplePlugin implements Plugin<void, void, SetupDeps, StartDeps> {
public setup(core: CoreSetup<StartDeps>, { developerExamples, embeddable }: SetupDeps) {
core.application.register({
id: PLUGIN_ID,
title: 'Portable dashboard examples',
visibleIn: [],
async mount(params: AppMountParameters) {
const [coreStart, depsStart] = await core.getStartServices();
const { renderApp } = await import('./app');
return renderApp(coreStart, depsStart, params);
},
});
developerExamples.register({
appId: PLUGIN_ID,
title: 'Portable Dashboards',
description: `Showcases different ways to embed a dashboard into your app`,
image: img,
});
embeddable.registerReactEmbeddableFactory(FILTER_DEBUGGER_EMBEDDABLE_ID, async () => {
const { factory } = await import('./filter_debugger_embeddable');
return factory;
});
}
public async start(core: CoreStart, deps: StartDeps) {
deps.dashboard.registerDashboardPanelPlacementSetting(FILTER_DEBUGGER_EMBEDDABLE_ID, () => ({
width: 48,
height: 12,
}));
}
public stop() {}
}