Ver Fonte

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
David Kaltschmidt há 7 anos atrás
pai
commit
b2e6b2485f
1 ficheiros alterados com 12 adições e 0 exclusões
  1. 12 0
      public/app/features/explore/Explore.tsx

+ 12 - 0
public/app/features/explore/Explore.tsx

@@ -94,6 +94,10 @@ export class Explore extends React.PureComponent<ExploreProps, ExploreState> {
    * Not kept in component state to prevent edit-render roundtrips.
    * Not kept in component state to prevent edit-render roundtrips.
    */
    */
   queryExpressions: string[];
   queryExpressions: string[];
+  /**
+   * Local ID cache to compare requested vs selected datasource
+   */
+  requestedDatasourceId: string;
 
 
   constructor(props) {
   constructor(props) {
     super(props);
     super(props);
@@ -167,6 +171,9 @@ export class Explore extends React.PureComponent<ExploreProps, ExploreState> {
     const datasourceId = datasource.meta.id;
     const datasourceId = datasource.meta.id;
     let datasourceError = null;
     let datasourceError = null;
 
 
+    // Keep ID to track selection
+    this.requestedDatasourceId = datasourceId;
+
     try {
     try {
       const testResult = await datasource.testDatasource();
       const testResult = await datasource.testDatasource();
       datasourceError = testResult.status === 'success' ? null : testResult.message;
       datasourceError = testResult.status === 'success' ? null : testResult.message;
@@ -174,6 +181,11 @@ export class Explore extends React.PureComponent<ExploreProps, ExploreState> {
       datasourceError = (error && error.statusText) || 'Network error';
       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 historyKey = `grafana.explore.history.${datasourceId}`;
     const history = store.getObject(historyKey, []);
     const history = store.getObject(historyKey, []);