Sfoglia il codice sorgente

Fix wizard page not updating after URL change

Fixes an issue where switching between different wizard page
configurations (using different saved data permalink bookmarks) does not
update the wizard page data, so a browser refresh was needed every time.
Sergiu Miclea 8 anni fa
parent
commit
fddd4d2b45
1 ha cambiato i file con 18 aggiunte e 5 eliminazioni
  1. 18 5
      src/components/pages/WizardPage/WizardPage.jsx

+ 18 - 5
src/components/pages/WizardPage/WizardPage.jsx

@@ -48,6 +48,7 @@ const Wrapper = styled.div``
 
 type Props = {
   match: any,
+  location: { search: string }
 }
 type WizardType = 'migration' | 'replica'
 type State = {
@@ -72,11 +73,7 @@ class WizardPage extends React.Component<Props, State> {
   }
 
   componentWillMount() {
-    wizardStore.getDataFromPermalink()
-    let type = this.props.match && this.props.match.params.type
-    if (type === 'migration' || type === 'replica') {
-      this.setState({ type })
-    }
+    this.initializeState()
   }
 
   componentDidMount() {
@@ -85,6 +82,14 @@ class WizardPage extends React.Component<Props, State> {
     KeyboardManager.onEsc('wizard', () => { this.handleEscKey() })
   }
 
+  componentWillReceiveProps(newProps: Props) {
+    if (newProps.location.search === this.props.location.search) {
+      return
+    }
+    wizardStore.clearData()
+    this.initializeState()
+  }
+
   componentWillUnmount() {
     wizardStore.clearData()
     KeyboardManager.removeKeyDown('wizard')
@@ -273,6 +278,14 @@ class WizardPage extends React.Component<Props, State> {
     wizardStore.setPermalink(wizardStore.data)
   }
 
+  initializeState() {
+    wizardStore.getDataFromPermalink()
+    let type = this.props.match && this.props.match.params.type
+    if (type === 'migration' || type === 'replica') {
+      this.setState({ type })
+    }
+  }
+
   loadEnvDestinationOptions(field?: Field) {
     let provider = wizardStore.data.target && wizardStore.data.target.type
     let providerWithExtraOptions = providersWithExtraOptions.find(p => typeof p !== 'string' && p.name === provider)