diff --git a/public/app/plugins/datasource/elasticsearch/components/QueryEditor/BucketAggregationsEditor/state/reducer.ts b/public/app/plugins/datasource/elasticsearch/components/QueryEditor/BucketAggregationsEditor/state/reducer.ts index d289f7dc32f..935f7a10e07 100644 --- a/public/app/plugins/datasource/elasticsearch/components/QueryEditor/BucketAggregationsEditor/state/reducer.ts +++ b/public/app/plugins/datasource/elasticsearch/components/QueryEditor/BucketAggregationsEditor/state/reducer.ts @@ -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 }]; } diff --git a/public/app/plugins/datasource/elasticsearch/components/QueryEditor/ElasticsearchQueryContext.tsx b/public/app/plugins/datasource/elasticsearch/components/QueryEditor/ElasticsearchQueryContext.tsx index 9e25bb96620..f91fe3d209d 100644 --- a/public/app/plugins/datasource/elasticsearch/components/QueryEditor/ElasticsearchQueryContext.tsx +++ b/public/app/plugins/datasource/elasticsearch/components/QueryEditor/ElasticsearchQueryContext.tsx @@ -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; diff --git a/public/app/plugins/datasource/elasticsearch/components/QueryEditor/MetricAggregationsEditor/state/reducer.ts b/public/app/plugins/datasource/elasticsearch/components/QueryEditor/MetricAggregationsEditor/state/reducer.ts index e3da5ccd2e6..a1b8fcb860a 100644 --- a/public/app/plugins/datasource/elasticsearch/components/QueryEditor/MetricAggregationsEditor/state/reducer.ts +++ b/public/app/plugins/datasource/elasticsearch/components/QueryEditor/MetricAggregationsEditor/state/reducer.ts @@ -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')];