LiteSun commented on a change in pull request #483:
URL: https://github.com/apache/apisix-dashboard/pull/483#discussion_r491783103



##########
File path: src/pages/Route/Create.tsx
##########
@@ -68,80 +60,63 @@ const Page: React.FC<Props> = (props) => {
     formatMessage({ id: 'route.constants.preview' }),
   ];
 
-  const [step1Data, setStep1Data] = useState(DEFAULT_STEP_1_DATA);
-  const [step2Data, setStep2Data] = useState(DEFAULT_STEP_2_DATA);
+  const [advancedMatchingRules, setAdvancedMatchingRules] = 
useState<RouteModule.MatchingRule[]>(
+    [],
+  );
+  const [upstreamHeaderList, setUpstreamHeaderList] = 
useState<RouteModule.UpstreamHeader[]>([]);
   const [step3Data, setStep3Data] = useState(DEFAULT_STEP_3_DATA);
-
   const [redirect, setRedirect] = useState(false);
 
   const [form1] = Form.useForm();
   const [form2] = Form.useForm();
 
   const [step, setStep] = useState(1);
   const [stepHeader, setStepHeader] = useState(STEP_HEADER_4);
-
   const [chart, setChart] = useState(INIT_CHART);
 
-  const routeData = {
-    step1Data,
-    step2Data,
-    step3Data,
-  };
   const setupRoute = (rid: number) =>
     fetchItem(rid).then((data) => {
-      form1.setFieldsValue(data.step1Data);
-      setStep1Data(data.step1Data as RouteModule.Step1Data);
-
-      form2.setFieldsValue(data.step2Data);
-      setStep2Data(data.step2Data);
-
+      form1.setFieldsValue(data.form1Data);
+      setAdvancedMatchingRules(data.advancedMatchingRules);
+      form2.setFieldsValue(data.form2Data);
+      setUpstreamHeaderList(data.upstreamHeaderList);
       setStep3Data(data.step3Data);
     });
 
-  useEffect(() => {
-    if (props.route.path.indexOf('edit') !== -1) {
-      setupRoute(props.match.params.rid);
-    }
-  }, []);
-
-  useEffect(() => {
-    const { redirectOption } = step1Data;
-
-    if (redirectOption === 'customRedirect') {
-      setRedirect(true);
-      setStepHeader(STEP_HEADER_2);
-      return;
-    }
-    setRedirect(false);
-    setStepHeader(STEP_HEADER_4);
-  }, [step1Data]);
-
   const onReset = () => {
-    setStep1Data(DEFAULT_STEP_1_DATA);
-    setStep2Data(DEFAULT_STEP_2_DATA);
+    setAdvancedMatchingRules([]);
+    setUpstreamHeaderList([]);
     setStep3Data(DEFAULT_STEP_3_DATA);
-
     form1.setFieldsValue(DEFAULT_STEP_1_DATA);
     form2.setFieldsValue(DEFAULT_STEP_2_DATA);
     setStep(1);
   };
 
+  useEffect(() => {
+    if (props.route.path.indexOf('edit') !== -1) {
+      setupRoute(props.match.params.rid);
+    } else {
+      onReset();

Review comment:
       > Why we should reset all fields when creating a route? the initial data 
should be empty, right?
   `onReset()` is here to initialize the page data.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to