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:
Erik Sundell
2022-12-05 15:44:04 +01:00
committed by GitHub
parent b4cf711a74
commit 32309a8373
6 changed files with 107 additions and 6 deletions

View File

@@ -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);