From 7b8546e8bce33b54eafdef082925b3cbefdf20cf Mon Sep 17 00:00:00 2001 From: Nick Peihl Date: Fri, 3 May 2024 09:18:36 -0400 Subject: [PATCH 1/5] Move panel placement register to dashboard start contract Also renames legacy placement method --- examples/embeddable_examples/public/plugin.ts | 4 +++- .../register_field_list_embeddable.ts | 9 +++---- .../api/duplicate_dashboard_panel.ts | 2 +- .../embeddable/create/create_dashboard.ts | 2 +- .../embeddable/dashboard_container.tsx | 6 ++--- .../public/dashboard_container/index.ts | 2 +- .../{component => }/panel_placement/index.ts | 4 ++++ .../panel_placement_registry.ts} | 6 +---- .../place_clone_panel_strategy.ts | 6 ++--- .../place_new_panel_strategies.ts | 4 ++-- .../panel_placement/place_panel.test.ts | 24 +++++++++---------- .../panel_placement/place_panel.ts | 16 ++++++------- .../{component => }/panel_placement/types.ts | 14 +++++++---- src/plugins/dashboard/public/index.ts | 3 ++- src/plugins/dashboard/public/plugin.tsx | 7 ++++++ .../links_embeddable_factory.test.ts | 6 ++--- .../embeddable/links_embeddable_factory.ts | 12 ++++++---- 17 files changed, 70 insertions(+), 57 deletions(-) rename src/plugins/dashboard/public/dashboard_container/{component => }/panel_placement/index.ts (71%) rename src/plugins/dashboard/public/dashboard_container/{external_api/dashboard_panel_placement_registry.ts => panel_placement/panel_placement_registry.ts} (81%) rename src/plugins/dashboard/public/dashboard_container/{component => }/panel_placement/place_clone_panel_strategy.ts (95%) rename src/plugins/dashboard/public/dashboard_container/{component => }/panel_placement/place_new_panel_strategies.ts (97%) rename src/plugins/dashboard/public/dashboard_container/{component => }/panel_placement/place_panel.test.ts (85%) rename src/plugins/dashboard/public/dashboard_container/{component => }/panel_placement/place_panel.ts (75%) rename src/plugins/dashboard/public/dashboard_container/{component => }/panel_placement/types.ts (69%) diff --git a/examples/embeddable_examples/public/plugin.ts b/examples/embeddable_examples/public/plugin.ts index 6939271e37341..312c9630fd91e 100644 --- a/examples/embeddable_examples/public/plugin.ts +++ b/examples/embeddable_examples/public/plugin.ts @@ -8,6 +8,7 @@ import { ChartsPluginStart } from '@kbn/charts-plugin/public'; import { CoreSetup, CoreStart, Plugin } from '@kbn/core/public'; +import { DashboardStart } from '@kbn/dashboard-plugin/public'; import { DataPublicPluginStart } from '@kbn/data-plugin/public'; import { DataViewFieldEditorStart } from '@kbn/data-view-field-editor-plugin/public'; import { DataViewsPublicPluginStart } from '@kbn/data-views-plugin/public'; @@ -44,6 +45,7 @@ export interface StartDeps { data: DataPublicPluginStart; charts: ChartsPluginStart; fieldFormats: FieldFormatsStart; + dashboard: DashboardStart; } export class EmbeddableExamplesPlugin implements Plugin { @@ -59,7 +61,7 @@ export class EmbeddableExamplesPlugin implements Plugin { diff --git a/examples/embeddable_examples/public/react_embeddables/field_list/register_field_list_embeddable.ts b/examples/embeddable_examples/public/react_embeddables/field_list/register_field_list_embeddable.ts index e31df63b62f37..04bb93d7d052e 100644 --- a/examples/embeddable_examples/public/react_embeddables/field_list/register_field_list_embeddable.ts +++ b/examples/embeddable_examples/public/react_embeddables/field_list/register_field_list_embeddable.ts @@ -6,10 +6,7 @@ * Side Public License, v 1. */ -import { - registerDashboardPanelPlacementSetting, - PanelPlacementStrategy, -} from '@kbn/dashboard-plugin/public'; +import { DashboardStart, PanelPlacementStrategy } from '@kbn/dashboard-plugin/public'; import { FIELD_LIST_ID } from './constants'; import { FieldListSerializedStateState } from './types'; @@ -22,6 +19,6 @@ const getPanelPlacementSetting = (serializedState?: FieldListSerializedStateStat }; }; -export function registerFieldListPanelPlacementSetting() { - registerDashboardPanelPlacementSetting(FIELD_LIST_ID, getPanelPlacementSetting); +export function registerFieldListPanelPlacementSetting(dashboard: DashboardStart) { + dashboard.registerDashboardPanelPlacementSetting(FIELD_LIST_ID, getPanelPlacementSetting); } diff --git a/src/plugins/dashboard/public/dashboard_container/embeddable/api/duplicate_dashboard_panel.ts b/src/plugins/dashboard/public/dashboard_container/embeddable/api/duplicate_dashboard_panel.ts index 134f180db9a7b..012c0e720cb05 100644 --- a/src/plugins/dashboard/public/dashboard_container/embeddable/api/duplicate_dashboard_panel.ts +++ b/src/plugins/dashboard/public/dashboard_container/embeddable/api/duplicate_dashboard_panel.ts @@ -19,7 +19,7 @@ import { v4 as uuidv4 } from 'uuid'; import { DashboardPanelState } from '../../../../common'; import { dashboardClonePanelActionStrings } from '../../../dashboard_actions/_dashboard_actions_strings'; import { pluginServices } from '../../../services/plugin_services'; -import { placeClonePanel } from '../../component/panel_placement'; +import { placeClonePanel } from '../../panel_placement'; import { DashboardContainer } from '../dashboard_container'; const duplicateLegacyInput = async ( diff --git a/src/plugins/dashboard/public/dashboard_container/embeddable/create/create_dashboard.ts b/src/plugins/dashboard/public/dashboard_container/embeddable/create/create_dashboard.ts index 88ece952a49b5..8ef4656dee874 100644 --- a/src/plugins/dashboard/public/dashboard_container/embeddable/create/create_dashboard.ts +++ b/src/plugins/dashboard/public/dashboard_container/embeddable/create/create_dashboard.ts @@ -46,7 +46,7 @@ import { SavedDashboardInput, } from '../../../services/dashboard_content_management/types'; import { pluginServices } from '../../../services/plugin_services'; -import { runPanelPlacementStrategy } from '../../component/panel_placement/place_new_panel_strategies'; +import { runPanelPlacementStrategy } from '../../panel_placement/place_new_panel_strategies'; import { startDiffingDashboardState } from '../../state/diffing/dashboard_diffing_integration'; import { DashboardPublicState } from '../../types'; import { DashboardContainer } from '../dashboard_container'; diff --git a/src/plugins/dashboard/public/dashboard_container/embeddable/dashboard_container.tsx b/src/plugins/dashboard/public/dashboard_container/embeddable/dashboard_container.tsx index 69fdf28647c09..d3ba52c97edf2 100644 --- a/src/plugins/dashboard/public/dashboard_container/embeddable/dashboard_container.tsx +++ b/src/plugins/dashboard/public/dashboard_container/embeddable/dashboard_container.tsx @@ -62,11 +62,11 @@ import { import { DashboardAnalyticsService } from '../../services/analytics/types'; import { DashboardCapabilitiesService } from '../../services/dashboard_capabilities/types'; import { pluginServices } from '../../services/plugin_services'; -import { placePanel } from '../component/panel_placement'; -import { runPanelPlacementStrategy } from '../component/panel_placement/place_new_panel_strategies'; +import { placePanel } from '../panel_placement'; +import { runPanelPlacementStrategy } from '../panel_placement/place_new_panel_strategies'; import { DashboardViewport } from '../component/viewport/dashboard_viewport'; import { DashboardExternallyAccessibleApi } from '../external_api/dashboard_api'; -import { getDashboardPanelPlacementSetting } from '../external_api/dashboard_panel_placement_registry'; +import { getDashboardPanelPlacementSetting } from '../panel_placement/panel_placement_registry'; import { dashboardContainerReducers } from '../state/dashboard_container_reducers'; import { getDiffingMiddleware } from '../state/diffing/dashboard_diffing_integration'; import { diff --git a/src/plugins/dashboard/public/dashboard_container/index.ts b/src/plugins/dashboard/public/dashboard_container/index.ts index c8944968e6cb7..20b9966850e20 100644 --- a/src/plugins/dashboard/public/dashboard_container/index.ts +++ b/src/plugins/dashboard/public/dashboard_container/index.ts @@ -22,5 +22,5 @@ export { export { DashboardRenderer } from './external_api/dashboard_renderer'; export type { DashboardAPI, AwaitingDashboardAPI } from './external_api/dashboard_api'; -export { registerDashboardPanelPlacementSetting } from './external_api/dashboard_panel_placement_registry'; export type { DashboardLocatorParams } from './types'; +export type { IProvidesLegacyPanelPlacementSettings } from './panel_placement'; diff --git a/src/plugins/dashboard/public/dashboard_container/component/panel_placement/index.ts b/src/plugins/dashboard/public/dashboard_container/panel_placement/index.ts similarity index 71% rename from src/plugins/dashboard/public/dashboard_container/component/panel_placement/index.ts rename to src/plugins/dashboard/public/dashboard_container/panel_placement/index.ts index 8e7444712c281..8ab73cf928277 100644 --- a/src/plugins/dashboard/public/dashboard_container/component/panel_placement/index.ts +++ b/src/plugins/dashboard/public/dashboard_container/panel_placement/index.ts @@ -9,3 +9,7 @@ export { placePanel } from './place_panel'; export { placeClonePanel } from './place_clone_panel_strategy'; + +export { registerDashboardPanelPlacementSetting } from './panel_placement_registry'; + +export type { GetPanelPlacementSettings, IProvidesLegacyPanelPlacementSettings } from './types'; diff --git a/src/plugins/dashboard/public/dashboard_container/external_api/dashboard_panel_placement_registry.ts b/src/plugins/dashboard/public/dashboard_container/panel_placement/panel_placement_registry.ts similarity index 81% rename from src/plugins/dashboard/public/dashboard_container/external_api/dashboard_panel_placement_registry.ts rename to src/plugins/dashboard/public/dashboard_container/panel_placement/panel_placement_registry.ts index e21fedb9aabe1..98fab7c662506 100644 --- a/src/plugins/dashboard/public/dashboard_container/external_api/dashboard_panel_placement_registry.ts +++ b/src/plugins/dashboard/public/dashboard_container/panel_placement/panel_placement_registry.ts @@ -6,13 +6,9 @@ * Side Public License, v 1. */ -import { PanelPlacementSettings } from '../component/panel_placement/types'; +import { GetPanelPlacementSettings } from './types'; import { panelPlacementStrings } from '../_dashboard_container_strings'; -type GetPanelPlacementSettings = ( - serializedState?: SerializedState -) => PanelPlacementSettings; - const registry = new Map>(); export const registerDashboardPanelPlacementSetting = ( diff --git a/src/plugins/dashboard/public/dashboard_container/component/panel_placement/place_clone_panel_strategy.ts b/src/plugins/dashboard/public/dashboard_container/panel_placement/place_clone_panel_strategy.ts similarity index 95% rename from src/plugins/dashboard/public/dashboard_container/component/panel_placement/place_clone_panel_strategy.ts rename to src/plugins/dashboard/public/dashboard_container/panel_placement/place_clone_panel_strategy.ts index affe85dff5d26..cbd56ad26eca2 100644 --- a/src/plugins/dashboard/public/dashboard_container/component/panel_placement/place_clone_panel_strategy.ts +++ b/src/plugins/dashboard/public/dashboard_container/panel_placement/place_clone_panel_strategy.ts @@ -9,10 +9,10 @@ import { cloneDeep, forOwn } from 'lodash'; import { PanelNotFoundError } from '@kbn/embeddable-plugin/public'; -import { DashboardPanelState } from '../../../../common'; -import { GridData } from '../../../../common/content_management'; +import { DashboardPanelState } from '../../../common'; +import { GridData } from '../../../common/content_management'; import { PanelPlacementProps, PanelPlacementReturn } from './types'; -import { DASHBOARD_GRID_COLUMN_COUNT } from '../../../dashboard_constants'; +import { DASHBOARD_GRID_COLUMN_COUNT } from '../../dashboard_constants'; interface IplacementDirection { grid: Omit; diff --git a/src/plugins/dashboard/public/dashboard_container/component/panel_placement/place_new_panel_strategies.ts b/src/plugins/dashboard/public/dashboard_container/panel_placement/place_new_panel_strategies.ts similarity index 97% rename from src/plugins/dashboard/public/dashboard_container/component/panel_placement/place_new_panel_strategies.ts rename to src/plugins/dashboard/public/dashboard_container/panel_placement/place_new_panel_strategies.ts index 168dcfa72a491..9c5d6646ea5ff 100644 --- a/src/plugins/dashboard/public/dashboard_container/component/panel_placement/place_new_panel_strategies.ts +++ b/src/plugins/dashboard/public/dashboard_container/panel_placement/place_new_panel_strategies.ts @@ -7,8 +7,8 @@ */ import { cloneDeep } from 'lodash'; -import { DASHBOARD_GRID_COLUMN_COUNT, PanelPlacementStrategy } from '../../../dashboard_constants'; -import { panelPlacementStrings } from '../../_dashboard_container_strings'; +import { DASHBOARD_GRID_COLUMN_COUNT, PanelPlacementStrategy } from '../../dashboard_constants'; +import { panelPlacementStrings } from '../_dashboard_container_strings'; import { PanelPlacementProps, PanelPlacementReturn } from './types'; export const runPanelPlacementStrategy = ( diff --git a/src/plugins/dashboard/public/dashboard_container/component/panel_placement/place_panel.test.ts b/src/plugins/dashboard/public/dashboard_container/panel_placement/place_panel.test.ts similarity index 85% rename from src/plugins/dashboard/public/dashboard_container/component/panel_placement/place_panel.test.ts rename to src/plugins/dashboard/public/dashboard_container/panel_placement/place_panel.test.ts index 24023ba92dbce..2555419934e07 100644 --- a/src/plugins/dashboard/public/dashboard_container/component/panel_placement/place_panel.test.ts +++ b/src/plugins/dashboard/public/dashboard_container/panel_placement/place_panel.test.ts @@ -6,13 +6,13 @@ * Side Public License, v 1. */ -import { DashboardPanelState } from '../../../../common'; +import { DashboardPanelState } from '../../../common'; import { EmbeddableFactory, EmbeddableInput } from '@kbn/embeddable-plugin/public'; import { CONTACT_CARD_EMBEDDABLE } from '@kbn/embeddable-plugin/public/lib/test_samples'; -import { DEFAULT_PANEL_HEIGHT, DEFAULT_PANEL_WIDTH } from '../../../dashboard_constants'; +import { DEFAULT_PANEL_HEIGHT, DEFAULT_PANEL_WIDTH } from '../../dashboard_constants'; import { placePanel } from './place_panel'; -import { IProvidesPanelPlacementSettings } from './types'; +import { IProvidesLegacyPanelPlacementSettings } from './types'; interface TestInput extends EmbeddableInput { test: string; @@ -92,8 +92,8 @@ test('adds a new panel state in the top most position when it is open', () => { }); test('adds a new panel state at the very top of the Dashboard with default sizing', () => { - const embeddableFactoryStub: IProvidesPanelPlacementSettings = { - getPanelPlacementSettings: jest.fn().mockImplementation(() => { + const embeddableFactoryStub: IProvidesLegacyPanelPlacementSettings = { + getLegacyPanelPlacementSettings: jest.fn().mockImplementation(() => { return { strategy: 'placeAtTop' }; }), }; @@ -111,15 +111,15 @@ test('adds a new panel state at the very top of the Dashboard with default sizin expect(panelState.gridData.h).toBe(DEFAULT_PANEL_HEIGHT); expect(panelState.gridData.w).toBe(DEFAULT_PANEL_WIDTH); - expect(embeddableFactoryStub.getPanelPlacementSettings).toHaveBeenCalledWith( + expect(embeddableFactoryStub.getLegacyPanelPlacementSettings).toHaveBeenCalledWith( { id: '9001', test: 'wowee' }, undefined ); }); test('adds a new panel state at the very top of the Dashboard with custom sizing', () => { - const embeddableFactoryStub: IProvidesPanelPlacementSettings = { - getPanelPlacementSettings: jest.fn().mockImplementation(() => { + const embeddableFactoryStub: IProvidesLegacyPanelPlacementSettings = { + getLegacyPanelPlacementSettings: jest.fn().mockImplementation(() => { return { strategy: 'placeAtTop', width: 10, height: 5 }; }), }; @@ -137,15 +137,15 @@ test('adds a new panel state at the very top of the Dashboard with custom sizing expect(panelState.gridData.h).toBe(5); expect(panelState.gridData.w).toBe(10); - expect(embeddableFactoryStub.getPanelPlacementSettings).toHaveBeenCalledWith( + expect(embeddableFactoryStub.getLegacyPanelPlacementSettings).toHaveBeenCalledWith( { id: '9002', test: 'woweee' }, undefined ); }); test('passes through given attributes', () => { - const embeddableFactoryStub: IProvidesPanelPlacementSettings = { - getPanelPlacementSettings: jest.fn().mockImplementation(() => { + const embeddableFactoryStub: IProvidesLegacyPanelPlacementSettings = { + getLegacyPanelPlacementSettings: jest.fn().mockImplementation(() => { return { strategy: 'placeAtTop', width: 10, height: 5 }; }), }; @@ -160,7 +160,7 @@ test('passes through given attributes', () => { { testAttr: 'hello' } ); - expect(embeddableFactoryStub.getPanelPlacementSettings).toHaveBeenCalledWith( + expect(embeddableFactoryStub.getLegacyPanelPlacementSettings).toHaveBeenCalledWith( { id: '9004', test: 'wow' }, { testAttr: 'hello' } ); diff --git a/src/plugins/dashboard/public/dashboard_container/component/panel_placement/place_panel.ts b/src/plugins/dashboard/public/dashboard_container/panel_placement/place_panel.ts similarity index 75% rename from src/plugins/dashboard/public/dashboard_container/component/panel_placement/place_panel.ts rename to src/plugins/dashboard/public/dashboard_container/panel_placement/place_panel.ts index c440c0fe93e10..86fe3c823e899 100644 --- a/src/plugins/dashboard/public/dashboard_container/component/panel_placement/place_panel.ts +++ b/src/plugins/dashboard/public/dashboard_container/panel_placement/place_panel.ts @@ -8,19 +8,19 @@ import { PanelState, EmbeddableInput, EmbeddableFactory } from '@kbn/embeddable-plugin/public'; -import { DashboardPanelState } from '../../../../common'; -import { IProvidesPanelPlacementSettings } from './types'; +import { DashboardPanelState } from '../../../common'; +import { IProvidesLegacyPanelPlacementSettings } from './types'; import { runPanelPlacementStrategy } from './place_new_panel_strategies'; import { DEFAULT_PANEL_HEIGHT, DEFAULT_PANEL_WIDTH, PanelPlacementStrategy, -} from '../../../dashboard_constants'; +} from '../../dashboard_constants'; -export const providesPanelPlacementSettings = ( +export const providesLegacyPanelPlacementSettings = ( value: unknown -): value is IProvidesPanelPlacementSettings => { - return Boolean((value as IProvidesPanelPlacementSettings).getPanelPlacementSettings); +): value is IProvidesLegacyPanelPlacementSettings => { + return Boolean((value as IProvidesLegacyPanelPlacementSettings).getLegacyPanelPlacementSettings); }; export function placePanel( @@ -37,10 +37,10 @@ export function placePanel( height: DEFAULT_PANEL_HEIGHT, strategy: PanelPlacementStrategy.findTopLeftMostOpenSpace, }; - if (providesPanelPlacementSettings(factory)) { + if (providesLegacyPanelPlacementSettings(factory)) { placementSettings = { ...placementSettings, - ...factory.getPanelPlacementSettings(newPanel.explicitInput, attributes), + ...factory.getLegacyPanelPlacementSettings(newPanel.explicitInput, attributes), }; } const { width, height, strategy } = placementSettings; diff --git a/src/plugins/dashboard/public/dashboard_container/component/panel_placement/types.ts b/src/plugins/dashboard/public/dashboard_container/panel_placement/types.ts similarity index 69% rename from src/plugins/dashboard/public/dashboard_container/component/panel_placement/types.ts rename to src/plugins/dashboard/public/dashboard_container/panel_placement/types.ts index d5fdbf705f443..54b490e004fac 100644 --- a/src/plugins/dashboard/public/dashboard_container/component/panel_placement/types.ts +++ b/src/plugins/dashboard/public/dashboard_container/panel_placement/types.ts @@ -7,9 +7,9 @@ */ import { EmbeddableInput } from '@kbn/embeddable-plugin/public'; -import { DashboardPanelState } from '../../../../common'; -import { GridData } from '../../../../common/content_management'; -import { PanelPlacementStrategy } from '../../../dashboard_constants'; +import { DashboardPanelState } from '../../../common'; +import { GridData } from '../../../common/content_management'; +import { PanelPlacementStrategy } from '../../dashboard_constants'; export interface PanelPlacementSettings { strategy?: PanelPlacementStrategy; @@ -28,12 +28,16 @@ export interface PanelPlacementProps { currentPanels: { [key: string]: DashboardPanelState }; } -export interface IProvidesPanelPlacementSettings< +export interface IProvidesLegacyPanelPlacementSettings< InputType extends EmbeddableInput = EmbeddableInput, AttributesType = unknown > { - getPanelPlacementSettings: ( + getLegacyPanelPlacementSettings: ( input: InputType, attributes?: AttributesType ) => Partial; } + +export type GetPanelPlacementSettings = ( + serializedState?: SerializedState +) => PanelPlacementSettings; diff --git a/src/plugins/dashboard/public/index.ts b/src/plugins/dashboard/public/index.ts index 3b1bafe2e1fd4..92c9f9043bc1f 100644 --- a/src/plugins/dashboard/public/index.ts +++ b/src/plugins/dashboard/public/index.ts @@ -17,13 +17,14 @@ export { PanelPlacementStrategy, } from './dashboard_constants'; export { - registerDashboardPanelPlacementSetting, type DashboardAPI, type AwaitingDashboardAPI, DashboardRenderer, DASHBOARD_CONTAINER_TYPE, type DashboardCreationOptions, type DashboardLocatorParams, + type DashboardContainer, + type IProvidesLegacyPanelPlacementSettings, } from './dashboard_container'; export type { DashboardSetup, DashboardStart, DashboardFeatureFlagConfig } from './plugin'; diff --git a/src/plugins/dashboard/public/plugin.tsx b/src/plugins/dashboard/public/plugin.tsx index 16625f7b37006..0a231492d70b9 100644 --- a/src/plugins/dashboard/public/plugin.tsx +++ b/src/plugins/dashboard/public/plugin.tsx @@ -56,6 +56,7 @@ import type { NoDataPagePluginStart } from '@kbn/no-data-page-plugin/public'; import { CustomBrandingStart } from '@kbn/core-custom-branding-browser'; import { SavedObjectsManagementPluginStart } from '@kbn/saved-objects-management-plugin/public'; import { DashboardContainerFactoryDefinition } from './dashboard_container/embeddable/dashboard_container_factory'; +import { registerDashboardPanelPlacementSetting } from './dashboard_container/panel_placement'; import { type DashboardAppLocator, DashboardAppLocatorDefinition, @@ -70,6 +71,7 @@ import { DashboardMountContextProps } from './dashboard_app/types'; import type { FindDashboardsService } from './services/dashboard_content_management/types'; import { CONTENT_ID, LATEST_VERSION } from '../common/content_management'; import { addPanelMenuTrigger } from './triggers'; +import { GetPanelPlacementSettings } from './dashboard_container/panel_placement'; export interface DashboardFeatureFlagConfig { allowByValueEmbeddables: boolean; @@ -119,6 +121,10 @@ export interface DashboardStart { locator?: DashboardAppLocator; dashboardFeatureFlagConfig: DashboardFeatureFlagConfig; findDashboardsService: () => Promise; + registerDashboardPanelPlacementSetting: ( + embeddableType: string, + getPanelPlacementSettings: GetPanelPlacementSettings + ) => void; } export let resolveServicesReady: () => void; @@ -344,6 +350,7 @@ export class DashboardPlugin return { locator: this.locator, dashboardFeatureFlagConfig: this.dashboardFeatureFlagConfig!, + registerDashboardPanelPlacementSetting, findDashboardsService: async () => { const { pluginServices } = await import('./services/plugin_services'); const { diff --git a/src/plugins/links/public/embeddable/links_embeddable_factory.test.ts b/src/plugins/links/public/embeddable/links_embeddable_factory.test.ts index 427827a1ace4b..d575c975e0295 100644 --- a/src/plugins/links/public/embeddable/links_embeddable_factory.test.ts +++ b/src/plugins/links/public/embeddable/links_embeddable_factory.test.ts @@ -12,7 +12,7 @@ import { LinksInput } from './types'; describe('linksFactory', () => { test('returns an empty object when not given proper meta information', () => { const linksFactory = new LinksFactoryDefinition(); - const settings = linksFactory.getPanelPlacementSettings({} as unknown as LinksInput, {}); + const settings = linksFactory.getLegacyPanelPlacementSettings({} as unknown as LinksInput, {}); expect(settings.height).toBeUndefined(); expect(settings.width).toBeUndefined(); expect(settings.strategy).toBeUndefined(); @@ -20,7 +20,7 @@ describe('linksFactory', () => { test('returns a horizontal layout', () => { const linksFactory = new LinksFactoryDefinition(); - const settings = linksFactory.getPanelPlacementSettings({} as unknown as LinksInput, { + const settings = linksFactory.getLegacyPanelPlacementSettings({} as unknown as LinksInput, { layout: 'horizontal', links: [], }); @@ -31,7 +31,7 @@ describe('linksFactory', () => { test('returns a vertical layout with the appropriate height', () => { const linksFactory = new LinksFactoryDefinition(); - const settings = linksFactory.getPanelPlacementSettings({} as unknown as LinksInput, { + const settings = linksFactory.getLegacyPanelPlacementSettings({} as unknown as LinksInput, { layout: 'vertical', links: [ { type: 'dashboardLink', destination: 'superDashboard1' }, diff --git a/src/plugins/links/public/embeddable/links_embeddable_factory.ts b/src/plugins/links/public/embeddable/links_embeddable_factory.ts index df629c9b1d053..eba91fe75770b 100644 --- a/src/plugins/links/public/embeddable/links_embeddable_factory.ts +++ b/src/plugins/links/public/embeddable/links_embeddable_factory.ts @@ -7,8 +7,8 @@ */ import { DASHBOARD_GRID_COLUMN_COUNT, PanelPlacementStrategy } from '@kbn/dashboard-plugin/public'; -import { DashboardContainer } from '@kbn/dashboard-plugin/public/dashboard_container'; -import { IProvidesPanelPlacementSettings } from '@kbn/dashboard-plugin/public/dashboard_container/component/panel_placement/types'; +import { DashboardContainer } from '@kbn/dashboard-plugin/public'; +import { IProvidesLegacyPanelPlacementSettings } from '@kbn/dashboard-plugin/public'; import { EmbeddableStateWithType } from '@kbn/embeddable-plugin/common'; import { EmbeddableFactory, @@ -46,7 +46,9 @@ const isLinksAttributes = (attributes?: unknown): attributes is LinksAttributes }; export class LinksFactoryDefinition - implements EmbeddableFactoryDefinition, IProvidesPanelPlacementSettings + implements + EmbeddableFactoryDefinition, + IProvidesLegacyPanelPlacementSettings { latestVersion?: string | undefined; telemetry?: @@ -64,10 +66,10 @@ export class LinksFactoryDefinition getIconForSavedObject: () => APP_ICON, }; - public getPanelPlacementSettings: IProvidesPanelPlacementSettings< + public getLegacyPanelPlacementSettings: IProvidesLegacyPanelPlacementSettings< LinksInput, LinksAttributes | unknown - >['getPanelPlacementSettings'] = (input, attributes) => { + >['getLegacyPanelPlacementSettings'] = (input, attributes) => { if (!isLinksAttributes(attributes) || !attributes.layout) { // if we have no information about the layout of this links panel defer to default panel size and placement. return {}; From c66ccd97bc2702c9366c1e6a3135cd7ff4f150aa Mon Sep 17 00:00:00 2001 From: Nick Peihl Date: Fri, 3 May 2024 11:11:59 -0400 Subject: [PATCH 2/5] Update dev docs --- .../public/app/register_embeddable.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/embeddable_examples/public/app/register_embeddable.tsx b/examples/embeddable_examples/public/app/register_embeddable.tsx index 95bac13ee0023..351828cc66c6b 100644 --- a/examples/embeddable_examples/public/app/register_embeddable.tsx +++ b/examples/embeddable_examples/public/app/register_embeddable.tsx @@ -64,10 +64,11 @@ export const RegisterEmbeddable = () => {

Configure initial dashboard placement (optional)

- Add an entry to registerDashboardPanelPlacementSetting to configure - initial dashboard placement. Panel placement lets you configure the width, height, and - placement strategy when panels get added to a dashboard. In the example below, the Field - List embeddable will be added to dashboards as a narrow and tall panel. + Add an entry to registerDashboardPanelPlacementSetting provided by the + Dashboard plugin start contract to configure initial dashboard placement. Panel placement + lets you configure the width, height, and placement strategy when panels get added to a + dashboard. In the example below, the Field List embeddable will be added to dashboards as + a narrow and tall panel.

From aa121f2c0a18fd66c3ec883894b80686313f8f74 Mon Sep 17 00:00:00 2001 From: Nick Peihl Date: Fri, 3 May 2024 11:12:13 -0400 Subject: [PATCH 3/5] Update SLO embeddable --- .../observability_solution/slo/kibana.jsonc | 4 ++-- .../slo/public/plugin.ts | 20 +++++++++---------- .../slo/public/types.ts | 2 ++ 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/x-pack/plugins/observability_solution/slo/kibana.jsonc b/x-pack/plugins/observability_solution/slo/kibana.jsonc index 587a9abe5e33f..052eaaae9e1d6 100644 --- a/x-pack/plugins/observability_solution/slo/kibana.jsonc +++ b/x-pack/plugins/observability_solution/slo/kibana.jsonc @@ -17,6 +17,7 @@ "charts", "contentManagement", "controls", + "dashboard", "data", "dataViews", "lens", @@ -49,8 +50,7 @@ "kibanaUtils", "unifiedSearch", "embeddable", - "ingestPipelines", - "dashboard" + "ingestPipelines" ] } } diff --git a/x-pack/plugins/observability_solution/slo/public/plugin.ts b/x-pack/plugins/observability_solution/slo/public/plugin.ts index 417ac1fbf75f3..ce5ff09847db2 100644 --- a/x-pack/plugins/observability_solution/slo/public/plugin.ts +++ b/x-pack/plugins/observability_solution/slo/public/plugin.ts @@ -16,7 +16,6 @@ import { } from '@kbn/core/public'; import { BehaviorSubject, firstValueFrom } from 'rxjs'; import { registerReactEmbeddableFactory } from '@kbn/embeddable-plugin/public'; -import { registerDashboardPanelPlacementSetting } from '@kbn/dashboard-plugin/public'; import { SloPublicPluginsSetup, SloPublicPluginsStart } from './types'; import { PLUGIN_NAME, sloAppId } from '../common'; import type { SloPublicSetup, SloPublicStart } from './types'; @@ -95,15 +94,6 @@ export class SloPlugin const hasPlatinumLicense = license.hasAtLeast('platinum'); if (hasPlatinumLicense) { - registerDashboardPanelPlacementSetting( - SLO_OVERVIEW_EMBEDDABLE_ID, - (serializedState: SloOverviewEmbeddableState | undefined) => { - if (serializedState?.showAllGroupByInstances || serializedState?.groupFilters) { - return { width: 24, height: 8 }; - } - return { width: 12, height: 8 }; - } - ); registerReactEmbeddableFactory(SLO_OVERVIEW_EMBEDDABLE_ID, async () => { const [coreStart, pluginsStart] = await coreSetup.getStartServices(); @@ -159,6 +149,16 @@ export class SloPlugin const kibanaVersion = this.initContext.env.packageInfo.version; const { ruleTypeRegistry, actionTypeRegistry } = pluginsStart.triggersActionsUi; + pluginsStart.dashboard.registerDashboardPanelPlacementSetting( + SLO_OVERVIEW_EMBEDDABLE_ID, + (serializedState: SloOverviewEmbeddableState | undefined) => { + if (serializedState?.showAllGroupByInstances || serializedState?.groupFilters) { + return { width: 24, height: 8 }; + } + return { width: 12, height: 8 }; + } + ); + return { getCreateSLOFlyout: getCreateSLOFlyoutLazy({ core: coreStart, diff --git a/x-pack/plugins/observability_solution/slo/public/types.ts b/x-pack/plugins/observability_solution/slo/public/types.ts index c480f79b02e78..76e2bcad185ba 100644 --- a/x-pack/plugins/observability_solution/slo/public/types.ts +++ b/x-pack/plugins/observability_solution/slo/public/types.ts @@ -15,6 +15,7 @@ import type { } from '@kbn/observability-shared-plugin/public'; import { AiopsPluginStart } from '@kbn/aiops-plugin/public/types'; import type { ChartsPluginStart } from '@kbn/charts-plugin/public'; +import { DashboardStart } from '@kbn/dashboard-plugin/public'; import type { EmbeddableStart } from '@kbn/embeddable-plugin/public'; import type { EmbeddableSetup } from '@kbn/embeddable-plugin/public'; import type { @@ -76,6 +77,7 @@ export interface SloPublicPluginsStart { aiops: AiopsPluginStart; cases: CasesPublicStart; cloud?: CloudStart; + dashboard: DashboardStart; dataViewEditor: DataViewEditorStart; fieldFormats: FieldFormatsStart; observability: ObservabilityPublicStart; From a649b03e6a79e35556721ca4d13548de4b9b2ff9 Mon Sep 17 00:00:00 2001 From: Nick Peihl Date: Fri, 3 May 2024 11:50:35 -0400 Subject: [PATCH 4/5] Type fixes --- src/plugins/dashboard/public/index.ts | 1 - .../components/dashboard_link/dashboard_link_component.test.tsx | 2 +- .../components/dashboard_link/dashboard_link_component.tsx | 2 +- .../dashboard_link/dashboard_link_destination_picker.tsx | 2 +- src/plugins/links/public/components/editor/link_destination.tsx | 2 +- src/plugins/links/public/components/editor/link_editor.tsx | 2 +- src/plugins/links/public/components/editor/links_editor.tsx | 2 +- .../links/public/components/editor/links_editor_single_link.tsx | 2 +- src/plugins/links/public/editor/open_editor_flyout.tsx | 2 +- src/plugins/links/public/editor/open_link_editor_flyout.tsx | 2 +- src/plugins/links/public/embeddable/links_embeddable.tsx | 2 +- src/plugins/links/public/embeddable/links_embeddable_factory.ts | 2 +- src/plugins/links/public/plugin.ts | 2 +- 13 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/plugins/dashboard/public/index.ts b/src/plugins/dashboard/public/index.ts index 92c9f9043bc1f..91731174eff76 100644 --- a/src/plugins/dashboard/public/index.ts +++ b/src/plugins/dashboard/public/index.ts @@ -23,7 +23,6 @@ export { DASHBOARD_CONTAINER_TYPE, type DashboardCreationOptions, type DashboardLocatorParams, - type DashboardContainer, type IProvidesLegacyPanelPlacementSettings, } from './dashboard_container'; export type { DashboardSetup, DashboardStart, DashboardFeatureFlagConfig } from './plugin'; diff --git a/src/plugins/links/public/components/dashboard_link/dashboard_link_component.test.tsx b/src/plugins/links/public/components/dashboard_link/dashboard_link_component.test.tsx index 4e6eb32319baf..84e358fdb381c 100644 --- a/src/plugins/links/public/components/dashboard_link/dashboard_link_component.test.tsx +++ b/src/plugins/links/public/components/dashboard_link/dashboard_link_component.test.tsx @@ -9,7 +9,7 @@ import React from 'react'; import { getDashboardLocatorParamsFromEmbeddable } from '@kbn/dashboard-plugin/public'; -import { DashboardContainer } from '@kbn/dashboard-plugin/public/dashboard_container'; +import type { DashboardContainer } from '@kbn/dashboard-plugin/public/dashboard_container'; import { DEFAULT_DASHBOARD_DRILLDOWN_OPTIONS } from '@kbn/presentation-util-plugin/public'; import { createEvent, fireEvent, render, screen, waitFor, within } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; diff --git a/src/plugins/links/public/components/dashboard_link/dashboard_link_component.tsx b/src/plugins/links/public/components/dashboard_link/dashboard_link_component.tsx index 57d881cecd705..202a697cd7160 100644 --- a/src/plugins/links/public/components/dashboard_link/dashboard_link_component.tsx +++ b/src/plugins/links/public/components/dashboard_link/dashboard_link_component.tsx @@ -17,7 +17,7 @@ import { DashboardLocatorParams, getDashboardLocatorParamsFromEmbeddable, } from '@kbn/dashboard-plugin/public'; -import { DashboardContainer } from '@kbn/dashboard-plugin/public/dashboard_container'; +import type { DashboardContainer } from '@kbn/dashboard-plugin/public/dashboard_container'; import { DashboardDrilldownOptions, DEFAULT_DASHBOARD_DRILLDOWN_OPTIONS, diff --git a/src/plugins/links/public/components/dashboard_link/dashboard_link_destination_picker.tsx b/src/plugins/links/public/components/dashboard_link/dashboard_link_destination_picker.tsx index 137d604c2e01e..fea0a5239ba0d 100644 --- a/src/plugins/links/public/components/dashboard_link/dashboard_link_destination_picker.tsx +++ b/src/plugins/links/public/components/dashboard_link/dashboard_link_destination_picker.tsx @@ -20,7 +20,7 @@ import { EuiFlexGroup, EuiComboBoxOptionOption, } from '@elastic/eui'; -import { DashboardContainer } from '@kbn/dashboard-plugin/public/dashboard_container'; +import type { DashboardContainer } from '@kbn/dashboard-plugin/public/dashboard_container'; import { DashboardItem } from '../../embeddable/types'; import { DashboardLinkStrings } from './dashboard_link_strings'; diff --git a/src/plugins/links/public/components/editor/link_destination.tsx b/src/plugins/links/public/components/editor/link_destination.tsx index bd33b6245ab51..5eb2d67a0d882 100644 --- a/src/plugins/links/public/components/editor/link_destination.tsx +++ b/src/plugins/links/public/components/editor/link_destination.tsx @@ -8,7 +8,7 @@ import React, { useState } from 'react'; -import { DashboardContainer } from '@kbn/dashboard-plugin/public/dashboard_container'; +import type { DashboardContainer } from '@kbn/dashboard-plugin/public/dashboard_container'; import { EuiFormRow } from '@elastic/eui'; import { diff --git a/src/plugins/links/public/components/editor/link_editor.tsx b/src/plugins/links/public/components/editor/link_editor.tsx index 7af2ddf1c57d5..ca3aeda7224bb 100644 --- a/src/plugins/links/public/components/editor/link_editor.tsx +++ b/src/plugins/links/public/components/editor/link_editor.tsx @@ -26,7 +26,7 @@ import { EuiFlyoutHeader, EuiRadioGroupOption, } from '@elastic/eui'; -import { DashboardContainer } from '@kbn/dashboard-plugin/public/dashboard_container'; +import type { DashboardContainer } from '@kbn/dashboard-plugin/public/dashboard_container'; import { LinkType, diff --git a/src/plugins/links/public/components/editor/links_editor.tsx b/src/plugins/links/public/components/editor/links_editor.tsx index 2a146ab5430cd..bd2da0041499d 100644 --- a/src/plugins/links/public/components/editor/links_editor.tsx +++ b/src/plugins/links/public/components/editor/links_editor.tsx @@ -28,7 +28,7 @@ import { EuiSwitch, EuiTitle, } from '@elastic/eui'; -import { DashboardContainer } from '@kbn/dashboard-plugin/public/dashboard_container'; +import type { DashboardContainer } from '@kbn/dashboard-plugin/public/dashboard_container'; import { Link, diff --git a/src/plugins/links/public/components/editor/links_editor_single_link.tsx b/src/plugins/links/public/components/editor/links_editor_single_link.tsx index e13913f1e349d..c69c33662c014 100644 --- a/src/plugins/links/public/components/editor/links_editor_single_link.tsx +++ b/src/plugins/links/public/components/editor/links_editor_single_link.tsx @@ -21,7 +21,7 @@ import { EuiSkeletonTitle, DraggableProvidedDragHandleProps, } from '@elastic/eui'; -import { DashboardContainer } from '@kbn/dashboard-plugin/public/dashboard_container'; +import type { DashboardContainer } from '@kbn/dashboard-plugin/public/dashboard_container'; import { LinkInfo } from '../../embeddable/types'; import { validateUrl } from '../external_link/external_link_tools'; diff --git a/src/plugins/links/public/editor/open_editor_flyout.tsx b/src/plugins/links/public/editor/open_editor_flyout.tsx index 3fc187a05be1c..8455ca16e604b 100644 --- a/src/plugins/links/public/editor/open_editor_flyout.tsx +++ b/src/plugins/links/public/editor/open_editor_flyout.tsx @@ -11,7 +11,7 @@ import { skip, take } from 'rxjs'; import { v4 as uuidv4 } from 'uuid'; import { EuiLoadingSpinner, EuiPanel } from '@elastic/eui'; -import { DashboardContainer } from '@kbn/dashboard-plugin/public/dashboard_container'; +import type { DashboardContainer } from '@kbn/dashboard-plugin/public/dashboard_container'; import { toMountPoint } from '@kbn/react-kibana-mount'; import { withSuspense } from '@kbn/shared-ux-utility'; diff --git a/src/plugins/links/public/editor/open_link_editor_flyout.tsx b/src/plugins/links/public/editor/open_link_editor_flyout.tsx index f8176d6e7e245..d3406264db4ad 100644 --- a/src/plugins/links/public/editor/open_link_editor_flyout.tsx +++ b/src/plugins/links/public/editor/open_link_editor_flyout.tsx @@ -10,7 +10,7 @@ import React from 'react'; import ReactDOM from 'react-dom'; import { KibanaRenderContextProvider } from '@kbn/react-kibana-context-render'; -import { DashboardContainer } from '@kbn/dashboard-plugin/public/dashboard_container'; +import type { DashboardContainer } from '@kbn/dashboard-plugin/public/dashboard_container'; import { coreServices } from '../services/kibana_services'; import { Link } from '../../common/content_management'; diff --git a/src/plugins/links/public/embeddable/links_embeddable.tsx b/src/plugins/links/public/embeddable/links_embeddable.tsx index d803b9df9e8c5..dcc49a7265a43 100644 --- a/src/plugins/links/public/embeddable/links_embeddable.tsx +++ b/src/plugins/links/public/embeddable/links_embeddable.tsx @@ -11,7 +11,7 @@ import React, { createContext } from 'react'; import { unmountComponentAtNode } from 'react-dom'; import { distinctUntilChanged, skip, Subject, Subscription, switchMap } from 'rxjs'; -import { DashboardContainer } from '@kbn/dashboard-plugin/public/dashboard_container'; +import type { DashboardContainer } from '@kbn/dashboard-plugin/public/dashboard_container'; import { AttributeService, Embeddable, diff --git a/src/plugins/links/public/embeddable/links_embeddable_factory.ts b/src/plugins/links/public/embeddable/links_embeddable_factory.ts index eba91fe75770b..9ff3877b8a42e 100644 --- a/src/plugins/links/public/embeddable/links_embeddable_factory.ts +++ b/src/plugins/links/public/embeddable/links_embeddable_factory.ts @@ -7,7 +7,7 @@ */ import { DASHBOARD_GRID_COLUMN_COUNT, PanelPlacementStrategy } from '@kbn/dashboard-plugin/public'; -import { DashboardContainer } from '@kbn/dashboard-plugin/public'; +import type { DashboardContainer } from '@kbn/dashboard-plugin/public/dashboard_container'; import { IProvidesLegacyPanelPlacementSettings } from '@kbn/dashboard-plugin/public'; import { EmbeddableStateWithType } from '@kbn/embeddable-plugin/common'; import { diff --git a/src/plugins/links/public/plugin.ts b/src/plugins/links/public/plugin.ts index ca13281fd2512..32788a2a283c1 100644 --- a/src/plugins/links/public/plugin.ts +++ b/src/plugins/links/public/plugin.ts @@ -12,7 +12,7 @@ import { } from '@kbn/content-management-plugin/public'; import { CoreSetup, CoreStart, Plugin } from '@kbn/core/public'; import { DashboardStart } from '@kbn/dashboard-plugin/public'; -import { DashboardContainer } from '@kbn/dashboard-plugin/public/dashboard_container'; +import type { DashboardContainer } from '@kbn/dashboard-plugin/public/dashboard_container'; import { EmbeddableSetup, EmbeddableStart } from '@kbn/embeddable-plugin/public'; import { PresentationUtilPluginStart } from '@kbn/presentation-util-plugin/public'; import { UsageCollectionStart } from '@kbn/usage-collection-plugin/public'; From 79d8d9c444de800794fa7121b6fa1a39cbe8bbb0 Mon Sep 17 00:00:00 2001 From: Nick Peihl Date: Mon, 6 May 2024 11:03:38 -0400 Subject: [PATCH 5/5] SLO plugin registers panel placement in setup --- .../slo/public/plugin.ts | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/x-pack/plugins/observability_solution/slo/public/plugin.ts b/x-pack/plugins/observability_solution/slo/public/plugin.ts index ce5ff09847db2..2f6dbaab39493 100644 --- a/x-pack/plugins/observability_solution/slo/public/plugin.ts +++ b/x-pack/plugins/observability_solution/slo/public/plugin.ts @@ -94,9 +94,17 @@ export class SloPlugin const hasPlatinumLicense = license.hasAtLeast('platinum'); if (hasPlatinumLicense) { + const [coreStart, pluginsStart] = await coreSetup.getStartServices(); + pluginsStart.dashboard.registerDashboardPanelPlacementSetting( + SLO_OVERVIEW_EMBEDDABLE_ID, + (serializedState: SloOverviewEmbeddableState | undefined) => { + if (serializedState?.showAllGroupByInstances || serializedState?.groupFilters) { + return { width: 24, height: 8 }; + } + return { width: 12, height: 8 }; + } + ); registerReactEmbeddableFactory(SLO_OVERVIEW_EMBEDDABLE_ID, async () => { - const [coreStart, pluginsStart] = await coreSetup.getStartServices(); - const deps = { ...coreStart, ...pluginsStart }; const { getOverviewEmbeddableFactory } = await import( @@ -117,8 +125,6 @@ export class SloPlugin registerSloAlertsEmbeddableFactory(); registerReactEmbeddableFactory(SLO_ERROR_BUDGET_ID, async () => { - const [coreStart, pluginsStart] = await coreSetup.getStartServices(); - const deps = { ...coreStart, ...pluginsStart }; const { getErrorBudgetEmbeddableFactory } = await import( @@ -149,16 +155,6 @@ export class SloPlugin const kibanaVersion = this.initContext.env.packageInfo.version; const { ruleTypeRegistry, actionTypeRegistry } = pluginsStart.triggersActionsUi; - pluginsStart.dashboard.registerDashboardPanelPlacementSetting( - SLO_OVERVIEW_EMBEDDABLE_ID, - (serializedState: SloOverviewEmbeddableState | undefined) => { - if (serializedState?.showAllGroupByInstances || serializedState?.groupFilters) { - return { width: 24, height: 8 }; - } - return { width: 12, height: 8 }; - } - ); - return { getCreateSLOFlyout: getCreateSLOFlyoutLazy({ core: coreStart,