mirror of
https://github.com/grafana/grafana.git
synced 2024-11-22 08:56:43 -06:00
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:
parent
4a1ca7e32f
commit
a3ff758874
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user