فهرست منبع

Improve wizard instances searching

Previously, if a user typed in the instances search input while the
instances were loading from a previous search, unexpected results may
have appeared. Usually the response from the previous search came before
the current search, in which case UI elements were updated incorrectly
for a short time. Rarely, the previous search response came after the
current search, in which case the instances list from the previous
search were displayed instead.

With this patch, typing while still searching is fully supported by
canceling all the previous requests (thus, bandwidth is also improved).
Sergiu Miclea 7 سال پیش
والد
کامیت
0813b9dd63
3فایلهای تغییر یافته به همراه8 افزوده شده و 10 حذف شده
  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'
 import { servicesUrl, wizardConfig } from '../config'
 
 
 class InstanceSource {
 class InstanceSource {
-  static lastEndpointId: string
-
   static loadInstances(endpointId: string, searchText: ?string, lastInstanceId: ?string, skipLimit?: boolean): Promise<Instance[]> {
   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 url = `${servicesUrl.coriolis}/${Api.projectId}/endpoints/${endpointId}/instances`
     let symbol = '?'
     let symbol = '?'

+ 4 - 1
src/stores/InstanceStore.js

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

+ 3 - 3
src/utils/ApiCaller.js

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