juzhiyuan commented on a change in pull request #1739: URL: https://github.com/apache/apisix-dashboard/pull/1739#discussion_r611386625
########## File path: web/src/components/Plugin/UI/limit-count.tsx ########## @@ -0,0 +1,215 @@ +/* + * 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 } from 'react'; +import type { FormInstance } from 'antd/es/form'; +import { Button, Col, Form, Input, InputNumber, Row, Select } from 'antd'; +import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons'; +import { useIntl } from 'umi'; + +type Props = { + form: FormInstance; +}; + +type PolicyProps = "local" | "redis" | "redis-cluster" + +const FORM_ITEM_LAYOUT = { + labelCol: { + span: 7, + }, + wrapperCol: { + span: 10 + }, +}; + +const FORM_ITEM_WITHOUT_LABEL = { + wrapperCol: { + span: 10, offset: 7, + }, +}; + +const removeBtnStyle = { + marginLeft: 20, + display: 'flex', + alignItems: 'center', +}; + +const RedisForm: React.FC = () => { + const { formatMessage } = useIntl(); + + return (<> + <Form.Item + label="redis_host" + name="redis_host" + tooltip={formatMessage({ id: 'component.pluginForm.limit-count.redis_host.tooltip' })} + required + > + <Input /> + </Form.Item> + <Form.Item + label="redis_port" + name="redis_port" + tooltip={formatMessage({ id: 'component.pluginForm.limit-count.redis_port.tooltip' })} + > + <InputNumber min={1} /> + </Form.Item> + <Form.Item + label="redis_password" + name="redis_password" + tooltip={formatMessage({ id: 'component.pluginForm.limit-count.redis_password.tooltip' })} + required + > + <Input /> + </Form.Item> + <Form.Item + label="redis_database" + name="redis_database" + tooltip={formatMessage({ id: 'component.pluginForm.limit-count.redis_database.tooltip' })} + > + <InputNumber min={0} /> + </Form.Item> + <Form.Item + label="redis_timeout" + name="redis_timeout" + tooltip={formatMessage({ id: 'component.pluginForm.limit-count.redis_timeout.tooltip' })} + > + <InputNumber /> + </Form.Item> + </>) +} + +const RedisClusterForm: React.FC<Props> = () => { + const { formatMessage } = useIntl(); + + return ( + <> + <Form.Item + label="redis_cluster_name" + name="redis_cluster_name" + tooltip={formatMessage({ id: 'component.pluginForm.limit-count.redis_cluster_name.tooltip' })} + required + > + <Input /> + </Form.Item> + <Form.List name="redis_cluster_nodes"> + {(fields, { add, remove }) => { + return ( + <div> + <Form.Item + label='redis_cluster_nodes' + tooltip={formatMessage({ id: 'component.pluginForm.limit-count.redis_cluster_nodes.tooltip' })} + style={{ marginBottom: 0 }} + > + {fields.map((field, index) => ( + <Row style={{ marginBottom: 10 }} gutter={16} key={index}> + <Col> + <Form.Item + {...field} + validateTrigger={['onChange', 'onBlur']} + noStyle + > + <Input /> + </Form.Item> + </Col> + <Col style={{ ...removeBtnStyle, marginLeft: -10 }}> + {fields.length > 1 ? ( + <MinusCircleOutlined + className="dynamic-delete-button" + onClick={() => { + remove(field.name); + }} + /> + ) : null} + </Col> + </Row> + ))} + </Form.Item> + + <Form.Item {...FORM_ITEM_WITHOUT_LABEL}> + <Button + type="dashed" + onClick={() => { + add(); + }} + > + <PlusOutlined /> {formatMessage({ id: 'component.global.add' })} + </Button> + </Form.Item> + </div> + ); + }} + </Form.List> + </>) +} + +const LimitCount: React.FC<Props> = ({ form }) => { + const [policy, setPoicy] = useState<PolicyProps>('local'); + const { formatMessage } = useIntl() + + return ( + <Form + form={form} + {...FORM_ITEM_LAYOUT} + initialValues={{ key: 'remote_addr', redis_cluster_nodes: [''], policy, redis_port: 6379, redis_database: 0, redis_timeout: 1000 }} + > + <Form.Item + label="count" + name="count" + tooltip={formatMessage({ id: 'component.pluginForm.limit-count.count.tooltip' })} + required + > + <InputNumber min={1} /> + </Form.Item> + <Form.Item + label="time_window" + name="time_window" + tooltip={formatMessage({ id: 'component.pluginForm.limit-count.time_window.tooltip' })} + required Review comment: `time_window` is `时间窗口`, you could refer to `Konga` for a reference. -- 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: [email protected]
