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

Merge pull request #264 from smiclea/wizard-permalink

Fix wizard page not updating after URL change
Dorin Paslaru 7 лет назад
Родитель
Сommit
a487307817
1 измененных файлов с 18 добавлено и 5 удалено
  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)