Skip to content

Commit 52fa6fe

Browse files
committed
fix aggregate transform update removed non-set aggretates
1 parent 5f6906a commit 52fa6fe

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

src/default_panels/GraphTransformsPanel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const Aggregations = (props, context) => {
2727
return (
2828
<PlotlySection name={_('Aggregations')} attr="aggregations">
2929
{aggregations
30-
.filter((aggr) => aggr?.target?.match(/transforms\[\d*\]\./gi) === null)
30+
.filter((aggr) => !(aggr?.target && aggr.target.match(/transforms\[\d*\]\./gi)))
3131
.map(({target}, i) => (
3232
<AggregationSection show key={i} aggregationIndex={i}>
3333
<Dropdown

src/lib/connectAggregationToTransform.js

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)