import { SavedObjectReference } from '../../../../../core/types' ; import { VisParams } from '../../../common' ; import { INDEX_PATTERN_SAVED_OBJECT_TYPE } from '../../../../data/common' ; const isControlsVis = ( visType ) => visType === 'input_control_vis' ; export const extractControlsReferences = ( visType , visParams , references = [ ] , prefix = 'control' ) => { if ( isControlsVis ( visType ) ) { ( visParams ?. controls ?? [ ] ) . forEach ( ( control , i ) => { if ( ! control . indexPattern ) { return ; } control . indexPatternRefName = `${ prefix }_${ i }_index_pattern` ; references . push ( { name : control . indexPatternRefName , type : INDEX_PATTERN_SAVED_OBJECT_TYPE , id : control . indexPattern , } ) ; delete control . indexPattern ; } ) ; } } ; export const injectControlsReferences = ( visType , visParams , references ) => { if ( isControlsVis ( visType ) ) { ( visParams . controls ?? [ ] ) . forEach ( ( control ) => { if ( ! control . indexPatternRefName ) { return ; } const reference = references . find ( ( ref ) => ref . name === control . indexPatternRefName ) ; if ( ! reference ) { throw new Error ( `Could not find index pattern reference "${ control . indexPatternRefName }"` ) ; } control . indexPattern = reference . id ; delete control . indexPatternRefName ; } ) ; } } ;