import { omit } from 'lodash' ; import { convertSavedDashboardPanelToPanelState , convertPanelStateToSavedDashboardPanel , } from './embeddable_saved_object_converters' ; import { SavedDashboardPanel } from '../types' ; import { SavedObjectReference } from '../../../../core/types' ; import { EmbeddablePersistableStateService } from '../../../embeddable/common/types' ; export interface InjectDeps { embeddablePersistableStateService : EmbeddablePersistableStateService ; } export function injectPanelsReferences ( panels , references , deps ) { const result = [ ] ; for ( const panel of panels ) { const embeddableState = convertSavedDashboardPanelToPanelState ( panel ) ; embeddableState . explicitInput = omit ( deps . embeddablePersistableStateService . inject ( { ... embeddableState . explicitInput , type : panel . type } , references ) , 'type' ) ; result . push ( convertPanelStateToSavedDashboardPanel ( embeddableState , panel . version ) ) ; } return result ; } export interface ExtractDeps { embeddablePersistableStateService : EmbeddablePersistableStateService ; } export function extractPanelsReferences ( panels , deps ) { const result = [ ] ; for ( const panel of panels ) { const embeddable = convertSavedDashboardPanelToPanelState ( panel ) ; const { state : embeddableInputWithExtractedReferences , references } = deps . embeddablePersistableStateService . extract ( { ... embeddable . explicitInput , type : embeddable . type , } ) ; embeddable . explicitInput = omit ( embeddableInputWithExtractedReferences , 'type' ) ; const newPanel = convertPanelStateToSavedDashboardPanel ( embeddable , panel . version ) ; result . push ( { panel : newPanel , references , } ) ; } return result ; }