Skip to content

Commit

Permalink
Avoid warning by suing useEffect on aggragation update
Browse files Browse the repository at this point in the history
  • Loading branch information
JulesVautier-io committed Jun 20, 2024
1 parent eb3ffe5 commit 3be40b4
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,15 @@ export function AggregationKind(props: SearchComponentProps) {
}
}, []); // Empty dependency array means this runs once after mount

const updateAggregationProp = (newAggregations: ({term: TermAgg} | {histogram: HistogramAgg})[]) => {
useEffect(() => {
// Update search request whenever aggregations change
const metric = props.searchRequest.aggregationConfig.metric;
const updatedAggregation = Object.assign({}, {metric: metric}, ...newAggregations);
const updatedSearchRequest = {...props.searchRequest, aggregationConfig: updatedAggregation};
const updatedAggregation = Object.assign({}, { metric: metric }, ...aggregations);
const updatedSearchRequest = { ...props.searchRequest, aggregationConfig: updatedAggregation };
props.onSearchRequestUpdate(updatedSearchRequest);
};
console.log('useEffect')
}, [aggregations]);


const handleAggregationChange = (pos: number, event: SelectChangeEvent) => {
const value = event.target.value;
Expand Down Expand Up @@ -149,7 +152,7 @@ export function AggregationKind(props: SearchComponentProps) {
newAggregations.splice(pos, 1);
}
}
updateAggregationProp(newAggregations);
// updateAggregationProp(newAggregations);
return newAggregations;
});
};
Expand All @@ -159,7 +162,7 @@ export function AggregationKind(props: SearchComponentProps) {
setAggregations((agg) => {
const newAggregations = [...agg];
newAggregations[pos] = {histogram: {interval:value}};
updateAggregationProp(newAggregations);
// updateAggregationProp(newAggregations);
return newAggregations;
});
}
Expand All @@ -172,7 +175,7 @@ export function AggregationKind(props: SearchComponentProps) {
if (isTerm(term)) {
term.term.field = value;
}
updateAggregationProp(newAggregations);
// updateAggregationProp(newAggregations);
return newAggregations;
});
};
Expand All @@ -185,7 +188,7 @@ export function AggregationKind(props: SearchComponentProps) {
if (isTerm(term)) {
term.term.size = Number(value);
}
updateAggregationProp(newAggregations);
// updateAggregationProp(newAggregations);
return newAggregations;
});
};
Expand Down

0 comments on commit 3be40b4

Please sign in to comment.