juzhiyuan commented on a change in pull request #1089:
URL: https://github.com/apache/apisix-dashboard/pull/1089#discussion_r547095850



##########
File path: web/src/pages/Service/Create.tsx
##########
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import React, { useState, useRef, useEffect } from 'react'
+import { useIntl, history } from 'umi';
+import { Card, Steps, Form, notification } from 'antd';
+import { PageHeaderWrapper } from '@ant-design/pro-layout';
+import { omit } from 'lodash';
+
+import ActionBar from '@/components/ActionBar';
+import PluginPage from '@/components/Plugin';
+import Preview from './components/Preview';
+import Step1 from "./components/Step1";
+import { create, update, fetchItem } from './service';
+
+const { Step } = Steps;
+
+const Page: React.FC = (props) => {
+    const { formatMessage } = useIntl();
+    const [form] = Form.useForm();
+    const [upstreamForm] = Form.useForm();
+    const upstreamRef = useRef<any>();
+    const [plugins, setPlugins] = useState<PluginComponent.Data>({});
+
+    const STEP_HEADER = [
+        formatMessage({ id: 'page.service.steps.stepTitle.basicInformation' }),
+        formatMessage({ id: 'page.service.steps.stepTitle.pluginConfig' }),
+        formatMessage({ id: 'component.global.steps.stepTitle.preview' }),
+    ]
+
+    const [stepHeader] = useState(STEP_HEADER);
+    const [step, setStep] = useState(1);
+
+    useEffect(() => {
+        const { serviceId } = (props as any).match.params;

Review comment:
       4 spaces?

##########
File path: web/src/pages/Service/Create.tsx
##########
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import React, { useState, useRef, useEffect } from 'react'
+import { useIntl, history } from 'umi';
+import { Card, Steps, Form, notification } from 'antd';
+import { PageHeaderWrapper } from '@ant-design/pro-layout';
+import { omit } from 'lodash';
+
+import ActionBar from '@/components/ActionBar';
+import PluginPage from '@/components/Plugin';
+import Preview from './components/Preview';
+import Step1 from "./components/Step1";
+import { create, update, fetchItem } from './service';
+
+const { Step } = Steps;
+
+const Page: React.FC = (props) => {
+    const { formatMessage } = useIntl();
+    const [form] = Form.useForm();
+    const [upstreamForm] = Form.useForm();
+    const upstreamRef = useRef<any>();
+    const [plugins, setPlugins] = useState<PluginComponent.Data>({});
+
+    const STEP_HEADER = [
+        formatMessage({ id: 'page.service.steps.stepTitle.basicInformation' }),
+        formatMessage({ id: 'page.service.steps.stepTitle.pluginConfig' }),
+        formatMessage({ id: 'component.global.steps.stepTitle.preview' }),
+    ]
+
+    const [stepHeader] = useState(STEP_HEADER);
+    const [step, setStep] = useState(1);
+
+    useEffect(() => {
+        const { serviceId } = (props as any).match.params;
+        if (serviceId) {
+            fetchItem(serviceId).then(({ data }) => {
+                if (data.upstream_id && data.upstream_id !== '') {

Review comment:
       `"" === falsy`

##########
File path: web/src/pages/Service/Create.tsx
##########
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import React, { useState, useRef, useEffect } from 'react'
+import { useIntl, history } from 'umi';
+import { Card, Steps, Form, notification } from 'antd';
+import { PageHeaderWrapper } from '@ant-design/pro-layout';
+import { omit } from 'lodash';
+
+import ActionBar from '@/components/ActionBar';
+import PluginPage from '@/components/Plugin';
+import Preview from './components/Preview';
+import Step1 from "./components/Step1";
+import { create, update, fetchItem } from './service';
+
+const { Step } = Steps;
+
+const Page: React.FC = (props) => {
+    const { formatMessage } = useIntl();
+    const [form] = Form.useForm();
+    const [upstreamForm] = Form.useForm();
+    const upstreamRef = useRef<any>();
+    const [plugins, setPlugins] = useState<PluginComponent.Data>({});
+
+    const STEP_HEADER = [
+        formatMessage({ id: 'page.service.steps.stepTitle.basicInformation' }),
+        formatMessage({ id: 'page.service.steps.stepTitle.pluginConfig' }),
+        formatMessage({ id: 'component.global.steps.stepTitle.preview' }),
+    ]
+
+    const [stepHeader] = useState(STEP_HEADER);
+    const [step, setStep] = useState(1);
+
+    useEffect(() => {
+        const { serviceId } = (props as any).match.params;
+        if (serviceId) {
+            fetchItem(serviceId).then(({ data }) => {
+                if (data.upstream_id && data.upstream_id !== '') {
+                    upstreamForm.setFieldsValue({ upstream_id: 
data.upstream_id });
+                }
+                if (data.upstream) {
+                    upstreamForm.setFieldsValue(data.upstream);
+                }
+                form.setFieldsValue(omit(data, ['upstream_id', 'upstream']));
+                setPlugins(data.plugins || {});
+            });
+        }
+    }, []);
+
+    const onSubmit = () => {
+        const data = {
+            ...form.getFieldsValue(),
+            plugins,
+        };
+
+        const upstreamFormData = upstreamForm.getFieldsValue();
+        if (upstreamFormData.upstream_id === '') {
+            data.upstream = omit(upstreamFormData, ['upstream_id']);
+        } else {
+            data.upstream_id = upstreamFormData.upstream_id;
+        }
+
+        const { serviceId } = (props as any).match.params;
+        (serviceId ? update(serviceId, data) : create(data))
+            .then(() => {
+                notification.success({
+                    message: `${serviceId
+                        ? formatMessage({ id: 'component.global.edit' })
+                        : formatMessage({ id: 'component.global.create' })
+                        } ${formatMessage({ id: 'menu.service' })} 
${formatMessage({
+                            id: 'component.status.success',
+                        })}`,
+                });
+                history.push('/service/list');
+            })
+            .catch(() => {
+                setStep(3);
+            });
+    };
+
+    const onStepChange = (nextStep: number) => {
+        if (nextStep === 2) {

Review comment:
       page 3 -> page 2?

##########
File path: web/src/pages/Service/Create.tsx
##########
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import React, { useState, useRef, useEffect } from 'react'
+import { useIntl, history } from 'umi';
+import { Card, Steps, Form, notification } from 'antd';
+import { PageHeaderWrapper } from '@ant-design/pro-layout';
+import { omit } from 'lodash';
+
+import ActionBar from '@/components/ActionBar';
+import PluginPage from '@/components/Plugin';
+import Preview from './components/Preview';
+import Step1 from "./components/Step1";
+import { create, update, fetchItem } from './service';
+
+const { Step } = Steps;
+
+const Page: React.FC = (props) => {
+    const { formatMessage } = useIntl();
+    const [form] = Form.useForm();
+    const [upstreamForm] = Form.useForm();
+    const upstreamRef = useRef<any>();
+    const [plugins, setPlugins] = useState<PluginComponent.Data>({});
+
+    const STEP_HEADER = [
+        formatMessage({ id: 'page.service.steps.stepTitle.basicInformation' }),
+        formatMessage({ id: 'page.service.steps.stepTitle.pluginConfig' }),
+        formatMessage({ id: 'component.global.steps.stepTitle.preview' }),
+    ]
+
+    const [stepHeader] = useState(STEP_HEADER);
+    const [step, setStep] = useState(1);
+
+    useEffect(() => {
+        const { serviceId } = (props as any).match.params;
+        if (serviceId) {
+            fetchItem(serviceId).then(({ data }) => {
+                if (data.upstream_id && data.upstream_id !== '') {
+                    upstreamForm.setFieldsValue({ upstream_id: 
data.upstream_id });
+                }
+                if (data.upstream) {
+                    upstreamForm.setFieldsValue(data.upstream);
+                }
+                form.setFieldsValue(omit(data, ['upstream_id', 'upstream']));

Review comment:
       and plugins?

##########
File path: web/src/pages/Service/components/Step1.tsx
##########
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import React, { useEffect, useState } from 'react';
+import { Form, Input } from 'antd';
+import { useIntl } from 'umi';
+
+import UpstreamForm from '@/components/Upstream';
+import { fetchUpstreamList } from '../service';
+
+const FORM_LAYOUT = {
+    labelCol: {
+        span: 3,
+    },
+    wrapperCol: {
+        span: 8,
+    },
+};
+
+const Step1: React.FC<ServiceModule.Step1PassProps> = ({
+    form,
+    upstreamForm,
+    upstreamRef,
+    disabled,
+}) => {
+    const { formatMessage } = useIntl();
+    const [list, setList] = useState<UpstreamModule.RequestBody[]>([]);
+    useEffect(() => {
+        fetchUpstreamList().then(({ data }) => setList(data));
+    }, []);
+
+    return <>
+        <Form {...FORM_LAYOUT} form={form}>
+            <Form.Item
+                name="name"
+                label={formatMessage({ id: 'component.global.name' })}
+            >
+                <Input disabled={disabled} />
+            </Form.Item>
+            <Form.Item
+                name="desc"
+                label={formatMessage({ id: 'component.global.description' })}
+            >
+                <Input.TextArea disabled={disabled} />
+            </Form.Item>
+        </Form>
+        <UpstreamForm
+            ref={upstreamRef}

Review comment:
       🤔 optional ref, may have a fallback value inside the component.




----------------------------------------------------------------
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