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

Allow navigation through executions while one is running CORWEB-67

Don't move the execution navigation every time the last execution is updated.
Move the navigation if a new execution was just added.
Show 'Cancel execution' button only for the currently running execution.
Sergiu Miclea 8 лет назад
Родитель
Сommit
e94b4f6cc2
1 измененных файлов с 21 добавлено и 16 удалено
  1. 21 16
      src/components/ReplicaExecutions/ReplicaExecutions.js

+ 21 - 16
src/components/ReplicaExecutions/ReplicaExecutions.js

@@ -74,10 +74,21 @@ class ReplicaExecutions extends Component {
 
   componentWillReceiveProps(newProps) {
     if (newProps.replica && newProps.replica.executions.length) {
+      let isNewExecution = newProps.replica.executions.length > (this.state.executionsCount || 0)
       let execution = newProps.replica.executions[newProps.replica.executions.length - 1]
-      this.setState({
-        executionRef: execution,
-        tasks: execution.tasks
+      this.setState(prevState => {
+        // Don't update the component every time the last execution is updated
+        // Update the component if the last execution is the currently selected one
+        // Update the component if a new execution was just added
+        if (prevState.executionRef && prevState.executionRef.id !== execution.id && !isNewExecution) {
+          execution = prevState.executionRef
+        }
+
+        return {
+          executionsCount: newProps.replica.executions.length,
+          executionRef: execution,
+          tasks: execution.tasks
+        }
       })
     } else if (newProps.replica.executions.length == 0) {
       this.setState({
@@ -151,15 +162,10 @@ class ReplicaExecutions extends Component {
   }
 
   pollTasks() {
-    if (this.props && this.props.replica && this.props.replica.executions.length) {
-      if (this.props.replica.executions[this.props.replica.executions.length - 1].status == "RUNNING") {
-        MigrationActions.getReplicaExecutionDetail(this.props.replica, this.state.executionRef.id,
-          (replica, executionId, response) => {
-            this.setState({
-              tasks: response.data.execution.tasks
-            })
-          })
-      }
+    let executions = this.props && this.props.replica && this.props.replica.executions
+    let lastExecution = executions && executions.length && executions[executions.length - 1]
+    if (lastExecution.status === 'RUNNING') {
+      MigrationActions.getReplicaExecutionDetail(this.props.replica, lastExecution.id)
     }
   }
 
@@ -181,14 +187,13 @@ class ReplicaExecutions extends Component {
     if (this.props.replica) {
       if (this.props.replica.executions.length && this.state.executionRef) {
         let executionBtn = <button className="wire red" onClick={(e) => this.deleteExecution(e)}>Delete</button>
-        if (this.props.replica.executions && this.props.replica.executions[this.props.replica.executions.length - 1] &&
-          this.props.replica.executions[this.props.replica.executions.length - 1].status == "RUNNING") {
-          executionBtn =
+
+        if (this.state.executionRef.status === 'RUNNING') {
+          executionBtn = 
             <button className="gray wire" onClick={(e) => this.cancelExecution(e)}>Cancel execution</button>
         }
 
         let executionsSorted = this.props.replica.executions
-
         executionsSorted.sort((a, b) => a.number - b.number)
         let executionTime = Helper.getTimeObject(this.state.executionRef.created_at)