Skip to content

Commit

Permalink
feat: use selector to choose methods (#1082)
Browse files Browse the repository at this point in the history
* fix: "method" can be null value

* Update RequestConfigView.tsx

Co-authored-by: 琚致远 <[email protected]>
  • Loading branch information
guoqqqi and juzhiyuan authored Dec 21, 2020
1 parent 565de4d commit e23e95e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
32 changes: 22 additions & 10 deletions web/src/pages/Route/components/Step1/RequestConfigView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
import React from 'react';
import Form from 'antd/es/form';
import { Checkbox, Button, Input, Select, Row, Col, InputNumber } from 'antd';
import { Button, Input, Select, Row, Col, InputNumber } from 'antd';
import { PlusOutlined, MinusCircleOutlined } from '@ant-design/icons';
import { useIntl } from 'umi';
import { PanelSection } from '@api7-dashboard/ui';
Expand Down Expand Up @@ -259,16 +259,28 @@ const RequestConfigView: React.FC<RouteModule.Step1PassProps> = ({
<Form.Item
label={formatMessage({ id: 'page.route.form.itemLabel.httpMethod' })}
name="methods"
rules={[
{
required: true,
message: `${formatMessage({ id: 'component.global.pleaseChoose' })} ${formatMessage({
id: 'page.route.form.itemLabel.httpMethod',
})}`,
},
]}
>
<Checkbox.Group options={HTTP_METHOD_OPTION_LIST} disabled={disabled} />
<Select
mode="multiple"
style={{ width: '100%' }}
optionLabelProp="label"
disabled={disabled}
onChange={(value) => {
if ((value as string[]).includes('ALL')) {
form.setFieldsValue({
methods: ['ALL'],
});
}
}}
>
{['ALL'].concat(HTTP_METHOD_OPTION_LIST).map((item) => {
return (
<Select.Option key={item} value={item}>
{item}
</Select.Option>
);
})}
</Select>
</Form.Item>
<Form.Item
label={formatMessage({ id: 'page.route.form.itemLabel.priority' })}
Expand Down
7 changes: 5 additions & 2 deletions web/src/pages/Route/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ export const transformStepData = ({
}
return [key, operator, value];
}),
// @ts-ignore
methods: form1Data.methods.includes("ALL") ? [] : form1Data.methods
};

if (Object.keys(redirect).length === 0 || redirect.http_to_https) {
Expand Down Expand Up @@ -135,7 +137,7 @@ export const transformRouteData = (data: RouteModule.Body) => {
const {
name,
desc,
methods,
methods = [],
uris,
uri,
hosts,
Expand All @@ -154,7 +156,8 @@ export const transformRouteData = (data: RouteModule.Body) => {
hosts: hosts || (host && [host]) || [''],
uris: uris || (uri && [uri]) || [],
remote_addrs: remote_addrs || [''],
methods,
// @ts-ignore
methods: methods.length ? methods : ["ALL"],
priority,
};

Expand Down

0 comments on commit e23e95e

Please sign in to comment.