Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use selector to choose methods #1082

Merged
merged 2 commits into from
Dec 21, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 any).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