Browse Source

Merge pull request #285 from smiclea/search-cancel

Improve wizard instances searching
Dorin Paslaru 7 years ago
parent
commit
b5c5d4aa37
3 changed files with 8 additions and 10 deletions
  1. 1 6
      src/sources/InstanceSource.js
  2. 4 1
      src/stores/InstanceStore.js
  3. 3 3
      src/utils/ApiCaller.js

+ 1 - 6
src/sources/InstanceSource.js

@@ -20,13 +20,8 @@ import type { Instance } from '../types/Instance'
 import { servicesUrl, wizardConfig } from '../config'
 
 class InstanceSource {
-  static lastEndpointId: string
-
   static loadInstances(endpointId: string, searchText: ?string, lastInstanceId: ?string, skipLimit?: boolean): Promise<Instance[]> {
-    if (this.lastEndpointId) {
-      Api.cancelRequests(this.lastEndpointId)
-      this.lastEndpointId = endpointId
-    }
+    Api.cancelRequests(endpointId)
 
     let url = `${servicesUrl.coriolis}/${Api.projectId}/endpoints/${endpointId}/instances`
     let symbol = '?'

+ 4 - 1
src/stores/InstanceStore.js

@@ -99,7 +99,10 @@ class InstanceStore {
       this.cachedInstances = instances
       this.searching = false
       this.searchNotFound = Boolean(instances.length === 0 && searchText)
-    }).catch(() => {
+    }).catch(r => {
+      if (r.canceled) {
+        return
+      }
       this.searching = false
       this.searchNotFound = true
     })

+ 3 - 3
src/utils/ApiCaller.js

@@ -121,9 +121,9 @@ class ApiCaller {
           console.log(`%cError No Response: ${axiosOptions.url}`, 'color: #D0021B')
           reject({})
         } else {
-          reject({})
-
-          if (error.constructor.name === 'Cancel') {
+          let canceled = error.constructor.name === 'Cancel'
+          reject({ canceled })
+          if (canceled) {
             return
           }