Skip to content

Commit

Permalink
feat(plugin): allowing limit-conn to dynamically adapt to the BE rules (
Browse files Browse the repository at this point in the history
  • Loading branch information
wmdmomo authored Aug 10, 2021
1 parent 1cb7cb0 commit 930e47a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
28 changes: 10 additions & 18 deletions web/src/components/Plugin/UI/limit-conn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { useIntl } from 'umi';

type Props = {
form: FormInstance;
schema: Record<string, any> | undefined;
ref?: any;
};

Expand All @@ -33,8 +34,9 @@ const FORM_ITEM_LAYOUT = {
},
};

const LimitConn: React.FC<Props> = ({ form }) => {
const LimitConn: React.FC<Props> = ({ form, schema }) => {
const { formatMessage } = useIntl();
const propertires = schema?.properties
return (
<Form form={form} {...FORM_ITEM_LAYOUT}>
<Form.Item
Expand All @@ -43,15 +45,15 @@ const LimitConn: React.FC<Props> = ({ form }) => {
name="conn"
tooltip={formatMessage({ id: 'component.pluginForm.limit-conn.conn.tooltip' })}
>
<InputNumber min={1} required />
<InputNumber min={propertires.conn.exclusiveMinimum} required />
</Form.Item>
<Form.Item
label="burst"
required
name="burst"
tooltip={formatMessage({ id: 'component.pluginForm.limit-conn.burst.tooltip' })}
>
<InputNumber min={0} required />
<InputNumber min={propertires.burst.minimum} required />
</Form.Item>
<Form.Item
label="default_conn_delay"
Expand All @@ -61,7 +63,7 @@ const LimitConn: React.FC<Props> = ({ form }) => {
id: 'component.pluginForm.limit-conn.default_conn_delay.tooltip',
})}
>
<InputNumber step={0.001} min={0.001} required />
<InputNumber step={0.001} min={propertires.default_conn_delay.exclusiveMinimum} required />
</Form.Item>

<Form.Item
Expand All @@ -71,29 +73,19 @@ const LimitConn: React.FC<Props> = ({ form }) => {
tooltip={formatMessage({ id: 'component.pluginForm.limit-conn.key.tooltip' })}
>
<Select>
{[
'remote_addr',
'server_addr',
'http_x_real_ip',
'http_x_forwarded_for',
'consumer_name',
].map((item) => {
return (
<Select.Option value={item} key={item}>
{item}
</Select.Option>
);
{propertires.key.enum.map((item: string) => {
return <Select.Option value={item} key={item}>{item}</Select.Option>
})}
</Select>
</Form.Item>

<Form.Item
label="rejected_code"
name="rejected_code"
initialValue={503}
initialValue={propertires.rejected_code.default}
tooltip={formatMessage({ id: 'component.pluginForm.limit-conn.rejected_code.tooltip' })}
>
<InputNumber min={200} max={599} required />
<InputNumber min={propertires.rejected_code.minimum} max={propertires.rejected_code.maximum} required />
</Form.Item>
</Form>
);
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/Plugin/UI/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const PluginForm: React.FC<Props> = ({ name, schema, renderForm, form })
case 'proxy-mirror':
return <ProxyMirror form={form} />;
case 'limit-conn':
return <LimitConn form={form} />;
return <LimitConn form={form} schema={schema}/>
case 'referer-restriction':
return <RefererRestriction form={form} />;
default:
Expand Down

0 comments on commit 930e47a

Please sign in to comment.