This is an automated email from the ASF dual-hosted git repository. juzhiyuan pushed a commit to branch next in repository https://gitbox.apache.org/repos/asf/incubator-apisix-dashboard.git
The following commit(s) were added to refs/heads/next by this push: new 6aba3fa fix: timeout (#236) 6aba3fa is described below commit 6aba3faa724dd0ad79a9fb240ad43dc34f427cb3 Author: litesun <31329157+lite...@users.noreply.github.com> AuthorDate: Wed Jun 3 15:53:47 2020 +0800 fix: timeout (#236) * feat: limit upload file * feat: intercept default upload api request * feat: limit upload file type * fix: show file when parse SSL file fail * feat: add search feature * feat: format code * fix: remove list item not work * feat: remove relatedRouting * feat: add routes step1 page * feat: update route * feat: format code * feat: update * feat: update * feat: add checkbox rule * feat: handle Modal close event * feat: format code * feat: add page skip * feat: format code * merge * feat: clean code * fix: step4 error * feat: add edit modal * feat: add form validation * fix: step4 lose data * fix: step4 edit * add: WebSocket switch * feat: https methods list Validation * fix: timeout * clean code --- .../Routes/components/Step1/RequestConfigView.tsx | 48 ++++++---------------- .../Routes/components/Step2/RequestRewriteView.tsx | 47 +++++++++++++-------- src/pages/Routes/constants.ts | 13 +++++- src/pages/Routes/typing.d.ts | 1 + 4 files changed, 53 insertions(+), 56 deletions(-) diff --git a/src/pages/Routes/components/Step1/RequestConfigView.tsx b/src/pages/Routes/components/Step1/RequestConfigView.tsx index a758103..dc24649 100644 --- a/src/pages/Routes/components/Step1/RequestConfigView.tsx +++ b/src/pages/Routes/components/Step1/RequestConfigView.tsx @@ -1,8 +1,7 @@ -import React, { useState } from 'react'; +import React from 'react'; import Form from 'antd/es/form'; -import { Checkbox, Button, Input } from 'antd'; +import { Checkbox, Button, Input, Switch } from 'antd'; import { CheckboxValueType } from 'antd/lib/checkbox/Group'; -import { CheckboxChangeEvent } from 'antd/lib/checkbox'; import { PlusOutlined, MinusCircleOutlined } from '@ant-design/icons'; import { @@ -18,28 +17,11 @@ interface Props extends RouteModule.Data {} const RequestConfigView: React.FC<Props> = ({ data, disabled, onChange }) => { const { protocols } = data.step1Data; - // TODO: checkedList Validation - const [checkedList, setCheckedList] = useState(HTTP_METHOD_OPTION_LIST); - const [indeterminate, setIndeterminate] = useState(false); - const [checkAll, setCheckAll] = useState(true); - const onProtocolChange = (e: CheckboxValueType[]) => { if (!e.includes('HTTP') && !e.includes('HTTPS')) return; onChange({ ...data.step1Data, protocols: e }); }; - const onMethodsChange = (methods: CheckboxValueType[]) => { - setCheckedList(methods as RouteModule.HttpMethod[]); - setIndeterminate(!!methods.length && methods.length < HTTP_METHOD_OPTION_LIST.length); - setCheckAll(methods.length === HTTP_METHOD_OPTION_LIST.length); - }; - - const onCheckAllChange = (e: CheckboxChangeEvent) => { - setCheckedList(e.target.checked ? HTTP_METHOD_OPTION_LIST : []); - setIndeterminate(false); - setCheckAll(e.target.checked); - }; - const renderHosts = () => ( <Form.List name="hosts"> {(fields, { add, remove }) => { @@ -139,28 +121,22 @@ const RequestConfigView: React.FC<Props> = ({ data, disabled, onChange }) => { <Form.Item label="协议" name="protocols" rules={[{ required: true, message: '请勾选协议' }]}> <Checkbox.Group disabled={disabled} - options={['HTTP', 'HTTPS', 'WebSocket']} + options={['HTTP', 'HTTPS']} value={protocols} onChange={onProtocolChange} /> </Form.Item> + <Form.Item label="WebSocket" name="WebSocket" valuePropName="checked"> + <Switch disabled={disabled} /> + </Form.Item> {renderHosts()} <Form.Item label="路径">{renderPaths()}</Form.Item> - <Form.Item label="HTTP 方法" name="httpMethods"> - <Checkbox - indeterminate={indeterminate} - onChange={onCheckAllChange} - checked={checkAll} - disabled={disabled} - > - ANY - </Checkbox> - <Checkbox.Group - options={HTTP_METHOD_OPTION_LIST} - value={checkedList} - onChange={onMethodsChange} - disabled={disabled} - /> + <Form.Item + label="HTTP 方法" + name="httpMethods" + rules={[{ required: true, message: '请勾选 HTTP 方法' }]} + > + <Checkbox.Group options={HTTP_METHOD_OPTION_LIST} disabled={disabled} /> </Form.Item> </PanelSection> ); diff --git a/src/pages/Routes/components/Step2/RequestRewriteView.tsx b/src/pages/Routes/components/Step2/RequestRewriteView.tsx index 857f435..373c534 100644 --- a/src/pages/Routes/components/Step2/RequestRewriteView.tsx +++ b/src/pages/Routes/components/Step2/RequestRewriteView.tsx @@ -88,6 +88,8 @@ const RequestRewriteView: React.FC<Props> = ({ data, form, disabled, onChange }) </Form.List> ); + const renderTimeUnit = () => <span style={{ margin: '0 8px' }}>ms</span>; + return ( <PanelSection title="请求改写"> <Form @@ -116,26 +118,35 @@ const RequestRewriteView: React.FC<Props> = ({ data, form, disabled, onChange }) > <Input disabled={disabled} /> </Form.Item> - <Form.Item - label="连接超时" - name={['timeout', 'connect']} - rules={[{ required: true, message: '连接超时时间' }]} - > - <InputNumber disabled={disabled} defaultValue={30000} /> ms + <Form.Item label="连接超时"> + <Form.Item + name={['timeout', 'connect']} + noStyle + rules={[{ required: true, message: '请输入连接超时时间' }]} + > + <InputNumber disabled={disabled} /> + </Form.Item> + {renderTimeUnit()} </Form.Item> - <Form.Item - label="发送超时" - name={['timeout', 'send']} - rules={[{ required: true, message: '发送超时时间' }]} - > - <InputNumber disabled={disabled} defaultValue={30000} /> ms + <Form.Item label="发送超时"> + <Form.Item + name={['timeout', 'send']} + noStyle + rules={[{ required: true, message: '请输入发送超时时间' }]} + > + <InputNumber disabled={disabled} /> + </Form.Item> + {renderTimeUnit()} </Form.Item> - <Form.Item - label="接收超时" - name={['timeout', 'read']} - rules={[{ required: true, message: '接收超时时间' }]} - > - <InputNumber disabled={disabled} defaultValue={30000} /> ms + <Form.Item label="接收超时"> + <Form.Item + name={['timeout', 'read']} + noStyle + rules={[{ required: true, message: '请输入接收超时时间' }]} + > + <InputNumber disabled={disabled} /> + </Form.Item> + {renderTimeUnit()} </Form.Item> </Form> </PanelSection> diff --git a/src/pages/Routes/constants.ts b/src/pages/Routes/constants.ts index 88387e1..b7d9574 100644 --- a/src/pages/Routes/constants.ts +++ b/src/pages/Routes/constants.ts @@ -1,4 +1,12 @@ -export const HTTP_METHOD_OPTION_LIST = ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'PATCH']; +export const HTTP_METHOD_OPTION_LIST: RouteModule.HttpMethod[] = [ + 'GET', + 'HEAD', + 'POST', + 'PUT', + 'DELETE', + 'OPTIONS', + 'PATCH', +]; export const FORM_ITEM_LAYOUT = { labelCol: { @@ -19,9 +27,10 @@ export const FORM_ITEM_WITHOUT_LABEL = { export const DEFAULT_STEP_1_DATA: RouteModule.Step1Data = { name: '', protocols: ['HTTP', 'HTTPS'], + WebSocket: false, hosts: [''], paths: [], - httpMethods: [], + httpMethods: HTTP_METHOD_OPTION_LIST, advancedMatchingRules: [], }; diff --git a/src/pages/Routes/typing.d.ts b/src/pages/Routes/typing.d.ts index 7be88b2..a50f0fe 100644 --- a/src/pages/Routes/typing.d.ts +++ b/src/pages/Routes/typing.d.ts @@ -13,6 +13,7 @@ declare namespace RouteModule { type Step1Data = { name: string; protocols: RequestProtocol[]; + WebSocket: boolean; hosts: string[]; paths: string[]; httpMethods: HttpMethod[];