import { inspect } from 'util' ; import { SavedObjectMigrationContext } from 'kibana/server' ; import { DashboardDoc730ToLatest } from '../../common' ; import { isDashboardDoc } from './is_dashboard_doc' ; import { moveFiltersToQuery } from './move_filters_to_query' ; import { migratePanelsTo730 , DashboardDoc700To720 } from '../../common' ; export const migrations730 = ( doc , { log } ) => { if ( ! isDashboardDoc ( doc ) ) { return doc ; } try { const searchSource = JSON . parse ( doc . attributes . kibanaSavedObjectMeta . searchSourceJSON ) ; doc . attributes . kibanaSavedObjectMeta . searchSourceJSON = JSON . stringify ( moveFiltersToQuery ( searchSource ) ) ; } catch ( e ) { log . warning ( `Exception @ migrations730 while trying to migrate dashboard query filters!\n` + `${ e . stack }\n` + `dashboard: ${ inspect ( doc , false , null ) }` ) ; return doc ; } let uiState = { } ; if ( doc . attributes . uiStateJSON && doc . attributes . uiStateJSON !== '' ) { uiState = JSON . parse ( doc . attributes . uiStateJSON ) ; } try { const panels = JSON . parse ( doc . attributes . panelsJSON ) ; doc . attributes . panelsJSON = JSON . stringify ( migratePanelsTo730 ( panels , '7.3.0' , doc . attributes . useMargins === undefined ? true : doc . attributes . useMargins , uiState ) ) ; delete doc . attributes . uiStateJSON ; } catch ( e ) { log . warning ( `Exception @ migrations730 while trying to migrate dashboard panels!\n` + `Error: ${ e . stack }\n` + `dashboard: ${ inspect ( doc , false , null ) }` ) ; return doc ; } return doc as DashboardDoc730ToLatest ; } ;