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

chore: Create route form optimization #2336

Merged
merged 4 commits into from
Feb 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ context('Create Route with search service name', () => {
serviceSelector: '[title="None"]',
upstreamSelector: '#upstream_id',
deleteAlert: '.ant-modal-body',
drawer: '.ant-drawer-content',
};

const data = {
Expand All @@ -52,7 +51,7 @@ context('Create Route with search service name', () => {
deleteRouteSuccess: 'Delete Route Successfully',
routeName: 'route_test1',
searchServiceName: 'service_test2',
upstreamName: 'None',
upstreamName: 'None (Only available when binding the service)',
};

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

// set name
cy.get(selector.name).type(data.routeName);
cy.get(selector.serviceSelector).type(data.serviceName2 + '\n');
cy.get(selector.serviceSelector).type(`${data.serviceName2}\n`);
// set priority
cy.get(selector.priority).type(data.priority);
cy.contains('Next').click();
// select upstream with None
cy.get(selector.upstreamSelector).type(data.upstreamName + '\n');
cy.get('.ant-select-selector')
.find(selector.upstreamSelector)
.type(`${data.upstreamName}\n`, { force: true });

cy.contains('Next').click();
cy.contains('Next').click();
cy.contains('Submit').click();
Expand All @@ -117,7 +119,7 @@ context('Create Route with search service name', () => {
let serviceUuid = '';
cy.visit('/');
cy.contains('Service').click();
cy.get(selector.name).type(data.serviceName2 + '\n');
cy.get(selector.name).type(`${data.serviceName2}\n`);
cy.contains(data.serviceName2)
.siblings()
.first()
Expand All @@ -126,7 +128,7 @@ context('Create Route with search service name', () => {
});
cy.visit('/');
cy.contains('Route').click();
cy.get(selector.name).type(data.routeName + '\n');
cy.get(selector.name).type(`${data.routeName}\n`);
cy.contains(data.routeName).siblings().contains('More').click();
cy.contains('View').click();
cy.get(selector.drawer).should('be.visible');
Expand All @@ -139,7 +141,7 @@ context('Create Route with search service name', () => {
it('should delete the route and services', function () {
cy.visit('/');
cy.contains('Route').click();
cy.get(selector.name).type(data.routeName + '\n');
cy.get(selector.name).type(`${data.routeName}\n`);
cy.contains(data.routeName).siblings().contains('More').click();
cy.contains('Delete').click();
cy.get(selector.deleteAlert)
Expand Down
11 changes: 9 additions & 2 deletions web/src/components/Upstream/UpstreamForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
import { Divider, Form, notification, Switch } from 'antd';
import React, { useState, forwardRef, useImperativeHandle, useEffect } from 'react';
import { useIntl } from 'umi';
import { useIntl, useLocation } from 'umi';
import type { FormInstance } from 'antd/es/form';

import PanelSection from '@/components/PanelSection';
Expand Down Expand Up @@ -67,6 +67,7 @@ const UpstreamForm: React.FC<Props> = forwardRef(
},
ref,
) => {
const location = useLocation();
const { formatMessage } = useIntl();
const [readonly, setReadonly] = useState(false);
const [hiddenForm, setHiddenForm] = useState(false);
Expand Down Expand Up @@ -281,7 +282,13 @@ const UpstreamForm: React.FC<Props> = forwardRef(
};

return (
<Form form={form} labelCol={{ span: 3 }}>
<Form
initialValues={{
upstream_id: !required && location.pathname === '/routes/create' ? 'None' : 'Custom',
}}
form={form}
labelCol={{ span: 3 }}
>
{showSelector && (
<UpstreamSelector
list={list}
Expand Down
9 changes: 7 additions & 2 deletions web/src/components/Upstream/components/UpstreamSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
import React from 'react';
import { Form, Select } from 'antd';
import { useIntl } from 'umi';
import { useIntl, useLocation } from 'umi';

type Upstream = {
name?: string;
Expand All @@ -32,6 +32,7 @@ type Props = {

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

return (
<Form.Item
Expand All @@ -50,7 +51,11 @@ const UpstreamSelector: React.FC<Props> = ({ onChange, list = [], disabled, requ
</Select.Option>
{[
{
name: formatMessage({ id: 'page.upstream.step.select.upstream.select.option' }),
name: formatMessage({
id: `page.upstream.step.select.upstream.select.option${
!required && location.pathname === '/routes/create' ? '.serviceSelected' : ''
}`,
}),
id: 'Custom',
},
...list,
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/Upstream/locales/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export default {
'component.upstream.fields.checks.passive.unhealthy.timeouts.tooltip':
'Number of timeouts in proxied traffic to consider a target unhealthy, as observed by passive health checks.',

'component.upstream.other.none': 'None',
'component.upstream.other.none': 'None (Only available when binding the service)',
'component.upstream.other.pass_host-with-multiple-nodes.title':
'Please check the target node configuration',
'component.upstream.other.pass_host-with-multiple-nodes':
Expand Down
2 changes: 2 additions & 0 deletions web/src/pages/Upstream/locales/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
export default {
'page.upstream.step.select.upstream': 'Select Upstream',
'page.upstream.step.select.upstream.select.option': 'Custom',
'page.upstream.step.select.upstream.select.option.serviceSelected':
'Custom (The current configuration will override the bound service)',
'page.upstream.step.select.upstream.select.none': 'None',
'page.upstream.step.backend.server.domain.or.ip': 'Backend Server Host/IP',
'page.upstream.form.item-label.node.domain.or.ip': 'Targets',
Expand Down
2 changes: 2 additions & 0 deletions web/src/pages/Upstream/locales/zh-CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
export default {
'page.upstream.step.select.upstream': '选择上游服务',
'page.upstream.step.select.upstream.select.option': '手动填写',
'page.upstream.step.select.upstream.select.option.serviceSelected':
'手动填写(当前配置将会覆盖已绑定的服务)',
'page.upstream.step.select.upstream.select.none': '无',
'page.upstream.step.backend.server.domain.or.ip': '后端服务域名或 IP',
'page.upstream.form.item-label.node.domain.or.ip': '目标节点',
Expand Down