import { useCallback } from 'react' ; import { IAggConfig , AggParamType } from 'src/plugins/data/public' ; type SetValue = ( value ? : IAggConfig ) => void ; function useSubAggParamsHandlers ( agg , aggParam , subAgg , setValue ) { const setAggParamValue = useCallback ( ( aggId , paramName , val ) => { const parsedParams = subAgg . toJSON ( ) ; const params = { ... parsedParams , params : { ... parsedParams . params , [ paramName ] : val , } , } ; setValue ( aggParam . makeAgg ( agg , params ) ) ; } , [ agg , aggParam , setValue , subAgg ] ) ; const onAggTypeChange = useCallback ( ( aggId , aggType ) => { const parsedAgg = subAgg . toJSON ( ) ; const params = { ... parsedAgg , type : aggType , } ; setValue ( aggParam . makeAgg ( agg , params ) ) ; } , [ agg , aggParam , setValue , subAgg ] ) ; return { onAggTypeChange , setAggParamValue } ; } export { useSubAggParamsHandlers } ;