import { IAggConfig } from 'src/plugins/data/public' ; export enum AGGS_ACTION_KEYS { TOUCHED = 'aggsTouched' , VALID = 'aggsValid' } interface AggsItem { touched : boolean ; valid : boolean ; } export interface AggsState { [ aggId ] : AggsItem ; } export interface AggsAction { type : AGGS_ACTION_KEYS ; payload : boolean ; aggId : string ; newState ? : AggsState ; } function aggGroupReducer ( state , action ) { const aggState = state [ action . aggId ] || { touched : false , valid : true } ; switch ( action . type ) { case AGGS_ACTION_KEYS . TOUCHED : return { ... state , [ action . aggId ] : { ... aggState , touched : action . payload } } ; case AGGS_ACTION_KEYS . VALID : return { ... state , [ action . aggId ] : { ... aggState , valid : action . payload } } ; default : throw new Error ( ) ; } } function initAggsState ( group ) { return group . reduce ( ( state , agg ) => { state [ agg . id ] = { touched : false , valid : true } ; return state ; } , { } as AggsState ) ; } export { aggGroupReducer , initAggsState } ;