Просмотр исходного кода

Disables "Execute" button in replica view after it is pressed

George Vrancianu 8 лет назад
Родитель
Сommit
f6d36bf8a9
2 измененных файлов с 21 добавлено и 5 удалено
  1. 13 3
      src/actions/MigrationActions/MigrationActions.js
  2. 8 2
      src/components/ReplicaView/ReplicaView.js

+ 13 - 3
src/actions/MigrationActions/MigrationActions.js

@@ -123,7 +123,7 @@ MigrationActions.deleteReplica.listen((replica, callback = null) => {
     .catch(MigrationActions.deleteReplica.failed);
     .catch(MigrationActions.deleteReplica.failed);
 })
 })
 
 
-MigrationActions.executeReplica.listen((replica, callback = null) => {
+MigrationActions.executeReplica.listen((replica, callback = null, errorCallback = null) => {
   if (replica.type == 'replica') {
   if (replica.type == 'replica') {
     let projectId = Reflux.GlobalState.userStore.currentUser.project.id
     let projectId = Reflux.GlobalState.userStore.currentUser.project.id
 
 
@@ -143,8 +143,18 @@ MigrationActions.executeReplica.listen((replica, callback = null) => {
         if (callback) {
         if (callback) {
           callback(replica, response)
           callback(replica, response)
         }
         }
-      }, MigrationActions.executeReplica.failed)
-      .catch(MigrationActions.executeReplica.failed);
+      }, (err) => {
+        MigrationActions.executeReplica.failed(err)
+        if (errorCallback) {
+          errorCallback(replica, err)
+        }
+      })
+      .catch((err) => {
+        MigrationActions.executeReplica.failed(err)
+        if (errorCallback) {
+          errorCallback(replica, err)
+        }
+      });
   } else {
   } else {
     NotificationActions.notify("You cannot execute a migration.", "warning")
     NotificationActions.notify("You cannot execute a migration.", "warning")
   }
   }

+ 8 - 2
src/components/ReplicaView/ReplicaView.js

@@ -44,6 +44,7 @@ class ReplicaView extends Reflux.Component {
 
 
     this.state = {
     this.state = {
       title: 'Coriolis: View Replica',
       title: 'Coriolis: View Replica',
+      isBeingExecuted: false,
       confirmationDialog: {
       confirmationDialog: {
         visible: false,
         visible: false,
         message: "Are you sure?",
         message: "Are you sure?",
@@ -64,8 +65,13 @@ class ReplicaView extends Reflux.Component {
   }
   }
 
 
   executeReplica() {
   executeReplica() {
+    this.setState({ isBeingExecuted: true })
     let item = this.state.replicas.filter(replica => replica.id == this.props.replicaId)[0]
     let item = this.state.replicas.filter(replica => replica.id == this.props.replicaId)[0]
-    MigrationActions.executeReplica(item)
+    MigrationActions.executeReplica(item, () => {
+      this.setState({ isBeingExecuted: false })
+    }, () => {
+      this.setState({ isBeingExecuted: false })
+    })
   }
   }
 
 
   goBack() {
   goBack() {
@@ -127,7 +133,7 @@ class ReplicaView extends Reflux.Component {
                 <div>
                 <div>
                   <button
                   <button
                     className="gray"
                     className="gray"
-                    disabled={item.status === "RUNNING"}
+                    disabled={item.status === "RUNNING" || this.state.isBeingExecuted}
                     onClick={(e) => this.executeReplica(e)}
                     onClick={(e) => this.executeReplica(e)}
                   >
                   >
                     Execute Now
                     Execute Now