import { get , omit } from 'lodash' ; import { VisualizeAppState } from '../types' ; param appState { VisualizeAppState } export function migrateAppState ( appState ) { if ( appState . vis . type !== 'table' ) { return appState ; } const visAggs = get ( appState , 'vis.aggs' ) ; if ( visAggs ) { let splitCount = 0 ; const migratedAggs = visAggs . map ( ( agg ) => { if ( agg . schema !== 'split' ) { return agg ; } splitCount ++ ; if ( splitCount === 1 ) { return agg ; } agg . schema = 'bucket' ; agg . params = omit ( agg . params , [ 'row' ] ) ; return agg ; } ) ; if ( splitCount <= 1 ) { return appState ; } appState . vis . aggs = migratedAggs ; } return appState ; }