Procházet zdrojové kódy

Fix polling not clearing on Details pages

Sometimes polling wouldn't get cleared after going from Details page to
another Details page, so the new Details page would show info from a
wrong page.
Sergiu Miclea před 6 roky
rodič
revize
799dbbac5c

+ 4 - 4
src/components/pages/MigrationDetailsPage/MigrationDetailsPage.jsx

@@ -61,7 +61,7 @@ class MigrationDetailsPage extends React.Component<Props, State> {
     showFromReplicaModal: false,
     showFromReplicaModal: false,
   }
   }
 
 
-  pollTimeout: TimeoutID
+  stopPolling: ?boolean
 
 
   componentDidMount() {
   componentDidMount() {
     document.title = 'Migration Details'
     document.title = 'Migration Details'
@@ -82,7 +82,7 @@ class MigrationDetailsPage extends React.Component<Props, State> {
 
 
   componentWillUnmount() {
   componentWillUnmount() {
     migrationStore.clearDetails()
     migrationStore.clearDetails()
-    clearTimeout(this.pollTimeout)
+    this.stopPolling = true
   }
   }
 
 
   loadMigrationWithInstances(migrationId: string, cache: boolean) {
   loadMigrationWithInstances(migrationId: string, cache: boolean) {
@@ -178,11 +178,11 @@ class MigrationDetailsPage extends React.Component<Props, State> {
   }
   }
 
 
   pollData() {
   pollData() {
-    if (this.state.showEditModal) {
+    if (this.state.showEditModal || this.stopPolling) {
       return
       return
     }
     }
     migrationStore.getMigration(this.props.match.params.id, false).then(() => {
     migrationStore.getMigration(this.props.match.params.id, false).then(() => {
-      this.pollTimeout = setTimeout(() => { this.pollData() }, configLoader.config.requestPollTimeout)
+      setTimeout(() => { this.pollData() }, configLoader.config.requestPollTimeout)
     })
     })
   }
   }
 
 

+ 4 - 4
src/components/pages/ReplicaDetailsPage/ReplicaDetailsPage.jsx

@@ -81,7 +81,7 @@ class ReplicaDetailsPage extends React.Component<Props, State> {
     isEditable: false,
     isEditable: false,
   }
   }
 
 
-  pollTimeout: TimeoutID
+  stopPolling: ?boolean
 
 
   componentDidMount() {
   componentDidMount() {
     document.title = 'Replica Details'
     document.title = 'Replica Details'
@@ -102,7 +102,7 @@ class ReplicaDetailsPage extends React.Component<Props, State> {
   componentWillUnmount() {
   componentWillUnmount() {
     replicaStore.clearDetails()
     replicaStore.clearDetails()
     scheduleStore.clearUnsavedSchedules()
     scheduleStore.clearUnsavedSchedules()
-    clearTimeout(this.pollTimeout)
+    this.stopPolling = true
   }
   }
 
 
   loadIsEditable(replicaDetails: MainItem) {
   loadIsEditable(replicaDetails: MainItem) {
@@ -306,7 +306,7 @@ class ReplicaDetailsPage extends React.Component<Props, State> {
   }
   }
 
 
   pollData(showLoading: boolean) {
   pollData(showLoading: boolean) {
-    if (this.state.showEditModal) {
+    if (this.state.showEditModal || this.stopPolling) {
       return
       return
     }
     }
 
 
@@ -315,7 +315,7 @@ class ReplicaDetailsPage extends React.Component<Props, State> {
     }
     }
 
 
     replicaStore.getReplicaExecutions(this.props.match.params.id, showLoading).then(() => {
     replicaStore.getReplicaExecutions(this.props.match.params.id, showLoading).then(() => {
-      this.pollTimeout = setTimeout(() => { this.pollData(false) }, configLoader.config.requestPollTimeout)
+      setTimeout(() => { this.pollData(false) }, configLoader.config.requestPollTimeout)
     })
     })
   }
   }