mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Add in logic to send root datasource as override if needed (#56904)
This commit is contained in:
parent
2f85172718
commit
3dbb0f1659
@ -268,13 +268,13 @@ export async function generateEmptyQuery(
|
|||||||
let defaultQuery: Partial<DataQuery> | undefined;
|
let defaultQuery: Partial<DataQuery> | undefined;
|
||||||
|
|
||||||
// datasource override is if we have switched datasources with no carry-over - we want to create a new query with a datasource we define
|
// datasource override is if we have switched datasources with no carry-over - we want to create a new query with a datasource we define
|
||||||
|
// it's also used if there's a root datasource and there were no previous queries
|
||||||
if (dataSourceOverride) {
|
if (dataSourceOverride) {
|
||||||
datasourceRef = dataSourceOverride;
|
datasourceRef = dataSourceOverride;
|
||||||
} else if (queries.length > 0 && queries[queries.length - 1].datasource) {
|
} else if (queries.length > 0 && queries[queries.length - 1].datasource) {
|
||||||
// otherwise use last queries' datasource
|
// otherwise use last queries' datasource
|
||||||
datasourceRef = queries[queries.length - 1].datasource;
|
datasourceRef = queries[queries.length - 1].datasource;
|
||||||
} else {
|
} else {
|
||||||
// if neither exists, use the default datasource
|
|
||||||
datasourceInstance = await getDataSourceSrv().get();
|
datasourceInstance = await getDataSourceSrv().get();
|
||||||
defaultQuery = datasourceInstance.getDefaultQuery?.(CoreApp.Explore);
|
defaultQuery = datasourceInstance.getDefaultQuery?.(CoreApp.Explore);
|
||||||
datasourceRef = datasourceInstance.getRef();
|
datasourceRef = datasourceInstance.getRef();
|
||||||
|
@ -222,7 +222,18 @@ export const clearCacheAction = createAction<ClearCachePayload>('explore/clearCa
|
|||||||
export function addQueryRow(exploreId: ExploreId, index: number): ThunkResult<void> {
|
export function addQueryRow(exploreId: ExploreId, index: number): ThunkResult<void> {
|
||||||
return async (dispatch, getState) => {
|
return async (dispatch, getState) => {
|
||||||
const queries = getState().explore[exploreId]!.queries;
|
const queries = getState().explore[exploreId]!.queries;
|
||||||
const query = await generateEmptyQuery(queries, index);
|
let datasourceOverride = undefined;
|
||||||
|
|
||||||
|
// if this is the first query being added, check for a root datasource
|
||||||
|
// if it's not mixed, send it as an override. generateEmptyQuery doesn't have access to state
|
||||||
|
if (queries.length === 0) {
|
||||||
|
const rootDatasource = getState().explore[exploreId]!.datasourceInstance;
|
||||||
|
if (!config.featureToggles.exploreMixedDatasource || !rootDatasource?.meta.mixed) {
|
||||||
|
datasourceOverride = rootDatasource;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const query = await generateEmptyQuery(queries, index, datasourceOverride?.getRef());
|
||||||
|
|
||||||
dispatch(addQueryRowAction({ exploreId, index, query }));
|
dispatch(addQueryRowAction({ exploreId, index, query }));
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user