From b2e6b2485fe2c7084f516b64a9cb44a12eed04c7 Mon Sep 17 00:00:00 2001 From: David Kaltschmidt Date: Mon, 12 Nov 2018 18:06:12 +0000 Subject: [PATCH] Explore: Dont set datasource in state if navigated away Datasource selection triggers a connection test, on success the DS is set in the Explore state. If the test takes long and user selects a different DS, and just after that the first test succeeds, then the first DS overwrites the state. * when test returns check if datasource is still the requested one --- public/app/features/explore/Explore.tsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/public/app/features/explore/Explore.tsx b/public/app/features/explore/Explore.tsx index 753f158fd9f..238c5c917b9 100644 --- a/public/app/features/explore/Explore.tsx +++ b/public/app/features/explore/Explore.tsx @@ -94,6 +94,10 @@ export class Explore extends React.PureComponent { * Not kept in component state to prevent edit-render roundtrips. */ queryExpressions: string[]; + /** + * Local ID cache to compare requested vs selected datasource + */ + requestedDatasourceId: string; constructor(props) { super(props); @@ -167,6 +171,9 @@ export class Explore extends React.PureComponent { const datasourceId = datasource.meta.id; let datasourceError = null; + // Keep ID to track selection + this.requestedDatasourceId = datasourceId; + try { const testResult = await datasource.testDatasource(); datasourceError = testResult.status === 'success' ? null : testResult.message; @@ -174,6 +181,11 @@ export class Explore extends React.PureComponent { datasourceError = (error && error.statusText) || 'Network error'; } + if (datasourceId !== this.requestedDatasourceId) { + // User already changed datasource again, discard results + return; + } + const historyKey = `grafana.explore.history.${datasourceId}`; const history = store.getObject(historyKey, []);