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