forked from apache/apisix-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
441 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,297 @@ | ||
/* | ||
* 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, { useEffect, useState } from 'react'; | ||
import Form from 'antd/es/form'; | ||
import { Button, Input, Radio, Row, Col } from 'antd'; | ||
import { PlusOutlined, MinusCircleOutlined } from '@ant-design/icons'; | ||
import { useIntl } from 'umi'; | ||
import { PanelSection } from '@api7-dashboard/ui'; | ||
|
||
import { | ||
FORM_ITEM_LAYOUT, | ||
FORM_ITEM_WITHOUT_LABEL, | ||
} from '@/pages/Route/constants'; | ||
|
||
const ProxyRewrite: React.FC<RouteModule.Step1PassProps> = ({ form, disabled }) => { | ||
const { formatMessage } = useIntl(); | ||
enum ShcemeRewrite { | ||
KEEP = 'keep', | ||
HTTP = 'http', | ||
HTTPS = 'https', | ||
} | ||
enum URIRewriteType { | ||
KEEP = 0, | ||
STATIC, | ||
REGEXP, | ||
} | ||
enum HostRewriteType { | ||
KEEP = 0, | ||
REWRITE, | ||
} | ||
const [uriRewrite, setUriRewrite] = useState<URIRewriteType>(URIRewriteType.KEEP); | ||
const [hostRewrite, setHostRewrite] = useState<HostRewriteType>(HostRewriteType.KEEP); | ||
|
||
const getUriRewriteItems = () => { | ||
switch (uriRewrite) { | ||
case URIRewriteType.STATIC: | ||
return ( | ||
<Form.Item | ||
label={formatMessage({ id: 'page.route.form.itemLabel.newPath' })} | ||
name={['proxyRewrite', 'uri']} | ||
rules={[ | ||
{ | ||
required: true, | ||
message: `${formatMessage({ id: 'component.global.pleaseEnter' })} ${formatMessage({ | ||
id: 'page.route.form.itemLabel.newPath', | ||
})}`, | ||
}, | ||
]} | ||
> | ||
<Input | ||
placeholder={`${formatMessage({ | ||
id: 'component.global.pleaseEnter', | ||
})} ${formatMessage({ id: 'page.route.form.itemLabel.newPath' })}`} | ||
disabled={disabled} | ||
/> | ||
</Form.Item> | ||
); | ||
case URIRewriteType.REGEXP: | ||
return ( | ||
<Form.List | ||
name={['proxyRewrite', 'regex_uri']} | ||
initialValue={['', '']} | ||
> | ||
{(fields) => | ||
fields.map((field, index) => { | ||
switch (index) { | ||
case 0: | ||
return ( | ||
<Form.Item | ||
label={formatMessage({ id: 'page.route.form.itemLabel.regx' })} | ||
name={field.name} | ||
rules={[ | ||
{ | ||
required: true, | ||
message: `${formatMessage({ | ||
id: 'component.global.pleaseEnter', | ||
})} ${formatMessage({ id: 'page.route.form.itemLabel.regx' })}`, | ||
}, | ||
]} | ||
> | ||
<Input | ||
placeholder={`${formatMessage({ | ||
id: 'component.global.pleaseEnter', | ||
})} ${formatMessage({ id: 'page.route.form.itemLabel.regx' })}`} | ||
disabled={disabled} | ||
/> | ||
</Form.Item> | ||
); | ||
case 1: | ||
return ( | ||
<Form.Item | ||
label={formatMessage({ id: 'page.route.form.itemLabel.template' })} | ||
name={field.name} | ||
rules={[ | ||
{ | ||
required: true, | ||
message: `${formatMessage({ | ||
id: 'component.global.pleaseEnter', | ||
})} ${formatMessage({ id: 'page.route.form.itemLabel.template' })}`, | ||
}, | ||
]} | ||
> | ||
<Input | ||
placeholder={`${formatMessage({ | ||
id: 'component.global.pleaseEnter', | ||
})} ${formatMessage({ id: 'page.route.form.itemLabel.template' })}`} | ||
disabled={disabled} | ||
/> | ||
</Form.Item> | ||
); | ||
default: | ||
return null; | ||
} | ||
}) | ||
} | ||
</Form.List> | ||
); | ||
case URIRewriteType.REGEXP: | ||
default: | ||
return null; | ||
} | ||
}; | ||
|
||
const getHostRewriteItems = () => { | ||
switch (hostRewrite) { | ||
case HostRewriteType.REWRITE: | ||
return ( | ||
<Form.Item | ||
label={formatMessage({ id: 'page.route.form.itemLabel.newHost' })} | ||
name={['proxyRewrite', 'host']} | ||
rules={[ | ||
{ | ||
required: true, | ||
message: `${formatMessage({ id: 'component.global.pleaseEnter' })} ${formatMessage({ | ||
id: 'page.route.form.itemLabel.newHost', | ||
})}`, | ||
}, | ||
]} | ||
> | ||
<Input | ||
placeholder={`${formatMessage({ | ||
id: 'component.global.pleaseEnter', | ||
})} ${formatMessage({ id: 'page.route.form.itemLabel.newHost' })}`} | ||
disabled={disabled} | ||
/> | ||
</Form.Item> | ||
); | ||
case HostRewriteType.KEEP: | ||
default: | ||
return null; | ||
} | ||
}; | ||
|
||
useEffect(() => {}, []); | ||
|
||
return ( | ||
<PanelSection title={formatMessage({ id: 'page.route.panelSection.title.requestOverride' })}> | ||
<Form.Item | ||
label={formatMessage({ id: 'page.route.form.itemLabel.scheme' })} | ||
name={['proxyRewrite', 'scheme']} | ||
> | ||
<Radio.Group disabled={disabled}> | ||
<Radio value={ShcemeRewrite.KEEP}> | ||
{formatMessage({ id: 'page.route.radio.staySame' })} | ||
</Radio> | ||
<Radio value={ShcemeRewrite.HTTP}>{(ShcemeRewrite.HTTP).toLocaleUpperCase()}</Radio> | ||
<Radio value={ShcemeRewrite.HTTPS}>{(ShcemeRewrite.HTTPS).toLocaleUpperCase()}</Radio> | ||
</Radio.Group> | ||
</Form.Item> | ||
<Form.Item | ||
label={formatMessage({ id: 'page.route.form.itemLabel.uriRewriteType' })} | ||
name='URIRewriteType' | ||
> | ||
<Radio.Group | ||
onChange={(e) => { | ||
setUriRewrite(e.target.value); | ||
}} | ||
disabled={disabled} | ||
> | ||
<Radio value={URIRewriteType.KEEP}> | ||
{formatMessage({ id: 'page.route.radio.staySame' })} | ||
</Radio> | ||
<Radio value={URIRewriteType.STATIC}> | ||
{formatMessage({ id: 'page.route.radio.static' })} | ||
</Radio> | ||
<Radio value={URIRewriteType.REGEXP}> | ||
{formatMessage({ id: 'page.route.radio.regx' })} | ||
</Radio> | ||
</Radio.Group> | ||
</Form.Item> | ||
{getUriRewriteItems()} | ||
|
||
<Form.Item | ||
label={formatMessage({ id: 'page.route.form.itemLabel.hostRewriteType' })} | ||
name='hostRewriteType' | ||
> | ||
<Radio.Group | ||
onChange={(e) => { | ||
setHostRewrite(e.target.value); | ||
}} | ||
disabled={disabled} | ||
> | ||
<Radio value={HostRewriteType.KEEP}> | ||
{formatMessage({ id: 'page.route.radio.staySame' })} | ||
</Radio> | ||
<Radio value={HostRewriteType.REWRITE}> | ||
{formatMessage({ id: 'page.route.radio.static' })} | ||
</Radio> | ||
</Radio.Group> | ||
</Form.Item> | ||
{getHostRewriteItems()} | ||
|
||
<Form.List | ||
name={['proxyRewrite', 'kvHeaders']} | ||
initialValue={[{ | ||
|
||
}]} | ||
> | ||
{(fields, { add, remove }, { errors }) => ( | ||
<> | ||
{fields.map((field, index) => ( | ||
<Form.Item | ||
{...(index === 0 ? FORM_ITEM_LAYOUT : FORM_ITEM_WITHOUT_LABEL)} | ||
label={ | ||
index === 0 | ||
? formatMessage({ id: 'page.route.form.itemLabel.headerRewrite' }) | ||
: '' | ||
} | ||
key={field.key} | ||
> | ||
<Row gutter={24} key={field.name}> | ||
<Col span={11}> | ||
<Form.Item | ||
name={[field.name, 'key']} | ||
fieldKey={[field.fieldKey, 'key']} | ||
noStyle | ||
> | ||
<Input | ||
placeholder={`${formatMessage({ | ||
id: 'component.global.pleaseEnter', | ||
})}${formatMessage({ id: 'page.route.parameterName' })}`} | ||
disabled={disabled} | ||
/> | ||
</Form.Item> | ||
</Col> | ||
<Col span={11}> | ||
<Form.Item | ||
name={[field.name, 'value']} | ||
fieldKey={[field.fieldKey, 'value']} | ||
noStyle | ||
> | ||
<Input | ||
placeholder={`${formatMessage({ | ||
id: 'component.global.pleaseEnter', | ||
})}${formatMessage({ id: 'page.route.value' })}`} | ||
disabled={disabled} | ||
/> | ||
</Form.Item> | ||
</Col> | ||
{!disabled && fields.length > 1 && ( | ||
<Col> | ||
<MinusCircleOutlined | ||
className="dynamic-delete-button" | ||
onClick={() => remove(field.name)} | ||
/> | ||
</Col> | ||
)} | ||
</Row> | ||
</Form.Item> | ||
))} | ||
<Form.Item {...FORM_ITEM_WITHOUT_LABEL}> | ||
<Button type="dashed" disabled={disabled} onClick={() => add()} icon={<PlusOutlined />}> | ||
{formatMessage({ id: 'component.global.create' })} | ||
</Button> | ||
</Form.Item> | ||
</> | ||
)} | ||
</Form.List> | ||
</PanelSection> | ||
); | ||
}; | ||
|
||
export default ProxyRewrite; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.