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/02/23 02:15:45 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_r812510125



##########
File path: web/src/pages/Proto/components/ProtoDrawer/index.tsx
##########
@@ -0,0 +1,160 @@
+/*
+ * 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';

Review comment:
       ```suggestion
   import { Input } from 'antd';
   
   import { create, update } from '../../service';
   ```

##########
File path: web/src/pages/Proto/List.tsx
##########
@@ -0,0 +1,170 @@
+/*
+ * 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';

Review comment:
       ```suggestion
   import { PlusOutlined } from '@ant-design/icons';
   import querystring from 'query-string';
   
   import { timestampToLocaleString } from '@/helpers';
   ```

##########
File path: web/src/pages/Proto/components/ProtoDrawer/index.less
##########
@@ -0,0 +1,28 @@
+/*
+ * 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 '~antd/es/style/themes/default.less';
+
+.formItemEditor {
+  flex-flow: column;
+  row-gap: 20px !important;
+
+  :global {
+    .ant-form-item-explain-error {
+      padding-left: 25px;
+    }

Review comment:
       It seems to have an effect on the error message on all pages here? Please make sure it doesn't affect other form styles.

##########
File path: web/src/pages/Proto/List.tsx
##########
@@ -0,0 +1,170 @@
+/*
+ * 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>
+        </>
+      ),
+    },
+  ];
+
+  return (
+    <>
+      <ProtoDrawer
+        protoData={protoData as ProtoModule.ProtoData}
+        setProtoData={setProtoData}
+        visible={drawerVisible}
+        setVisible={setDrawerVisible}
+        editMode={editMode}
+        refreshTable={refreshTable}
+      ></ProtoDrawer>

Review comment:
       ```suggestion
         <ProtoDrawer
           protoData={protoData as ProtoModule.ProtoData}
           setProtoData={setProtoData}
           visible={drawerVisible}
           setVisible={setDrawerVisible}
           editMode={editMode}
           refreshTable={refreshTable}
         />
   ```

##########
File path: web/src/pages/Proto/components/ProtoDrawer/index.tsx
##########
@@ -0,0 +1,160 @@
+/*
+ * 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: 'component.global.create' })} ${formatMessage({
+            id: 'menu.proto',
+          })} ${formatMessage({
+            id: 'component.status.success',
+          })}`,

Review comment:
       We would prefer not to use this style of writing, which is not particularly friendly to Chinese and English

##########
File path: web/src/pages/Proto/List.tsx
##########
@@ -0,0 +1,170 @@
+/*
+ * 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>
+        </>
+      ),
+    },
+  ];
+
+  return (
+    <>
+      <ProtoDrawer
+        protoData={protoData as ProtoModule.ProtoData}
+        setProtoData={setProtoData}
+        visible={drawerVisible}
+        setVisible={setDrawerVisible}
+        editMode={editMode}
+        refreshTable={refreshTable}
+      ></ProtoDrawer>

Review comment:
       And I think we can just put the drawer component inside the PageHeaderWrapper




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