import { Vis } from '../types' ; import type { VisualizeInput , VisualizeEmbeddable , VisualizeByValueInput , VisualizeByReferenceInput , VisualizeSavedObjectAttributes , } from './visualize_embeddable' ; import { IContainer , ErrorEmbeddable , AttributeService , } from '../../../../plugins/embeddable/public' ; import { DisabledLabEmbeddable } from './disabled_lab_embeddable' ; import { getUISettings , getHttp , getTimeFilter , getCapabilities } from '../services' ; import { urlFor } from '../utils/saved_visualize_utils' ; import { VisualizeEmbeddableFactoryDeps } from './visualize_embeddable_factory' ; import { VISUALIZE_ENABLE_LABS_SETTING } from '../../common/constants' ; import { IndexPattern } from '../../../data/public' ; import { createVisualizeEmbeddableAsync } from './visualize_embeddable_async' ; export const createVisEmbeddableFromObject = ( deps ) => async ( vis , input , attributeService ? , parent ? ) : Promise < VisualizeEmbeddable | ErrorEmbeddable | DisabledLabEmbeddable > => { try { const visId = vis . id as string ; const editPath = visId ? urlFor ( visId ) : '#/edit_by_value' ; const editUrl = visId ? getHttp ( ) . basePath . prepend ( `/app/visualize${ urlFor ( visId ) }` ) : '' ; const isLabsEnabled = getUISettings ( ) . get < boolean > ( VISUALIZE_ENABLE_LABS_SETTING ) ; if ( ! isLabsEnabled && vis . type . stage === 'experimental' ) { return new DisabledLabEmbeddable ( vis . title , input ) ; } let indexPatterns = [ ] ; if ( vis . type . getUsedIndexPattern ) { indexPatterns = await vis . type . getUsedIndexPattern ( vis . params ) ; } else if ( vis . data . indexPattern ) { indexPatterns = [ vis . data . indexPattern ] ; } const capabilities = { visualizeSave : Boolean ( getCapabilities ( ) . visualize . save ) , dashboardSave : Boolean ( getCapabilities ( ) . dashboard ?. showWriteControls ) , } ; return createVisualizeEmbeddableAsync ( getTimeFilter ( ) , { vis , indexPatterns , editPath , editUrl , deps , capabilities , } , input , attributeService , parent ) ; } catch ( e ) { console . error ( e ) ; return new ErrorEmbeddable ( e , input , parent ) ; } } ;