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:Support duplicate one existing Route #1558

Merged
merged 6 commits into from
Apr 2, 2021
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
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,11 @@ web/.nyc_output
web/coverage
web/cypress/screenshots/
web/cypress/videos/
web/cypress/downloads/
web/cypress/screenshots/
web/cypress/videos/

# vim
*.swp
*.swo

4 changes: 4 additions & 0 deletions web/config/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ const routes = [
path: '/routes/:rid/edit',
component: './Route/Create',
},
{
path: '/routes/:rid/duplicate',
juzhiyuan marked this conversation as resolved.
Show resolved Hide resolved
component: './Route/Create',
},
{
path: '/ssl/:id/edit',
component: './SSL/Create',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
context('Create and Delete Route', () => {
const name = `routeName${new Date().valueOf()}`;
const newName = `newName${new Date().valueOf()}`;
const duplicateNewName = `duplicateName${new Date().valueOf()}`;
const sleepTime = 100;
const timeout = 5000;

Expand Down Expand Up @@ -153,12 +154,46 @@ context('Create and Delete Route', () => {
});
});

it('should delete the route', function () {
cy.visit('/routes/list');

it('should duplicate the route', function () {
cy.visit('/');
cy.contains('Route').click();

cy.get(this.domSelector.nameSelector).type(newName);
cy.contains('Search').click();
cy.contains(newName).siblings().contains('Delete').click();
cy.contains('button', 'Confirm').click();
cy.get(this.domSelector.notification).should('contain', this.data.deleteRouteSuccess);
cy.contains(newName).siblings().contains('Duplicate').click();

cy.get(this.domSelector.name).clear().type(duplicateNewName);
cy.get(this.domSelector.description).clear().type(this.data.description2);
cy.contains('Next').click();
cy.contains('Next').click();
cy.contains('Next').click();
cy.contains('Submit').click();
cy.contains(this.data.submitSuccess);
cy.contains('Goto List').click();
cy.url().should('contains', 'routes/list');
cy.contains(duplicateNewName).siblings().should('contain', this.data.description2);

// test view
cy.contains(duplicateNewName).siblings().contains('View').click();
cy.get(this.domSelector.drawer).should('be.visible');

cy.get(this.domSelector.codemirrorScroll).within(() => {
cy.contains('upstream').should("exist");
cy.contains(duplicateNewName).should('exist');
});
});

it('should delete the route', function () {
cy.visit('/routes/list');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LiteSun Do we need to visit this page by clicking Sidebar Menu?

const { domSelector, data } = this;
const routeNames = [newName, duplicateNewName];
routeNames.forEach(function (routeName) {
cy.get(domSelector.name).clear().type(routeName);
cy.contains('Search').click();
cy.contains(routeName).siblings().contains('Delete').click();
cy.contains('button', 'Confirm').click();
cy.get(domSelector.notification).should('contain', data.deleteRouteSuccess);
LiteSun marked this conversation as resolved.
Show resolved Hide resolved
});
});
});
1 change: 1 addition & 0 deletions web/src/locales/en-US/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default {
'component.global.save': 'Save',
'component.global.edit': 'Configure',
'component.global.view': 'View',
'component.global.duplicate': 'Duplicate',
'component.global.manage': 'Manage',
'component.global.update': 'Update',
'component.global.get': 'Get',
Expand Down
1 change: 1 addition & 0 deletions web/src/locales/zh-CN/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default {
'component.global.save': '保存',
'component.global.edit': '编辑',
'component.global.view': '查看',
'component.global.duplicate': '复制',
'component.global.manage': '管理',
'component.global.update': '更新',
'component.global.get': '获取',
Expand Down
10 changes: 5 additions & 5 deletions web/src/pages/Route/Create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const Page: React.FC<Props> = (props) => {
};

useEffect(() => {
if (props.route.path.indexOf('edit') !== -1) {
if (props.route.path.indexOf('edit') !== -1 || props.route.path.indexOf('duplicate') !== -1) {
setupRoute(props.match.params.rid);
} else {
onReset();
Expand Down Expand Up @@ -233,7 +233,7 @@ const Page: React.FC<Props> = (props) => {
redirectOption === 'forceHttps' && filterHosts.length !== 0
? checkHostWithSSL(hosts)
: Promise.resolve(),
checkUniqueName(value.name, (props as any).match.params.rid || ''),
checkUniqueName(value.name, props.route.path.indexOf('edit') > 0 ? (props as any).match.params.rid : ''),
]).then(() => {
setStep(nextStep);
});
Expand Down Expand Up @@ -269,9 +269,9 @@ const Page: React.FC<Props> = (props) => {
return (
<>
<PageHeaderWrapper
title={(props as any).match.params.rid
? formatMessage({ id: 'page.route.editRoute' })
: formatMessage({ id: 'page.route.createRoute' })}
title={`${
formatMessage({ id: `component.global.${props.route.path.split('/').slice(-1)[0]}`})
} ${formatMessage({ id: 'menu.routes' })}`}
>
<Card bordered={false}>
<Steps current={step - 1} className={styles.steps}>
Expand Down
3 changes: 3 additions & 0 deletions web/src/pages/Route/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,9 @@ const Page: React.FC = () => {
}}>
{formatMessage({ id: 'component.global.view' })}
</Button>
<Button type="primary" onClick={() => history.push(`/routes/${record.id}/duplicate`)}>
juzhiyuan marked this conversation as resolved.
Show resolved Hide resolved
{formatMessage({ id: 'component.global.duplicate' })}
</Button>
<Popconfirm
title={formatMessage({ id: 'component.global.popconfirm.title.delete' })}
onConfirm={() => {
Expand Down