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



##########
File path: web/src/components/RawDataEditor/RawDataEditor.tsx
##########
@@ -0,0 +1,106 @@
+/*
+ * 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 } from 'react';
+import { Button, Drawer, PageHeader, Tooltip, notification } from 'antd';
+import { LinkOutlined } from '@ant-design/icons';
+import CodeMirror from '@uiw/react-codemirror';
+import { CopyToClipboard } from 'react-copy-to-clipboard';
+import { useIntl } from 'umi';
+
+type Props = {
+  visible: boolean,

Review comment:
       both `visible` or `readonly` is optional, the default value is `false`. 

##########
File path: web/src/components/RawDataEditor/RawDataEditor.tsx
##########
@@ -0,0 +1,106 @@
+/*
+ * 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 } from 'react';
+import { Button, Drawer, PageHeader, Tooltip, notification } from 'antd';
+import { LinkOutlined } from '@ant-design/icons';
+import CodeMirror from '@uiw/react-codemirror';
+import { CopyToClipboard } from 'react-copy-to-clipboard';
+import { useIntl } from 'umi';
+
+type Props = {
+  visible: boolean,
+  readonly: boolean,
+  type: 'route' | 'service' | 'consumer' | 'upstream'
+  data: any,
+  onClose?: () => void;
+};
+
+const RawDataEditor: React.FC<Props> = ({ visible, readonly = true, type, data 
= {}, onClose }) => {
+  const ref = useRef<any>(null);
+  const { formatMessage } = useIntl();
+
+  return (
+    <div>
+      <Drawer
+        title='Raw Data Editor'
+        placement="right"
+        width={700}
+        visible={visible}
+        onClose={onClose}
+      >
+        <PageHeader
+          title=""
+          ghost={false}

Review comment:
       the default value is `true`?

##########
File path: web/src/components/RawDataEditor/RawDataEditor.tsx
##########
@@ -0,0 +1,106 @@
+/*
+ * 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 } from 'react';
+import { Button, Drawer, PageHeader, Tooltip, notification } from 'antd';
+import { LinkOutlined } from '@ant-design/icons';
+import CodeMirror from '@uiw/react-codemirror';
+import { CopyToClipboard } from 'react-copy-to-clipboard';
+import { useIntl } from 'umi';
+
+type Props = {
+  visible: boolean,
+  readonly: boolean,
+  type: 'route' | 'service' | 'consumer' | 'upstream'
+  data: any,
+  onClose?: () => void;
+};
+
+const RawDataEditor: React.FC<Props> = ({ visible, readonly = true, type, data 
= {}, onClose }) => {
+  const ref = useRef<any>(null);
+  const { formatMessage } = useIntl();
+
+  return (
+    <div>

Review comment:
       We could use `<React.Fragment />` here to replace `div`

##########
File path: web/src/pages/Consumer/List.tsx
##########
@@ -59,6 +62,12 @@ const Page: React.FC = () => {
           >
             {formatMessage({ id: 'component.global.edit' })}
           </Button>
+          <Button type="primary" style={{ marginRight: 10 }} onClick={() => {
+            setRawDataEditorVisable(!rawDataEditorVisable);

Review comment:
       ```suggestion
               setRawDataEditorVisable(true);
   ```

##########
File path: web/src/components/RawDataEditor/locales/en-US.ts
##########
@@ -0,0 +1,19 @@
+/*
+ * 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.
+ */
+export default {
+  'component.rawDataEditor.tip': 'Editing is not currently supported',

Review comment:
       ```suggestion
     'component.rawDataEditor.tip': 'Don't support edit mode currently',
   ```

##########
File path: web/src/pages/Upstream/List.tsx
##########
@@ -64,6 +68,12 @@ const Page: React.FC = () => {
           >
             {formatMessage({ id: 'page.upstream.list.edit' })}
           </Button>
+          <Button type="primary" onClick={() => {
+            setRawDataEditorVisable(!rawDataEditorVisable);

Review comment:
       ditto

##########
File path: web/src/pages/Consumer/List.tsx
##########
@@ -23,12 +23,15 @@ import { history, useIntl } from 'umi';
 import { PlusOutlined } from '@ant-design/icons';
 
 import { timestampToLocaleString } from '@/helpers';
+import { RawDataEditor } from '@/components/RawDataEditor';

Review comment:
       if only export one function, set it as the default usually.

##########
File path: web/src/pages/Consumer/List.tsx
##########
@@ -23,12 +23,15 @@ import { history, useIntl } from 'umi';
 import { PlusOutlined } from '@ant-design/icons';
 
 import { timestampToLocaleString } from '@/helpers';
+import { RawDataEditor } from '@/components/RawDataEditor';
 
 import { fetchList, remove } from './service';
 
 const Page: React.FC = () => {
   const ref = useRef<ActionType>();
   const { formatMessage } = useIntl();
+  const [rawDataEditorVisable, setRawDataEditorVisable] = useState(false);

Review comment:
       ```suggestion
     const [rawDataEditorVisible, setRawDataEditorVisible] = useState(false);
   ```

##########
File path: web/src/pages/Route/List.tsx
##########
@@ -378,6 +381,12 @@ const Page: React.FC = () => {
             <Button type="primary" onClick={() => 
history.push(`/routes/${record.id}/edit`)}>
               {formatMessage({ id: 'component.global.edit' })}
             </Button>
+            <Button type="primary" onClick={() => {
+              setRawDataEditorVisable(!rawDataEditorVisable);

Review comment:
       ditto

##########
File path: web/src/pages/Consumer/List.tsx
##########
@@ -59,6 +62,12 @@ const Page: React.FC = () => {
           >
             {formatMessage({ id: 'component.global.edit' })}
           </Button>
+          <Button type="primary" style={{ marginRight: 10 }} onClick={() => {
+            setRawDataEditorVisable(!rawDataEditorVisable);
+            setRawData(record);

Review comment:
       Should we set data first, then show that editor?

##########
File path: web/src/components/RawDataEditor/RawDataEditor.tsx
##########
@@ -0,0 +1,106 @@
+/*
+ * 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 } from 'react';
+import { Button, Drawer, PageHeader, Tooltip, notification } from 'antd';
+import { LinkOutlined } from '@ant-design/icons';
+import CodeMirror from '@uiw/react-codemirror';
+import { CopyToClipboard } from 'react-copy-to-clipboard';
+import { useIntl } from 'umi';
+
+type Props = {
+  visible: boolean,
+  readonly: boolean,
+  type: 'route' | 'service' | 'consumer' | 'upstream'
+  data: any,

Review comment:
       ```suggestion
     data: Record<string, any>,
   ```

##########
File path: web/src/components/RawDataEditor/RawDataEditor.tsx
##########
@@ -0,0 +1,106 @@
+/*
+ * 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 } from 'react';
+import { Button, Drawer, PageHeader, Tooltip, notification } from 'antd';
+import { LinkOutlined } from '@ant-design/icons';
+import CodeMirror from '@uiw/react-codemirror';
+import { CopyToClipboard } from 'react-copy-to-clipboard';
+import { useIntl } from 'umi';
+
+type Props = {
+  visible: boolean,
+  readonly: boolean,
+  type: 'route' | 'service' | 'consumer' | 'upstream'
+  data: any,
+  onClose?: () => void;
+};
+
+const RawDataEditor: React.FC<Props> = ({ visible, readonly = true, type, data 
= {}, onClose }) => {
+  const ref = useRef<any>(null);
+  const { formatMessage } = useIntl();
+
+  return (
+    <div>
+      <Drawer
+        title='Raw Data Editor'

Review comment:
       i18n
   
   - Raw Data Editor
   - 元数据编辑器

##########
File path: web/src/pages/Service/List.tsx
##########
@@ -53,10 +56,15 @@ const Page: React.FC = () => {
             <Button
               type="primary"
               onClick={() => history.push(`/service/${record.id}/edit`)}
-              style={{ marginRight: 10 }}
             >
               {formatMessage({ id: 'component.global.edit' })}
             </Button>
+            <Button type="primary" onClick={() => {
+              setRawDataEditorVisable(!rawDataEditorVisable);

Review comment:
       ditto




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