import { i18n } from '@kbn/i18n' ; import { EmbeddablePersistableStateService } from 'src/plugins/embeddable/common' ; import { DashboardContainerInput } from '../..' ; import { DASHBOARD_CONTAINER_TYPE } from './dashboard_constants' ; import type { DashboardContainer , DashboardContainerServices } from './dashboard_container' ; import { Container , ErrorEmbeddable , ContainerOutput , EmbeddableFactory , EmbeddableFactoryDefinition , } from '../../services/embeddable' ; import { createExtract , createInject , } from '../../../common/embeddable/dashboard_container_persistable_state' ; import { ControlGroupContainer , ControlGroupInput , ControlGroupOutput , CONTROL_GROUP_TYPE , } from '../../../../controls/public' ; import { getDefaultDashboardControlGroupInput } from '../../dashboard_constants' ; export type DashboardContainerFactory = EmbeddableFactory < DashboardContainerInput , ContainerOutput , DashboardContainer > ; export class DashboardContainerFactoryDefinition implements EmbeddableFactoryDefinition < DashboardContainerInput , ContainerOutput , DashboardContainer > { public readonly isContainerType = true ; public readonly type = DASHBOARD_CONTAINER_TYPE ; public inject : EmbeddablePersistableStateService [ 'inject' ] ; public extract : EmbeddablePersistableStateService [ 'extract' ] ; constructor ( private readonly getStartServices , private readonly persistableStateService ) { this . inject = createInject ( this . persistableStateService ) ; this . extract = createExtract ( this . persistableStateService ) ; } public isEditable = async ( ) => { return false ; } ; public readonly getDisplayName = ( ) => { return i18n . translate ( 'dashboard.factory.displayName' , { defaultMessage : 'Dashboard' , } ) ; } ; public getDefaultInput ( ) { return { panels : { } , isEmbeddedExternally : false , isFullScreenMode : false , useMargins : true , syncColors : true , } ; } public create = async ( initialInput , parent ? ) : Promise < DashboardContainer | ErrorEmbeddable > => { const services = await this . getStartServices ( ) ; const controlsGroupFactory = services . embeddable . getEmbeddableFactory < ControlGroupInput , ControlGroupOutput , ControlGroupContainer > ( CONTROL_GROUP_TYPE ) ; const controlGroup = await controlsGroupFactory ?. create ( { ... getDefaultDashboardControlGroupInput ( ) , ... ( initialInput . controlGroupInput ?? { } ) , viewMode : initialInput . viewMode , id : `control_group_${ initialInput . id ?? 'new_dashboard' }` , } ) ; const { DashboardContainer : DashboardContainerEmbeddable } = await import ( './dashboard_container' ) ; return new DashboardContainerEmbeddable ( initialInput , services , parent , controlGroup ) ; } ; }