ElasticSearch: Fix dispatching queries at a wrong time (#55225)

* Loki: Fix running queries without an `expr`

* rever previous change

* only dispatch `initQuery` if the DS is uninitialized

* moved `isUninitialized` to static var
This commit is contained in:
Sven Grossmann 2022-09-19 11:45:21 +02:00 committed by GitHub
parent 4a1ca7e32f
commit a3ff758874
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,4 +1,4 @@
import React, { Context, createContext, PropsWithChildren, useCallback, useContext, useEffect } from 'react';
import React, { Context, createContext, PropsWithChildren, useCallback, useContext, useEffect, useState } from 'react';
import { TimeRange } from '@grafana/data';
@ -54,14 +54,16 @@ export const ElasticsearchProvider = ({
const isUninitialized = !query.metrics || !query.bucketAggs || query.query === undefined;
const [shouldRunInit, setShouldRunInit] = useState(isUninitialized);
// This initializes the query by dispatching an init action to each reducer.
// useStatelessReducer will then call `onChange` with the newly generated query
useEffect(() => {
if (isUninitialized) {
if (shouldRunInit) {
dispatch(initQuery());
setShouldRunInit(false);
}
});
}, [shouldRunInit, dispatch]);
if (isUninitialized) {
return null;