You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2022/03/01 05:46:24 UTC

[GitHub] [apisix-dashboard] guoqqqi commented on a change in pull request #2320: feat: support protobuf on Web

guoqqqi commented on a change in pull request #2320:
URL: https://github.com/apache/apisix-dashboard/pull/2320#discussion_r816464029



##########
File path: web/src/pages/Proto/List.tsx
##########
@@ -0,0 +1,168 @@
+/*
+ * 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, { useRef, useEffect, useState } from 'react';
+import { PageHeaderWrapper } from '@ant-design/pro-layout';
+import ProTable from '@ant-design/pro-table';
+import type { ProColumns, ActionType } from '@ant-design/pro-table';
+import ProtoDrawer from './components/ProtoDrawer';
+import { Button, notification, Popconfirm, Space } from 'antd';
+import { history, useIntl } from 'umi';
+import { PlusOutlined } from '@ant-design/icons';
+import querystring from 'query-string';
+
+import { timestampToLocaleString } from '@/helpers';
+import { fetchList, remove } from './service';
+
+const Page: React.FC = () => {
+  const ref = useRef<ActionType>();
+  const { formatMessage } = useIntl();
+  const [drawerVisible, setDrawerVisible] = useState(false);
+  const emptyProtoData = {
+    id: null,
+    content: '',
+    desc: '',
+  };
+  const [protoData, setProtoData] = useState<ProtoModule.ProtoData>(emptyProtoData);
+  const [editMode, setEditMode] = useState<ProtoModule.EditMode>('create');
+  const [paginationConfig, setPaginationConfig] = useState({ pageSize: 10, current: 1 });
+
+  const refreshTable = () => {
+    ref.current?.reload();
+  };
+
+  const savePageList = (page = 1, pageSize = 10) => {
+    history.replace(`/proto/list?page=${page}&pageSize=${pageSize}`);
+  };
+
+  useEffect(() => {
+    const { page = 1, pageSize = 10 } = querystring.parse(window.location.search);
+    setPaginationConfig({ pageSize: Number(pageSize), current: Number(page) });
+  }, [window.location.search]);
+
+  const showDrawer = (data: ProtoModule.ProtoData, mode: ProtoModule.EditMode) => {
+    setDrawerVisible(true);
+    setProtoData(data);
+    setEditMode(mode);
+  };
+
+  const columns: ProColumns<ProtoModule.ResponseBody>[] = [
+    {
+      title: formatMessage({ id: 'component.global.id' }),
+      hideInSearch: true,
+      dataIndex: 'id',
+      width: 100,
+    },
+    {
+      title: formatMessage({ id: 'page.proto.desc' }),
+      dataIndex: 'desc',
+      ellipsis: true,
+      width: 200,
+    },
+    {
+      title: formatMessage({ id: 'page.proto.content' }),
+      hideInSearch: true,
+      dataIndex: 'content',
+      ellipsis: true,
+    },
+    {
+      title: formatMessage({ id: 'component.global.updateTime' }),
+      dataIndex: 'update_time',
+      hideInSearch: true,
+      render: (text) => timestampToLocaleString(text as number),
+      width: 200,
+    },
+    {
+      title: formatMessage({ id: 'component.global.operation' }),
+      valueType: 'option',
+      fixed: 'right',
+      hideInSearch: true,
+      render: (_, record) => (
+        <>

Review comment:
       ```suggestion
   
   ```

##########
File path: web/src/pages/Proto/List.tsx
##########
@@ -0,0 +1,168 @@
+/*
+ * 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, { useRef, useEffect, useState } from 'react';
+import { PageHeaderWrapper } from '@ant-design/pro-layout';
+import ProTable from '@ant-design/pro-table';
+import type { ProColumns, ActionType } from '@ant-design/pro-table';
+import ProtoDrawer from './components/ProtoDrawer';
+import { Button, notification, Popconfirm, Space } from 'antd';
+import { history, useIntl } from 'umi';
+import { PlusOutlined } from '@ant-design/icons';
+import querystring from 'query-string';
+
+import { timestampToLocaleString } from '@/helpers';
+import { fetchList, remove } from './service';
+
+const Page: React.FC = () => {
+  const ref = useRef<ActionType>();
+  const { formatMessage } = useIntl();
+  const [drawerVisible, setDrawerVisible] = useState(false);
+  const emptyProtoData = {
+    id: null,
+    content: '',
+    desc: '',
+  };
+  const [protoData, setProtoData] = useState<ProtoModule.ProtoData>(emptyProtoData);
+  const [editMode, setEditMode] = useState<ProtoModule.EditMode>('create');
+  const [paginationConfig, setPaginationConfig] = useState({ pageSize: 10, current: 1 });
+
+  const refreshTable = () => {
+    ref.current?.reload();
+  };
+
+  const savePageList = (page = 1, pageSize = 10) => {
+    history.replace(`/proto/list?page=${page}&pageSize=${pageSize}`);
+  };
+
+  useEffect(() => {
+    const { page = 1, pageSize = 10 } = querystring.parse(window.location.search);
+    setPaginationConfig({ pageSize: Number(pageSize), current: Number(page) });
+  }, [window.location.search]);
+
+  const showDrawer = (data: ProtoModule.ProtoData, mode: ProtoModule.EditMode) => {
+    setDrawerVisible(true);
+    setProtoData(data);
+    setEditMode(mode);
+  };
+
+  const columns: ProColumns<ProtoModule.ResponseBody>[] = [
+    {
+      title: formatMessage({ id: 'component.global.id' }),
+      hideInSearch: true,
+      dataIndex: 'id',
+      width: 100,
+    },
+    {
+      title: formatMessage({ id: 'page.proto.desc' }),
+      dataIndex: 'desc',
+      ellipsis: true,
+      width: 200,
+    },
+    {
+      title: formatMessage({ id: 'page.proto.content' }),
+      hideInSearch: true,
+      dataIndex: 'content',
+      ellipsis: true,
+    },
+    {
+      title: formatMessage({ id: 'component.global.updateTime' }),
+      dataIndex: 'update_time',
+      hideInSearch: true,
+      render: (text) => timestampToLocaleString(text as number),
+      width: 200,
+    },
+    {
+      title: formatMessage({ id: 'component.global.operation' }),
+      valueType: 'option',
+      fixed: 'right',
+      hideInSearch: true,
+      render: (_, record) => (
+        <>
+          <Space align="baseline">
+            <Button
+              type="primary"
+              onClick={() =>
+                showDrawer({ id: record.id, content: record.content, desc: record.desc }, 'update')
+              }
+            >
+              {formatMessage({ id: 'component.global.edit' })}
+            </Button>
+            <Popconfirm
+              title={formatMessage({ id: 'page.upstream.list.confirm.delete' })}
+              okText={formatMessage({ id: 'page.upstream.list.confirm' })}
+              cancelText={formatMessage({ id: 'page.upstream.list.cancel' })}
+              onConfirm={() => {
+                remove(record.id).then(() => {
+                  notification.success({
+                    message: formatMessage({ id: 'page.upstream.list.delete.successfully' }),
+                  });
+                  /* eslint-disable no-unused-expressions */
+                  ref.current?.reload();
+                });
+              }}
+            >
+              <Button type="primary" danger>
+                {formatMessage({ id: 'page.upstream.list.delete' })}
+              </Button>
+            </Popconfirm>
+          </Space>
+        </>

Review comment:
       ```suggestion
   
   ```

##########
File path: web/src/pages/Proto/components/ProtoDrawer/index.tsx
##########
@@ -0,0 +1,149 @@
+/*
+ * 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 } from 'react';
+import { Button, Drawer, Form, notification, Space } from 'antd';
+import { useIntl } from 'umi';
+import Editor from '@monaco-editor/react';
+import { Input } from 'antd';
+
+import { create, update } from '../../service';
+import styles from './index.less';
+
+const ProtoDrawer: React.FC<ProtoModule.ProtoDrawerProps> = ({
+  protoData,
+  setProtoData,
+  visible,
+  setVisible,
+  editMode,
+  refreshTable,
+}) => {
+  const [form] = Form.useForm();
+  const { formatMessage } = useIntl();
+
+  useEffect(() => {
+    form.setFieldsValue(protoData);
+  }, [visible]);
+
+  const submit = async () => {
+    await form.validateFields();
+    const formData: ProtoModule.ProtoData = form.getFieldsValue(true);
+    if (editMode === 'create') {
+      create(formData).then(() => {
+        notification.success({
+          message: formatMessage({ id: 'page.proto.drawer.create.successfully' }),
+        });
+        setVisible(false);
+        refreshTable();
+      });
+    } else {
+      update(formData);
+      notification.success({
+        message: formatMessage({ id: 'page.proto.drawer.edit.successfully' }),
+      });
+      setVisible(false);
+      refreshTable();
+    }
+  };
+
+  return (
+    <Drawer
+      title={formatMessage({
+        id: editMode === 'create' ? 'page.proto.drawer.create' : 'page.proto.drawer.edit',
+      })}
+      visible={visible}
+      placement="right"
+      closable={false}
+      maskClosable={true}
+      destroyOnClose
+      onClose={() => setVisible(false)}
+      width={700}
+      footer={
+        <div style={{ display: 'flex', justifyContent: 'space-between' }}>
+          <Button
+            onClick={() => {
+              setVisible(false);
+            }}
+          >
+            {formatMessage({ id: 'component.global.cancel' })}
+          </Button>
+          <Space>
+            <Button type="primary" onClick={() => submit()}>
+              {formatMessage({ id: 'component.global.submit' })}
+            </Button>
+          </Space>
+        </div>
+      }
+    >
+      <Form form={form} labelAlign="left" labelCol={{ span: 4 }} wrapperCol={{ span: 16 }}>
+        <Form.Item
+          label="id"
+          name="id"
+          tooltip={formatMessage({ id: 'page.proto.id.tooltip' })}
+          rules={[
+            {
+              required: true,
+              message: `${formatMessage({ id: 'component.global.pleaseEnter' })} id`,
+            },
+          ]}
+          validateTrigger={['onChange', 'onBlur', 'onClick']}
+        >
+          <Input disabled={editMode === 'update'} required></Input>
+        </Form.Item>
+        <Form.Item
+          label="desc"
+          name="desc"
+          tooltip={formatMessage({ id: 'page.proto.desc.tooltip' })}
+          validateTrigger={['onChange', 'onBlur', 'onClick']}
+        >
+          <Input></Input>

Review comment:
       ```suggestion
             <Input />
   ```

##########
File path: web/src/pages/Proto/components/ProtoDrawer/index.tsx
##########
@@ -0,0 +1,149 @@
+/*
+ * 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 } from 'react';
+import { Button, Drawer, Form, notification, Space } from 'antd';
+import { useIntl } from 'umi';
+import Editor from '@monaco-editor/react';
+import { Input } from 'antd';
+
+import { create, update } from '../../service';
+import styles from './index.less';
+
+const ProtoDrawer: React.FC<ProtoModule.ProtoDrawerProps> = ({
+  protoData,
+  setProtoData,
+  visible,
+  setVisible,
+  editMode,
+  refreshTable,
+}) => {
+  const [form] = Form.useForm();
+  const { formatMessage } = useIntl();
+
+  useEffect(() => {
+    form.setFieldsValue(protoData);
+  }, [visible]);
+
+  const submit = async () => {
+    await form.validateFields();
+    const formData: ProtoModule.ProtoData = form.getFieldsValue(true);
+    if (editMode === 'create') {
+      create(formData).then(() => {
+        notification.success({
+          message: formatMessage({ id: 'page.proto.drawer.create.successfully' }),
+        });
+        setVisible(false);
+        refreshTable();
+      });
+    } else {
+      update(formData);
+      notification.success({
+        message: formatMessage({ id: 'page.proto.drawer.edit.successfully' }),
+      });
+      setVisible(false);
+      refreshTable();
+    }
+  };
+
+  return (
+    <Drawer
+      title={formatMessage({
+        id: editMode === 'create' ? 'page.proto.drawer.create' : 'page.proto.drawer.edit',
+      })}
+      visible={visible}
+      placement="right"
+      closable={false}
+      maskClosable={true}
+      destroyOnClose
+      onClose={() => setVisible(false)}
+      width={700}
+      footer={
+        <div style={{ display: 'flex', justifyContent: 'space-between' }}>
+          <Button
+            onClick={() => {
+              setVisible(false);
+            }}
+          >
+            {formatMessage({ id: 'component.global.cancel' })}
+          </Button>
+          <Space>
+            <Button type="primary" onClick={() => submit()}>
+              {formatMessage({ id: 'component.global.submit' })}
+            </Button>
+          </Space>
+        </div>
+      }
+    >
+      <Form form={form} labelAlign="left" labelCol={{ span: 4 }} wrapperCol={{ span: 16 }}>
+        <Form.Item
+          label="id"
+          name="id"
+          tooltip={formatMessage({ id: 'page.proto.id.tooltip' })}
+          rules={[
+            {
+              required: true,
+              message: `${formatMessage({ id: 'component.global.pleaseEnter' })} id`,
+            },
+          ]}
+          validateTrigger={['onChange', 'onBlur', 'onClick']}
+        >
+          <Input disabled={editMode === 'update'} required></Input>

Review comment:
       ```suggestion
             <Input disabled={editMode === 'update'} required />
   ```

##########
File path: web/src/pages/Proto/List.tsx
##########
@@ -0,0 +1,168 @@
+/*
+ * 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, { useRef, useEffect, useState } from 'react';
+import { PageHeaderWrapper } from '@ant-design/pro-layout';
+import ProTable from '@ant-design/pro-table';
+import type { ProColumns, ActionType } from '@ant-design/pro-table';
+import ProtoDrawer from './components/ProtoDrawer';

Review comment:
       chang this to the 27 line




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

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

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