Elasticsearch: Fix infinite loop when using mixed datasources (#70386)

* Elasticsearch context: do not init query when it is already initialized

* Fix buggy conditional
This commit is contained in:
Matias Chomicki 2023-06-22 12:44:02 +02:00 committed by GitHub
parent e60966d977
commit dbf7ebb923
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 5 deletions

View File

@ -107,10 +107,9 @@ export const createReducer =
}
if (initQuery.match(action)) {
if (state?.length || 0 > 0) {
if (state && state.length > 0) {
return state;
}
return [{ ...defaultBucketAgg('2'), field: defaultTimeField }];
}

View File

@ -59,11 +59,11 @@ export const ElasticsearchProvider = ({
// This initializes the query by dispatching an init action to each reducer.
// useStatelessReducer will then call `onChange` with the newly generated query
useEffect(() => {
if (shouldRunInit) {
if (shouldRunInit && isUninitialized) {
dispatch(initQuery());
setShouldRunInit(false);
}
}, [shouldRunInit, dispatch]);
}, [shouldRunInit, dispatch, isUninitialized]);
if (isUninitialized) {
return null;

View File

@ -155,7 +155,7 @@ export const reducer = (state: ElasticsearchQuery['metrics'], action: Action): E
}
if (initQuery.match(action)) {
if (state?.length || 0 > 0) {
if (state && state.length > 0) {
return state;
}
return [defaultMetricAgg('1')];