Commit 390090da by David Kaltschmidt

Set datasource in deep links to Explore

parent d06b26de
...@@ -35,6 +35,7 @@ function parseInitialState(initial) { ...@@ -35,6 +35,7 @@ function parseInitialState(initial) {
try { try {
const parsed = JSON.parse(decodePathComponent(initial)); const parsed = JSON.parse(decodePathComponent(initial));
return { return {
datasource: parsed.datasource,
queries: parsed.queries.map(q => q.query), queries: parsed.queries.map(q => q.query),
range: parsed.range, range: parsed.range,
}; };
...@@ -50,6 +51,7 @@ interface IExploreState { ...@@ -50,6 +51,7 @@ interface IExploreState {
datasourceLoading: boolean | null; datasourceLoading: boolean | null;
datasourceMissing: boolean; datasourceMissing: boolean;
graphResult: any; graphResult: any;
initialDatasource?: string;
latency: number; latency: number;
loading: any; loading: any;
queries: any; queries: any;
...@@ -65,13 +67,14 @@ interface IExploreState { ...@@ -65,13 +67,14 @@ interface IExploreState {
export class Explore extends React.Component<any, IExploreState> { export class Explore extends React.Component<any, IExploreState> {
constructor(props) { constructor(props) {
super(props); super(props);
const { range, queries } = parseInitialState(props.routeParams.initial); const { datasource, queries, range } = parseInitialState(props.routeParams.initial);
this.state = { this.state = {
datasource: null, datasource: null,
datasourceError: null, datasourceError: null,
datasourceLoading: null, datasourceLoading: null,
datasourceMissing: false, datasourceMissing: false,
graphResult: null, graphResult: null,
initialDatasource: datasource,
latency: 0, latency: 0,
loading: false, loading: false,
queries: ensureQueries(queries), queries: ensureQueries(queries),
...@@ -87,14 +90,20 @@ export class Explore extends React.Component<any, IExploreState> { ...@@ -87,14 +90,20 @@ export class Explore extends React.Component<any, IExploreState> {
async componentDidMount() { async componentDidMount() {
const { datasourceSrv } = this.props; const { datasourceSrv } = this.props;
const { initialDatasource } = this.state;
if (!datasourceSrv) { if (!datasourceSrv) {
throw new Error('No datasource service passed as props.'); throw new Error('No datasource service passed as props.');
} }
const datasources = datasourceSrv.getExploreSources(); const datasources = datasourceSrv.getExploreSources();
if (datasources.length > 0) { if (datasources.length > 0) {
this.setState({ datasourceLoading: true }); this.setState({ datasourceLoading: true });
// Try default datasource, otherwise get first // Priority: datasource in url, default datasource, first explore datasource
let datasource = await datasourceSrv.get(); let datasource;
if (initialDatasource) {
datasource = await datasourceSrv.get(initialDatasource);
} else {
datasource = await datasourceSrv.get();
}
if (!datasource.meta.explore) { if (!datasource.meta.explore) {
datasource = await datasourceSrv.get(datasources[0].name); datasource = await datasourceSrv.get(datasources[0].name);
} }
......
...@@ -357,6 +357,7 @@ export class PrometheusDatasource { ...@@ -357,6 +357,7 @@ export class PrometheusDatasource {
state = { state = {
...state, ...state,
queries, queries,
datasource: this.name,
}; };
} }
return state; return state;
......
...@@ -61,7 +61,7 @@ ...@@ -61,7 +61,7 @@
} }
.datasource-picker { .datasource-picker {
min-width: 6rem; min-width: 10rem;
} }
.timepicker { .timepicker {
......
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