const getInVis = require ( '../../util/immutable-utils' ) . getInVis ; import { AnyAction , Dispatch } from 'redux' ; import { ThunkDispatch } from 'redux-thunk' ; import { Data } from 'vega' ; import { CompiledBinding } from '.' ; import { State } from '../../store' ; import { LyraAggregateTransform } from '../../store/factory/Pipeline' ; import { summarizeAggregate } from '../datasetActions' ; import { aggregatePipeline } from '../pipelineActions' ; param { Function } dispatch param { ImmutableMap } state param { Object } parsed param { number } dsId returns { void } export default function parseData ( dispatch , state , parsed ) { parsed . map . data [ 'source_0' ] = parsed . dsId ; parsed . map . data [ 'data_0' ] = parsed . dsId ; const dataDef = parsed . output . data , data = dataDef . find ( d => d . name === 'data_0' ) || dataDef . find ( d => d . name === 'source_0' ) ; parseAggregate ( dispatch , state , parsed , data ) ; } ; function parseAggregate ( dispatch , state , parsed , data ) { const aggregate = data . transform && data . transform . find ( tx => tx . type === 'aggregate' ) as LyraAggregateTransform ; if ( ! aggregate ) { return ; } const groupby = aggregate . groupby as string [ ] ; const keys = groupby . join ( '|' ) ; const plId = parsed . plId ; let aggId = getInVis ( state , 'pipelines.' + plId + '._aggregates.' + keys ) ; if ( ! aggId ) { dispatch ( aggregatePipeline ( plId , aggregate ) ) ; aggId = aggregate . _id ; } else { dispatch ( summarizeAggregate ( aggregate , aggId ) ) ; } parsed . map . data [ 'source_0' ] = aggId ; parsed . map . data [ 'data_0' ] = aggId ; }