Skip to content

Commit abefe97

Browse files
authored
chore: Create route form optimization (#2336)
1 parent 6d2445e commit abefe97

File tree

6 files changed

+30
-12
lines changed

6 files changed

+30
-12
lines changed

web/cypress/integration/route/create-route-with-search-service-and-set-priority.spec.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ context('Create Route with search service name', () => {
3232
serviceSelector: '[title="None"]',
3333
upstreamSelector: '#upstream_id',
3434
deleteAlert: '.ant-modal-body',
35-
drawer: '.ant-drawer-content',
3635
};
3736

3837
const data = {
@@ -52,7 +51,7 @@ context('Create Route with search service name', () => {
5251
deleteRouteSuccess: 'Delete Route Successfully',
5352
routeName: 'route_test1',
5453
searchServiceName: 'service_test2',
55-
upstreamName: 'None',
54+
upstreamName: 'None (Only available when binding the service)',
5655
};
5756

5857
beforeEach(() => {
@@ -101,12 +100,15 @@ context('Create Route with search service name', () => {
101100

102101
// set name
103102
cy.get(selector.name).type(data.routeName);
104-
cy.get(selector.serviceSelector).type(data.serviceName2 + '\n');
103+
cy.get(selector.serviceSelector).type(`${data.serviceName2}\n`);
105104
// set priority
106105
cy.get(selector.priority).type(data.priority);
107106
cy.contains('Next').click();
108107
// select upstream with None
109-
cy.get(selector.upstreamSelector).type(data.upstreamName + '\n');
108+
cy.get('.ant-select-selector')
109+
.find(selector.upstreamSelector)
110+
.type(`${data.upstreamName}\n`, { force: true });
111+
110112
cy.contains('Next').click();
111113
cy.contains('Next').click();
112114
cy.contains('Submit').click();
@@ -117,7 +119,7 @@ context('Create Route with search service name', () => {
117119
let serviceUuid = '';
118120
cy.visit('/');
119121
cy.contains('Service').click();
120-
cy.get(selector.name).type(data.serviceName2 + '\n');
122+
cy.get(selector.name).type(`${data.serviceName2}\n`);
121123
cy.contains(data.serviceName2)
122124
.siblings()
123125
.first()
@@ -126,7 +128,7 @@ context('Create Route with search service name', () => {
126128
});
127129
cy.visit('/');
128130
cy.contains('Route').click();
129-
cy.get(selector.name).type(data.routeName + '\n');
131+
cy.get(selector.name).type(`${data.routeName}\n`);
130132
cy.contains(data.routeName).siblings().contains('More').click();
131133
cy.contains('View').click();
132134
cy.get(selector.drawer).should('be.visible');
@@ -139,7 +141,7 @@ context('Create Route with search service name', () => {
139141
it('should delete the route and services', function () {
140142
cy.visit('/');
141143
cy.contains('Route').click();
142-
cy.get(selector.name).type(data.routeName + '\n');
144+
cy.get(selector.name).type(`${data.routeName}\n`);
143145
cy.contains(data.routeName).siblings().contains('More').click();
144146
cy.contains('Delete').click();
145147
cy.get(selector.deleteAlert)

web/src/components/Upstream/UpstreamForm.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
import { Divider, Form, notification, Switch } from 'antd';
1818
import React, { useState, forwardRef, useImperativeHandle, useEffect } from 'react';
19-
import { useIntl } from 'umi';
19+
import { useIntl, useLocation } from 'umi';
2020
import type { FormInstance } from 'antd/es/form';
2121

2222
import PanelSection from '@/components/PanelSection';
@@ -67,6 +67,7 @@ const UpstreamForm: React.FC<Props> = forwardRef(
6767
},
6868
ref,
6969
) => {
70+
const location = useLocation();
7071
const { formatMessage } = useIntl();
7172
const [readonly, setReadonly] = useState(false);
7273
const [hiddenForm, setHiddenForm] = useState(false);
@@ -281,7 +282,13 @@ const UpstreamForm: React.FC<Props> = forwardRef(
281282
};
282283

283284
return (
284-
<Form form={form} labelCol={{ span: 3 }}>
285+
<Form
286+
initialValues={{
287+
upstream_id: !required && location.pathname === '/routes/create' ? 'None' : 'Custom',
288+
}}
289+
form={form}
290+
labelCol={{ span: 3 }}
291+
>
285292
{showSelector && (
286293
<UpstreamSelector
287294
list={list}

web/src/components/Upstream/components/UpstreamSelector.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
import React from 'react';
1818
import { Form, Select } from 'antd';
19-
import { useIntl } from 'umi';
19+
import { useIntl, useLocation } from 'umi';
2020

2121
type Upstream = {
2222
name?: string;
@@ -32,6 +32,7 @@ type Props = {
3232

3333
const UpstreamSelector: React.FC<Props> = ({ onChange, list = [], disabled, required }) => {
3434
const { formatMessage } = useIntl();
35+
const location = useLocation();
3536

3637
return (
3738
<Form.Item
@@ -50,7 +51,11 @@ const UpstreamSelector: React.FC<Props> = ({ onChange, list = [], disabled, requ
5051
</Select.Option>
5152
{[
5253
{
53-
name: formatMessage({ id: 'page.upstream.step.select.upstream.select.option' }),
54+
name: formatMessage({
55+
id: `page.upstream.step.select.upstream.select.option${
56+
!required && location.pathname === '/routes/create' ? '.serviceSelected' : ''
57+
}`,
58+
}),
5459
id: 'Custom',
5560
},
5661
...list,

web/src/components/Upstream/locales/en-US.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export default {
147147
'component.upstream.fields.checks.passive.unhealthy.timeouts.tooltip':
148148
'Number of timeouts in proxied traffic to consider a target unhealthy, as observed by passive health checks.',
149149

150-
'component.upstream.other.none': 'None',
150+
'component.upstream.other.none': 'None (Only available when binding the service)',
151151
'component.upstream.other.pass_host-with-multiple-nodes.title':
152152
'Please check the target node configuration',
153153
'component.upstream.other.pass_host-with-multiple-nodes':

web/src/pages/Upstream/locales/en-US.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
export default {
1818
'page.upstream.step.select.upstream': 'Select Upstream',
1919
'page.upstream.step.select.upstream.select.option': 'Custom',
20+
'page.upstream.step.select.upstream.select.option.serviceSelected':
21+
'Custom (The current configuration will override the bound service)',
2022
'page.upstream.step.select.upstream.select.none': 'None',
2123
'page.upstream.step.backend.server.domain.or.ip': 'Backend Server Host/IP',
2224
'page.upstream.form.item-label.node.domain.or.ip': 'Targets',

web/src/pages/Upstream/locales/zh-CN.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
export default {
1818
'page.upstream.step.select.upstream': '选择上游服务',
1919
'page.upstream.step.select.upstream.select.option': '手动填写',
20+
'page.upstream.step.select.upstream.select.option.serviceSelected':
21+
'手动填写(当前配置将会覆盖已绑定的服务)',
2022
'page.upstream.step.select.upstream.select.none': '无',
2123
'page.upstream.step.backend.server.domain.or.ip': '后端服务域名或 IP',
2224
'page.upstream.form.item-label.node.domain.or.ip': '目标节点',

0 commit comments

Comments
 (0)