import { omit } from 'lodash' ; import { DashboardPanelState , SavedDashboardPanel } from '../types' ; import { EmbeddableInput , SavedObjectEmbeddableInput } from '../../../embeddable/common/' ; export function convertSavedDashboardPanelToPanelState < TEmbeddableInput extends EmbeddableInput | SavedObjectEmbeddableInput = SavedObjectEmbeddableInput > ( savedDashboardPanel ) { return { type : savedDashboardPanel . type , gridData : savedDashboardPanel . gridData , panelRefName : savedDashboardPanel . panelRefName , explicitInput : { id : savedDashboardPanel . panelIndex , ... ( savedDashboardPanel . id !== undefined && { savedObjectId : savedDashboardPanel . id } ) , ... ( savedDashboardPanel . title !== undefined && { title : savedDashboardPanel . title } ) , ... savedDashboardPanel . embeddableConfig , } as TEmbeddableInput , } ; } export function convertPanelStateToSavedDashboardPanel ( panelState , version ) { const savedObjectId = ( panelState . explicitInput as SavedObjectEmbeddableInput ) . savedObjectId ; return { version , type : panelState . type , gridData : panelState . gridData , panelIndex : panelState . explicitInput . id , embeddableConfig : omit ( panelState . explicitInput , [ 'id' , 'savedObjectId' , 'title' ] ) , ... ( panelState . explicitInput . title !== undefined && { title : panelState . explicitInput . title } ) , ... ( savedObjectId !== undefined && { id : savedObjectId } ) , ... ( panelState . panelRefName !== undefined && { panelRefName : panelState . panelRefName } ) , } ; }