mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Datasource: Fix - apply default query also to queries in new panels (#59625)
* apply default query also to new panels * add comment * add tests
This commit is contained in:
@@ -9,6 +9,23 @@ export const getNextRefIdChar = (queries: DataQuery[]): string => {
|
||||
}
|
||||
};
|
||||
|
||||
// This function checks if the query has defined properties beyond those defined in the DataQuery interface.
|
||||
export function queryIsEmpty(query: DataQuery): boolean {
|
||||
const dataQueryProps = ['refId', 'hide', 'key', 'queryType', 'datasource'];
|
||||
|
||||
for (const key in query) {
|
||||
// label is not a DataQuery prop, but it's defined in the query when called from the QueryRunner.
|
||||
if (key === 'label') {
|
||||
continue;
|
||||
}
|
||||
if (!dataQueryProps.includes(key)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
export function addQuery(queries: DataQuery[], query?: Partial<DataQuery>, datasource?: DataSourceRef): DataQuery[] {
|
||||
const q = query || {};
|
||||
q.refId = getNextRefIdChar(queries);
|
||||
|
||||
Reference in New Issue
Block a user