Merge "fix: support the same port if different protocol"

This commit is contained in:
Zuul 2022-07-21 08:20:57 +00:00 committed by Gerrit Code Review
commit 8bda065853
2 changed files with 18 additions and 5 deletions

View File

@ -131,6 +131,10 @@ export class CreateDNAT extends ModalAction {
}); });
}; };
get nameForStateUpdate() {
return ['protocol'];
}
get formItems() { get formItems() {
const { fixed_ip_address = { selectedRows: [] } } = this.state; const { fixed_ip_address = { selectedRows: [] } } = this.state;
const ret = [ const ret = [
@ -169,8 +173,10 @@ export class CreateDNAT extends ModalAction {
new Error(`${t('Please input')} ${t('External Port')}`) new Error(`${t('Please input')} ${t('External Port')}`)
); );
} }
const { alreadyUsedPorts } = this.state; const { alreadyUsedPorts, protocol } = this.state;
const flag = alreadyUsedPorts.some((pf) => pf.external_port === val); const flag = alreadyUsedPorts.some(
(pf) => pf.external_port === val && pf.protocol === protocol
);
if (flag) { if (flag) {
return Promise.reject( return Promise.reject(
new Error( new Error(
@ -180,6 +186,7 @@ export class CreateDNAT extends ModalAction {
} }
return Promise.resolve(true); return Promise.resolve(true);
}, },
dependencies: ['protocol'],
}, },
{ {
name: 'internal_port', name: 'internal_port',
@ -202,13 +209,14 @@ export class CreateDNAT extends ModalAction {
const internal_ip_address = const internal_ip_address =
formData.fixed_ip_address.selectedRows[0].fixed_ip_address; formData.fixed_ip_address.selectedRows[0].fixed_ip_address;
const internal_port_id = formData.virtual_adapter.selectedRows[0].id; const internal_port_id = formData.virtual_adapter.selectedRows[0].id;
const { alreadyUsedPorts } = this.state; const { alreadyUsedPorts, protocol } = this.state;
// determine whether the FIP has been bound to the port of the port // determine whether the FIP has been bound to the port of the port
const flag = alreadyUsedPorts.some( const flag = alreadyUsedPorts.some(
(pf) => (pf) =>
pf.internal_port === val && pf.internal_port === val &&
pf.internal_port_id === internal_port_id && pf.internal_port_id === internal_port_id &&
pf.internal_ip_address === internal_ip_address pf.internal_ip_address === internal_ip_address &&
pf.protocol === protocol
); );
if (flag) { if (flag) {
return Promise.reject( return Promise.reject(
@ -221,6 +229,7 @@ export class CreateDNAT extends ModalAction {
} }
return Promise.resolve(true); return Promise.resolve(true);
}, },
dependencies: ['protocol'],
}, },
]; ];
const extraColumn = getPortFormItem.call(this, ['compute:nova', '']); const extraColumn = getPortFormItem.call(this, ['compute:nova', '']);

View File

@ -15,6 +15,7 @@
import { action } from 'mobx'; import { action } from 'mobx';
import client from 'client'; import client from 'client';
import Base from 'stores/base'; import Base from 'stores/base';
import { isEmpty } from 'lodash';
export class PortForwardingStore extends Base { export class PortForwardingStore extends Base {
get client() { get client() {
@ -38,7 +39,10 @@ export class PortForwardingStore extends Base {
if (items.length === 0) { if (items.length === 0) {
return items; return items;
} }
const { fipInfo } = filters; const { fipInfo = {} } = filters;
if (isEmpty(fipInfo)) {
return items;
}
const { floating_ip_address } = fipInfo; const { floating_ip_address } = fipInfo;
items.forEach((item) => { items.forEach((item) => {
item.fip = fipInfo; item.fip = fipInfo;