@@ -19,19 +19,40 @@ export default function connectAggregationToTransform(WrappedComponent) {
1919 const { aggregationIndex} = props ;
2020 const { container, fullContainer} = context ;
2121
22+ // Keep references to the parent transform containers
23+ this . parentContainer = container ;
24+ this . parentFullContainer = fullContainer ;
25+
2226 this . container = ( container ?. aggregations || [ ] ) [ aggregationIndex ] ;
2327 this . fullContainer = ( fullContainer ?. aggregations || [ ] ) [ aggregationIndex ] ;
2428 }
2529
2630 updateAggregation ( update ) {
27- const newUpdate = { } ;
28- const path = `aggregations[${ this . props . aggregationIndex } ]` ;
29- for ( const key in update ) {
30- newUpdate [ `${ path } .${ key } ` ] = update [ key ] ;
31+ // Build a full aggregations array update so other entries are preserved
32+ const { aggregationIndex} = this . props ;
33+ const sourceAggs = Array . isArray ( this . parentContainer ?. aggregations )
34+ ? this . parentContainer . aggregations
35+ : Array . isArray ( this . parentFullContainer ?. aggregations )
36+ ? this . parentFullContainer . aggregations
37+ : [ ] ;
38+
39+ const newAggs = sourceAggs . map ( ( a ) => ( a ? { ...a } : a ) ) ;
40+ const current = newAggs [ aggregationIndex ] ? { ...newAggs [ aggregationIndex ] } : { } ;
41+
42+ Object . keys ( update ) . forEach ( ( k ) => {
43+ current [ k ] = update [ k ] ;
44+ } ) ;
45+
46+ // If target wasn't provided and doesn't exist yet, fall back to existing agg target
47+ if ( typeof update . target === 'undefined' && ! current . target && this . fullContainer ?. target ) {
48+ current . target = this . fullContainer . target ;
3149 }
32- newUpdate [ `${ path } .target` ] = this . fullContainer . target ;
33- newUpdate [ `${ path } .enabled` ] = true ;
34- this . context . updateContainer ( newUpdate ) ;
50+
51+ current . enabled = true ;
52+ newAggs [ aggregationIndex ] = current ;
53+
54+ // Send whole aggregations array; parent context will prefix with transforms[index].
55+ this . context . updateContainer ( { aggregations : newAggs } ) ;
3556 }
3657
3758 getChildContext ( ) {
0 commit comments