mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Explore: Fix running queries without a datasource property set (#40805)
* Explore: Fix running queries without a datasource property set * fix test * adjust test
This commit is contained in:
@@ -239,7 +239,7 @@ describe('hasNonEmptyQuery', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('should return false if query is empty', () => {
|
test('should return false if query is empty', () => {
|
||||||
expect(hasNonEmptyQuery([{ refId: '1', key: '2', context: 'panel' }])).toBeFalsy();
|
expect(hasNonEmptyQuery([{ refId: '1', key: '2', context: 'panel', datasource: 'some-ds' }])).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should return false if no queries exist', () => {
|
test('should return false if no queries exist', () => {
|
||||||
|
@@ -277,9 +277,12 @@ export function ensureQueries(queries?: DataQuery[]): DataQuery[] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A target is non-empty when it has keys (with non-empty values) other than refId, key and context.
|
* A target is non-empty when it has keys (with non-empty values) other than refId, key, context and datasource.
|
||||||
|
* FIXME: While this is reasonable for practical use cases, a query without any propery might still be "non-empty"
|
||||||
|
* in its own scope, for instance when there's no user input needed. This might be the case for an hypothetic datasource in
|
||||||
|
* which query options are only set in its config and the query object itself, as generated from its query editor it's always "empty"
|
||||||
*/
|
*/
|
||||||
const validKeys = ['refId', 'key', 'context'];
|
const validKeys = ['refId', 'key', 'context', 'datasource'];
|
||||||
export function hasNonEmptyQuery<TQuery extends DataQuery>(queries: TQuery[]): boolean {
|
export function hasNonEmptyQuery<TQuery extends DataQuery>(queries: TQuery[]): boolean {
|
||||||
return (
|
return (
|
||||||
queries &&
|
queries &&
|
||||||
|
@@ -326,7 +326,6 @@ export const runQueries = (
|
|||||||
const exploreItemState = getState().explore[exploreId]!;
|
const exploreItemState = getState().explore[exploreId]!;
|
||||||
const {
|
const {
|
||||||
datasourceInstance,
|
datasourceInstance,
|
||||||
queries,
|
|
||||||
containerWidth,
|
containerWidth,
|
||||||
isLive: live,
|
isLive: live,
|
||||||
range,
|
range,
|
||||||
@@ -341,6 +340,11 @@ export const runQueries = (
|
|||||||
} = exploreItemState;
|
} = exploreItemState;
|
||||||
let newQuerySub;
|
let newQuerySub;
|
||||||
|
|
||||||
|
const queries = exploreItemState.queries.map((query) => ({
|
||||||
|
...query,
|
||||||
|
datasource: query.datasource || datasourceInstance?.name,
|
||||||
|
}));
|
||||||
|
|
||||||
const cachedValue = getResultsFromCache(cache, absoluteRange);
|
const cachedValue = getResultsFromCache(cache, absoluteRange);
|
||||||
|
|
||||||
// If we have results saved in cache, we are going to use those results instead of running queries
|
// If we have results saved in cache, we are going to use those results instead of running queries
|
||||||
|
Reference in New Issue
Block a user