mirror of https://github.com/grafana/grafana
- extends handlers for panel menu and keypress 'x' - in a mixed-datasource panel finds first datasource that supports explore and collects its targets - passes those targets to the found datasource to be serialized for explore state - removed `supportMetrics` and `supportsExplore` - use datasource metadata instead (set in plugin.json) - Use angular timeout to wrap url change for explore jump - Extract getExploreUrl into core/utils/explorepull/13416/head
parent
7b543ca4b5
commit
54c9beb146
@ -0,0 +1,52 @@ |
||||
import { renderUrl } from 'app/core/utils/url'; |
||||
|
||||
/** |
||||
* Returns an Explore-URL that contains a panel's queries and the dashboard time range. |
||||
* |
||||
* @param panel Origin panel of the jump to Explore |
||||
* @param panelTargets The origin panel's query targets |
||||
* @param panelDatasource The origin panel's datasource |
||||
* @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 |
||||
*/ |
||||
export async function getExploreUrl( |
||||
panel: any, |
||||
panelTargets: any[], |
||||
panelDatasource: any, |
||||
datasourceSrv: any, |
||||
timeSrv: any |
||||
) { |
||||
let exploreDatasource = panelDatasource; |
||||
let exploreTargets = panelTargets; |
||||
let url; |
||||
|
||||
// Mixed datasources need to choose only one datasource
|
||||
if (panelDatasource.meta.id === 'mixed' && panelTargets) { |
||||
// Find first explore datasource among targets
|
||||
let mixedExploreDatasource; |
||||
for (const t of panel.targets) { |
||||
const datasource = await datasourceSrv.get(t.datasource); |
||||
if (datasource && datasource.meta.explore) { |
||||
mixedExploreDatasource = datasource; |
||||
break; |
||||
} |
||||
} |
||||
|
||||
// Add all its targets
|
||||
if (mixedExploreDatasource) { |
||||
exploreDatasource = mixedExploreDatasource; |
||||
exploreTargets = panelTargets.filter(t => t.datasource === mixedExploreDatasource.name); |
||||
} |
||||
} |
||||
|
||||
if (exploreDatasource && exploreDatasource.meta.explore) { |
||||
const range = timeSrv.timeRangeForUrl(); |
||||
const state = { |
||||
...exploreDatasource.getExploreState(exploreTargets), |
||||
range, |
||||
}; |
||||
const exploreState = JSON.stringify(state); |
||||
url = renderUrl('/explore', { state: exploreState }); |
||||
} |
||||
return url; |
||||
} |
Loading…
Reference in new issue