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



##########
File path: web/src/pages/Route/List.tsx
##########
@@ -14,21 +14,32 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-import React, { useRef, useState } from 'react';
+import React, { useRef, useEffect, useState } from 'react';
 import { PageHeaderWrapper } from '@ant-design/pro-layout';
 import ProTable, { ProColumns, ActionType } from '@ant-design/pro-table';
-import { Button, Popconfirm, notification, Tag, Space } from 'antd';
+import { Button, Popconfirm, notification, Tag, Space, Select } from 'antd';
 import { history, useIntl } from 'umi';
 import { PlusOutlined, BugOutlined } from '@ant-design/icons';
-import { timestampToLocaleString } from '@/helpers';
 
-import { fetchList, remove, updateRouteStatus } from './service';
+import { timestampToLocaleString } from '@/helpers';
+import { transformLabelList } from './transform';
+import { fetchList, remove, fetchLabelList, updateRouteStatus } from 
'./service';
 import { DebugDrawView } from './components/DebugViews';
 
+
+const { OptGroup, Option } = Select;
+
 const Page: React.FC = () => {
   const ref = useRef<ActionType>();
   const { formatMessage } = useIntl();
 
+  const [labelList, setLabelList] = useState<RouteModule.LabelList>({});
+
+  useEffect(() => {
+    fetchLabelList().then((data) => {
+      setLabelList(transformLabelList(data));

Review comment:
       would better use a transformer in service, then you could set state by 
`then(setXXX)`

##########
File path: web/src/locales/zh-CN/component.ts
##########
@@ -32,6 +32,7 @@ export default {
   'component.global.loading': '加载中',
   'component.global.list': '列表',
   'component.global.description': '描述',
+  'component.global.label': '标签',

Review comment:
       ```suggestion
     'component.global.labels': '标签',
   ```

##########
File path: web/src/pages/Route/List.tsx
##########
@@ -90,6 +101,47 @@ const Page: React.FC = () => {
       dataIndex: 'desc',
       hideInSearch: true,
     },
+    {
+      title: formatMessage({ id: 'component.global.label' }),
+      dataIndex: 'labels',
+      render: (_, record) => {
+        return Object.keys(record.labels || {}).map((item) => (
+          <Tag key={Math.random().toString(36).slice(2)}>

Review comment:
       why use this method to set key?

##########
File path: web/src/pages/Route/components/Step1/LabelsDrawer.tsx
##########
@@ -0,0 +1,176 @@
+/*
+ * 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 { AutoComplete, Button, Col, Drawer, Form, notification, Row } from 
'antd';
+import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons';
+import { useIntl } from 'umi';
+
+import { transformLabelList, transformLableValueToKeyValue } from 
'../../transform';
+import { fetchLabelList } from '../../service';
+
+interface Props extends Pick<RouteModule.Step1PassProps, 'onChange'> {
+  labelsDataSource: string[];
+  disabled: boolean;
+  onClose(): void;
+}
+
+const LabelList = (disabled: boolean, labelList: RouteModule.LabelList) => {
+  const { formatMessage } = useIntl();
+
+  const keyOptions = Object.keys(labelList || {}).map((item) => ({ value: item 
}));
+  return (
+    <Form.List name="labels">
+      {(fields, { add, remove }) => {
+        return (
+          <>
+            {fields.map((field, index) => (
+              <Form.Item
+                key={field.key}
+                label={index === 0 && 'Label'}
+                labelCol={{ span: index === 0 ? 3 : 0 }}
+                wrapperCol={{ offset: index === 0 ? 0 : 3 }}
+              >
+                <Row style={{ marginBottom: 10 }} gutter={16}>
+                  <Col>
+                    <Form.Item
+                      style={{ marginBottom: 0 }}
+                      name={[field.name, 'labelKey']}
+                      rules={[
+                        {
+                          required: true,
+                          message: 'Please input key',
+                        },
+                      ]}
+                    >
+                      <AutoComplete options={keyOptions} style={{ width: 100 
}} />
+                    </Form.Item>
+                  </Col>
+                  <Col>
+                    <Form.Item shouldUpdate noStyle>
+                      {({ getFieldValue }) => {
+                        const key = getFieldValue(['labels', field.name, 
'labelKey']);
+                        let valueOptions = [{ value: '' }];
+                        if (labelList) {
+                          valueOptions = (labelList[key] || []).map((item) => 
({ value: item }));
+                        }
+
+                        return (
+                          <Form.Item
+                            noStyle
+                            name={[field.name, 'labelValue']}
+                            fieldKey={[field.fieldKey, 'labelValue']}
+                            rules={[
+                              {
+                                required: true,
+                                message: 'Please input value',
+                              },
+                            ]}
+                          >
+                            <AutoComplete options={valueOptions} style={{ 
width: 100 }} />
+                          </Form.Item>
+                        );
+                      }}
+                    </Form.Item>
+                  </Col>
+                  <Col>
+                    {!disabled && <MinusCircleOutlined onClick={() => 
remove(field.name)} />}
+                  </Col>
+                </Row>
+              </Form.Item>
+            ))}
+            {!disabled && (
+              <Form.Item wrapperCol={{ offset: 3 }}>
+                <Button type="dashed" onClick={add}>
+                  <PlusOutlined />
+                  {formatMessage({ id: 'component.global.add' })}
+                </Button>
+              </Form.Item>
+            )}
+          </>
+        );
+      }}
+    </Form.List>
+  );
+};
+
+const LabelsDrawer: React.FC<Props> = ({
+  disabled,
+  labelsDataSource,
+  onClose,
+  onChange = () => { },
+}) => {
+  const transformLabel = transformLableValueToKeyValue(labelsDataSource);
+
+  const { formatMessage } = useIntl();
+  const [form] = Form.useForm();
+  const [labelList, setLabelList] = useState<RouteModule.LabelList>();

Review comment:
       default value?




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