Commit 22c9575a by kay delaney Committed by GitHub

Going to Explore from a panel with mixed data sources now works (#18784)

Closes #18597
parent a75850a2
...@@ -199,7 +199,7 @@ export class KeybindingSrv { ...@@ -199,7 +199,7 @@ export class KeybindingSrv {
if (dashboard.meta.focusPanelId) { if (dashboard.meta.focusPanelId) {
const panel = dashboard.getPanelById(dashboard.meta.focusPanelId); const panel = dashboard.getPanelById(dashboard.meta.focusPanelId);
const datasource = await this.datasourceSrv.get(panel.datasource); const datasource = await this.datasourceSrv.get(panel.datasource);
const url = await getExploreUrl(panel, panel.targets, datasource, this.datasourceSrv, this.timeSrv); const url = await getExploreUrl(panel.targets, datasource, this.datasourceSrv, this.timeSrv);
if (url) { if (url) {
this.$timeout(() => this.$location.url(url)); this.$timeout(() => this.$location.url(url));
} }
......
...@@ -65,37 +65,25 @@ export const lastUsedDatasourceKeyForOrgId = (orgId: number) => `${LAST_USED_DAT ...@@ -65,37 +65,25 @@ export const lastUsedDatasourceKeyForOrgId = (orgId: number) => `${LAST_USED_DAT
* @param datasourceSrv Datasource service to query other datasources in case the panel datasource is mixed * @param datasourceSrv Datasource service to query other datasources in case the panel datasource is mixed
* @param timeSrv Time service to get the current dashboard range from * @param timeSrv Time service to get the current dashboard range from
*/ */
export async function getExploreUrl( export async function getExploreUrl(panelTargets: any[], panelDatasource: any, datasourceSrv: any, timeSrv: any) {
panel: any,
panelTargets: any[],
panelDatasource: any,
datasourceSrv: any,
timeSrv: any
) {
let exploreDatasource = panelDatasource; let exploreDatasource = panelDatasource;
let exploreTargets: DataQuery[] = panelTargets; let exploreTargets: DataQuery[] = panelTargets;
let url: string; let url: string;
// Mixed datasources need to choose only one datasource // Mixed datasources need to choose only one datasource
if (panelDatasource.meta.id === 'mixed' && panelTargets) { if (panelDatasource.meta.id === 'mixed' && exploreTargets) {
// Find first explore datasource among targets // Find first explore datasource among targets
let mixedExploreDatasource: any; for (const t of exploreTargets) {
for (const t of panel.targets) {
const datasource = await datasourceSrv.get(t.datasource); const datasource = await datasourceSrv.get(t.datasource);
if (datasource && datasource.meta.explore) { if (datasource) {
mixedExploreDatasource = datasource; exploreDatasource = datasource;
exploreTargets = panelTargets.filter(t => t.datasource === datasource.name);
break; break;
} }
} }
// Add all its targets
if (mixedExploreDatasource) {
exploreDatasource = mixedExploreDatasource;
exploreTargets = panelTargets.filter(t => t.datasource === mixedExploreDatasource.name);
}
} }
if (panelDatasource) { if (exploreDatasource) {
const range = timeSrv.timeRangeForUrl(); const range = timeSrv.timeRangeForUrl();
let state: Partial<ExploreUrlState> = { range }; let state: Partial<ExploreUrlState> = { range };
if (exploreDatasource.getExploreState) { if (exploreDatasource.getExploreState) {
...@@ -103,8 +91,8 @@ export async function getExploreUrl( ...@@ -103,8 +91,8 @@ export async function getExploreUrl(
} else { } else {
state = { state = {
...state, ...state,
datasource: panelDatasource.name, datasource: exploreDatasource.name,
queries: exploreTargets.map(t => ({ ...t, datasource: panelDatasource.name })), queries: exploreTargets.map(t => ({ ...t, datasource: exploreDatasource.name })),
}; };
} }
......
...@@ -253,7 +253,7 @@ class MetricsPanelCtrl extends PanelCtrl { ...@@ -253,7 +253,7 @@ class MetricsPanelCtrl extends PanelCtrl {
} }
async explore() { async explore() {
const url = await getExploreUrl(this.panel, this.panel.targets, this.datasource, this.datasourceSrv, this.timeSrv); const url = await getExploreUrl(this.panel.targets, this.datasource, this.datasourceSrv, this.timeSrv);
if (url) { if (url) {
this.$timeout(() => this.$location.url(url)); this.$timeout(() => this.$location.url(url));
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment