From 22bd2926343b6522c5e7616487d12c6e2ec5cdf1 Mon Sep 17 00:00:00 2001 From: xusongfu Date: Wed, 11 Aug 2021 16:58:46 +0800 Subject: [PATCH] fix: Fix cannot create network with ipv6 and other issues 1. Fix the gateway_ip form item to prevent wrong verification 2. Fix checkCidr function to make sure correct verification of empty values 3. Fix rule message to match form label with empty value 4. Add `maskClosable = false` to prevent closing the modal by mistake when filling in the form, causing all inputs to be cleared Change-Id: I55f504b6a457de7ff0dd1017453a1cd800f4610a --- src/components/FormItem/index.jsx | 3 +- src/locales/en.json | 4 +- src/locales/zh.json | 4 +- .../Network/actions/CreateNetwork.jsx | 46 ++++++------------- .../Network/actions/CreateSubnet.jsx | 41 ++++++----------- 5 files changed, 34 insertions(+), 64 deletions(-) diff --git a/src/components/FormItem/index.jsx b/src/components/FormItem/index.jsx index 505d6fc0..372fb1f8 100644 --- a/src/components/FormItem/index.jsx +++ b/src/components/FormItem/index.jsx @@ -281,6 +281,7 @@ export default class FormItem extends React.Component { tip, name, hidden, + label, } = this.props; if (hidden) { return []; @@ -294,7 +295,7 @@ export default class FormItem extends React.Component { if (required) { if (tip && type.indexOf('select-table') < 0) { requiredRule.required = true; - requiredRule.message = t('Please input!'); + requiredRule.message = `${t('Please input') + label}!`; } else { newRule.required = required; } diff --git a/src/locales/en.json b/src/locales/en.json index aca806ff..baa84385 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -850,7 +850,6 @@ "Invalid CIDR.": "Invalid CIDR.", "Invalid IP Address": "Invalid IP Address", "Invalid IP Address and Port": "Invalid IP Address and Port", - "Invalid Ip.": "Invalid Ip.", "Invalid Mac Address. Please Use \":\" as separator.": "Invalid Mac Address. Please Use \":\" as separator.", "Invalid Tag Value: {tag}": "Invalid Tag Value: {tag}", "Invalid: ": "Invalid: ", @@ -862,7 +861,7 @@ "Invalid: Password must be the same with confirm password.": "Invalid: Password must be the same with confirm password.", "Invalid: Please input a valid ip": "Invalid: Please input a valid ip", "Invalid: Please input a valid ipv4": "Invalid: Please input a valid ipv4", - "Invalid: Project name can not be chinese": "Invalid: Project name can not be chinese", + "Invalid: Please input a valid ipv6.": "Invalid: Please input a valid ipv6.", "Invalid: Project name can not be duplicated": "Invalid: Project name can not be duplicated", "Invalid: Quota value(s) cannot be less than the current usage value(s): { used } used.": "Invalid: Quota value(s) cannot be less than the current usage value(s): { used } used.", "Invalid: User Group name can not be duplicated": "Invalid: User Group name can not be duplicated", @@ -1172,7 +1171,6 @@ "Please input your Username!": "Please input your Username!", "Please input your current password!": "Please input your current password!", "Please input your password!": "Please input your password!", - "Please input!": "Please input!", "Please make sure this IP address be available to avoid creating VM failure.": "Please make sure this IP address be available to avoid creating VM failure.", "Please make sure this IP address be available.": "Please make sure this IP address be available.", "Please reasonably plan the network and subnet to which the virtual network card belongs.": "Please reasonably plan the network and subnet to which the virtual network card belongs.", diff --git a/src/locales/zh.json b/src/locales/zh.json index a506cad7..1b3cd1fe 100644 --- a/src/locales/zh.json +++ b/src/locales/zh.json @@ -850,7 +850,6 @@ "Invalid CIDR.": "无效的CIDR", "Invalid IP Address": "无效的IP地址", "Invalid IP Address and Port": "无效的IP地址和端口,成员已存在", - "Invalid Ip.": "无效IP", "Invalid Mac Address. Please Use \":\" as separator.": "无效的Mac地址。请使用\":\"作为分隔符。", "Invalid Tag Value: {tag}": "非法的Tag值: {tag}", "Invalid: ": "无效:", @@ -862,7 +861,7 @@ "Invalid: Password must be the same with confirm password.": "无效:密码和确认密码必须一致。", "Invalid: Please input a valid ip": "无效:请输入有效的IP", "Invalid: Please input a valid ipv4": "无效:请输入有效的IPV4", - "Invalid: Project name can not be chinese": "无效:项目名称不可带中文", + "Invalid: Please input a valid ipv6.": "无效:请输入有效的IPV6", "Invalid: Project name can not be duplicated": "无效:项目名称不可重复", "Invalid: Quota value(s) cannot be less than the current usage value(s): { used } used.": "无效:配额必须大于已使用数量{ used }且为整数", "Invalid: User Group name can not be duplicated": "无效:用户组名称不可重复", @@ -1172,7 +1171,6 @@ "Please input your Username!": "请输入用户名", "Please input your current password!": "请输入当前密码!", "Please input your password!": "请输入密码!", - "Please input!": "请输入!", "Please make sure this IP address be available to avoid creating VM failure.": "需检查此 IP 是否已被占用,否则可能创建失败。", "Please make sure this IP address be available.": "需确保此IP未被占用。", "Please reasonably plan the network and subnet to which the virtual network card belongs.": "请合理规划虚拟网卡所属的网络和子网。", diff --git a/src/pages/network/containers/Network/actions/CreateNetwork.jsx b/src/pages/network/containers/Network/actions/CreateNetwork.jsx index 389ec7e1..fa19dca9 100644 --- a/src/pages/network/containers/Network/actions/CreateNetwork.jsx +++ b/src/pages/network/containers/Network/actions/CreateNetwork.jsx @@ -210,8 +210,6 @@ export default class CreateNetwork extends ModalAction { } checkCidr = (value) => { - if (isEmpty(value)) return false; - const { ip_version = 'ipv4' } = this.state; if (ip_version === 'ipv4' && !isIpCidr(value)) return false; @@ -435,9 +433,9 @@ export default class CreateNetwork extends ModalAction { if (!create_subnet && !value) { return Promise.resolve(); } - if (!this.checkCidr(value)) { + if (!isEmpty(value) && !this.checkCidr(value)) { // eslint-disable-next-line prefer-promise-reject-errors - return Promise.reject(new Error(t('Invalid CIDR.'))); + return Promise.reject(new Error(t('Invalid: ') + t('CIDR'))); } return Promise.resolve(); }, @@ -484,7 +482,7 @@ export default class CreateNetwork extends ModalAction { { name: 'gateway_ip', label: t('Gateway IP'), - type: 'ip-input', + type: ip_version === 'ipv6' ? 'input' : 'ip-input', onChange: (e) => { this.setState({ gateway_ip: e.target.value, @@ -493,32 +491,18 @@ export default class CreateNetwork extends ModalAction { tip: t( 'If no gateway is specified, the first IP address will be defaulted.' ), - hidden: !(create_subnet && more && isIpv4 && !disable_gateway), - }, - { - name: 'gateway_ip', - label: t('Gateway IP'), - type: 'input', - onChange: (e) => { - this.setState({ - gateway_ip: e.target.value, - }); - }, - tip: t( - 'If no gateway is specified, the first IP address will be defaulted.' - ), - hidden: !( - create_subnet && - more && - ip_version === 'ipv6' && - !disable_gateway - ), - validator: (rule, value) => { - if (!this.checkGateway(value)) { - return Promise.reject(new Error(t('Invalid Ip.'))); - } - return Promise.resolve(); - }, + hidden: !(create_subnet && more && !disable_gateway), + validator: + ip_version === 'ipv6' + ? (rule, value) => { + if (!this.checkGateway(value)) { + return Promise.reject( + new Error(t('Invalid: Please input a valid ipv6.')) + ); + } + return Promise.resolve(); + } + : null, }, { name: 'enable_dhcp', diff --git a/src/pages/network/containers/Network/actions/CreateSubnet.jsx b/src/pages/network/containers/Network/actions/CreateSubnet.jsx index f73de7ed..ba23e270 100644 --- a/src/pages/network/containers/Network/actions/CreateSubnet.jsx +++ b/src/pages/network/containers/Network/actions/CreateSubnet.jsx @@ -73,8 +73,6 @@ export default class CreateSubnet extends ModalAction { } checkCidr = (value) => { - if (isEmpty(value)) return false; - const { ip_version = 'ipv4' } = this.state; if (ip_version === 'ipv4' && !isIpCidr(value)) return false; @@ -207,8 +205,8 @@ export default class CreateSubnet extends ModalAction { required: true, // validator: (rule, value) => (isIpWithMask(value) ? Promise.resolve(true) : Promise.reject(new Error(t('Invalid CIDR.')))), validator: (rule, value) => { - if (!this.checkCidr(value)) { - return Promise.reject(new Error(t('Invalid CIDR.'))); + if (!isEmpty(value) && !this.checkCidr(value)) { + return Promise.reject(new Error(t('Invalid: ') + t('CIDR'))); } return Promise.resolve(); }, @@ -232,7 +230,7 @@ export default class CreateSubnet extends ModalAction { { name: 'gateway_ip', label: t('Gateway IP'), - type: 'ip-input', + type: ip_version === 'ipv6' ? 'input' : 'ip-input', onChange: (e) => { this.setState({ gateway_ip: e.target.value, @@ -241,27 +239,18 @@ export default class CreateSubnet extends ModalAction { tip: t( 'If no gateway is specified, the first IP address will be defaulted.' ), - hidden: !(more && isIpv4 && !disable_gateway), - }, - { - name: 'gateway_ip', - label: t('Gateway IP'), - type: 'input', - onChange: (e) => { - this.setState({ - gateway_ip: e.target.value, - }); - }, - tip: t( - 'If no gateway is specified, the first IP address will be defaulted.' - ), - hidden: !(more && ip_version === 'ipv6' && !disable_gateway), - validator: (rule, value) => { - if (!this.checkGateway(value)) { - return Promise.reject(new Error(t('Invalid Ip.'))); - } - return Promise.resolve(); - }, + hidden: !(more && !disable_gateway), + validator: + ip_version === 'ipv6' + ? (rule, value) => { + if (!this.checkGateway(value)) { + return Promise.reject( + new Error(t('Invalid: Please input a valid ipv6.')) + ); + } + return Promise.resolve(); + } + : null, }, { name: 'enable_dhcp',