Procházet zdrojové kódy

Fix execution being added twice

Occasionally after finishing the wizard and after being redirected to
the replica's execution page, the first execution would be added twice.
This also fixes an issue where, after finishing the wizard with multiple
replicas separated per VM, the replica list page wouldn't list the
current running execution for a few seconds for the newly created ones.
Sergiu Miclea před 8 roky
rodič
revize
7f9eacbdc8
1 změnil soubory, kde provedl 30 přidání a 11 odebrání
  1. 30 11
      src/stores/ReplicaStore.js

+ 30 - 11
src/stores/ReplicaStore.js

@@ -23,19 +23,28 @@ import type { Execution } from '../types/Execution'
 import type { Field } from '../types/Field'
 
 class ReplicaStoreUtils {
-  static addExecutionToReplica(opts: { replicaStore: any, replicaId: string, execution: Execution }) {
-    let executions = [opts.execution]
+  static addExecutionToReplica(opts: {
+    replicas: MainItem[],
+    replicaDetails: ?MainItem,
+    execution: Execution,
+    replicaId: string,
+  }) {
+    let replicasToUpdate = opts.replicas.filter(r => r.id === opts.replicaId)
+    if (opts.replicaDetails && opts.replicaDetails.id === opts.replicaId) {
+      replicasToUpdate.push(opts.replicaDetails)
+    }
 
-    if (opts.replicaStore.replicaDetails.id === opts.replicaId) {
-      if (opts.replicaStore.replicaDetails.executions) {
-        executions = [...opts.replicaStore.replicaDetails.executions, opts.execution]
+    replicasToUpdate.forEach(r => {
+      if (r.executions.find(e => e.id === opts.execution.id)) {
+        return
       }
 
-      opts.replicaStore.replicaDetails = {
-        ...opts.replicaStore.replicaDetails,
-        executions,
+      if (r.executions) {
+        r.executions.push(opts.execution)
+      } else {
+        r.executions = [opts.execution]
       }
-    }
+    })
   }
 }
 
@@ -93,7 +102,12 @@ class ReplicaStore {
 
   @action execute(replicaId: string, fields?: Field[]): Promise<void> {
     return ReplicaSource.execute(replicaId, fields).then(execution => {
-      ReplicaStoreUtils.addExecutionToReplica({ replicaStore: this, replicaId, execution })
+      ReplicaStoreUtils.addExecutionToReplica({
+        replicaId,
+        replicas: this.replicas,
+        replicaDetails: this.replicaDetails,
+        execution,
+      })
     })
   }
 
@@ -128,7 +142,12 @@ class ReplicaStore {
 
   @action deleteDisks(replicaId: string) {
     return ReplicaSource.deleteDisks(replicaId).then(execution => {
-      ReplicaStoreUtils.addExecutionToReplica({ replicaStore: this, replicaId, execution })
+      ReplicaStoreUtils.addExecutionToReplica({
+        replicaId,
+        replicas: this.replicas,
+        replicaDetails: this.replicaDetails,
+        execution,
+      })
     })
   }