Datasources: Use getDefaultQuery in annotations editors (#61870)

+ Add Cloudwatch default annotation
This commit is contained in:
Ida Štambuk
2023-01-30 16:45:03 +01:00
committed by GitHub
parent b6f477ae03
commit f1a2a76897
8 changed files with 106 additions and 11 deletions
@@ -24,7 +24,6 @@ import {
import { toDataQueryError } from '@grafana/runtime';
import { isExpressionReference } from '@grafana/runtime/src/utils/DataSourceWithBackend';
import { backendSrv } from 'app/core/services/backend_srv';
import { queryIsEmpty } from 'app/core/utils/query';
import { dataSource as expressionDatasource } from 'app/features/expressions/ExpressionDatasource';
import { ExpressionQuery } from 'app/features/expressions/types';
@@ -176,10 +175,11 @@ export function callQueryMethod(
request: DataQueryRequest,
queryFunction?: typeof datasource.query
) {
// If the datasource has defined a default query, make sure it's applied if the query is empty
request.targets = request.targets.map((t) =>
queryIsEmpty(t) ? { ...datasource?.getDefaultQuery?.(CoreApp.PanelEditor), ...t } : t
);
// If the datasource has defined a default query, make sure it's applied
request.targets = request.targets.map((t) => ({
...datasource?.getDefaultQuery?.(CoreApp.PanelEditor),
...t,
}));
// If its a public datasource, just return the result. Expressions will be handled on the backend.
if (datasource.type === 'public-ds') {