Add in logic to send root datasource as override if needed (#56904)

This commit is contained in:
Kristina 2022-10-14 08:12:04 -05:00 committed by GitHub
parent 2f85172718
commit 3dbb0f1659
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -268,13 +268,13 @@ export async function generateEmptyQuery(
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
// it's also used if there's a root datasource and there were no previous queries
if (dataSourceOverride) {
datasourceRef = dataSourceOverride;
} else if (queries.length > 0 && queries[queries.length - 1].datasource) {
// otherwise use last queries' datasource
datasourceRef = queries[queries.length - 1].datasource;
} else {
// if neither exists, use the default datasource
datasourceInstance = await getDataSourceSrv().get();
defaultQuery = datasourceInstance.getDefaultQuery?.(CoreApp.Explore);
datasourceRef = datasourceInstance.getRef();

View File

@ -222,7 +222,18 @@ export const clearCacheAction = createAction<ClearCachePayload>('explore/clearCa
export function addQueryRow(exploreId: ExploreId, index: number): ThunkResult<void> {
return async (dispatch, getState) => {
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 }));
};