From 3ada93aae8cf6c21d6e801143473247acf0ca537 Mon Sep 17 00:00:00 2001 From: xusongfu Date: Mon, 12 Dec 2022 22:15:35 +0800 Subject: [PATCH] fix the validator of cluster name and labels 1. fix the validator of cluster name 2. replace the labels in cluster which from cluster template Closes-Bug: #1999398 Change-Id: I244282686cab18ec69930b8221701a9363f70b74 --- src/locales/en.json | 1 + src/locales/zh.json | 1 + .../actions/StepCreate/StepNetwork/index.jsx | 39 +++++-------------- .../actions/StepCreate/index.jsx | 10 ++--- .../actions/StepCreate/StepInfo/index.jsx | 20 +++++++++- .../actions/StepCreate/StepLabel/index.jsx | 16 +++++++- .../actions/StepCreate/StepNodeSpec/index.jsx | 4 +- 7 files changed, 50 insertions(+), 41 deletions(-) diff --git a/src/locales/en.json b/src/locales/en.json index 495293b1..e96bf061 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -2334,6 +2334,7 @@ "The name should contain letter or number, the length is 1 to 16, characters can only contain \"0-9, a-z, A-Z, -, _.\"": "The name should contain letter or number, the length is 1 to 16, characters can only contain \"0-9, a-z, A-Z, -, _.\"", "The name should contain letter or number, the length is 2 to 64, characters can only contain \"0-9, a-z, A-Z, -, _.\"": "The name should contain letter or number, the length is 2 to 64, characters can only contain \"0-9, a-z, A-Z, -, _.\"", "The name should start with upper letter or lower letter, and be a string of 1 to 128, characters can only contain \"0-9, a-z, A-Z, \"-'_()[].:^\".": "The name should start with upper letter or lower letter, and be a string of 1 to 128, characters can only contain \"0-9, a-z, A-Z, \"-'_()[].:^\".", + "The name should start with upper letter or lower letter, characters can only contain \"0-9, a-z, A-Z, -, _, .\"": "The name should start with upper letter or lower letter, characters can only contain \"0-9, a-z, A-Z, -, _, .\"", "The name should start with upper letter, lower letter or chinese, and be a string of 1 to 128, characters can only contain \"0-9, a-z, A-Z, \"-'_()[].\".": "The name should start with upper letter, lower letter or chinese, and be a string of 1 to 128, characters can only contain \"0-9, a-z, A-Z, \"-'_()[].\".", "The name should start with upper letter, lower letter or chinese, and be a string of 1 to 128, characters can only contain \"0-9, a-z, A-Z, \"-'_()[].:^\".": "The name should start with upper letter, lower letter or chinese, and be a string of 1 to 128, characters can only contain \"0-9, a-z, A-Z, \"-'_()[].:^\".", "The name should start with upper letter, lower letter or chinese, and be a string of 1 to 128, characters can only contain \"0-9, a-z, A-Z, \"-'_.\".": "The name should start with upper letter, lower letter or chinese, and be a string of 1 to 128, characters can only contain \"0-9, a-z, A-Z, \"-'_.\".", diff --git a/src/locales/zh.json b/src/locales/zh.json index cc504761..41e8e15e 100644 --- a/src/locales/zh.json +++ b/src/locales/zh.json @@ -2334,6 +2334,7 @@ "The name should contain letter or number, the length is 1 to 16, characters can only contain \"0-9, a-z, A-Z, -, _.\"": "名称应包含字母或数字,长度为 1 到 16,且字符只能包含“0-9、a-z、A-Z、-、_”。", "The name should contain letter or number, the length is 2 to 64, characters can only contain \"0-9, a-z, A-Z, -, _.\"": "名称应包含字母或数字,长度为 2 到 64,且字符只能包含“0-9、a-z、A-Z、-、_”。", "The name should start with upper letter or lower letter, and be a string of 1 to 128, characters can only contain \"0-9, a-z, A-Z, \"-'_()[].:^\".": "名称应以大写字母或小写字母开头,最长为128字符,且只包含“0-9, a-z, A-Z, \"'-_()[].:^”。", + "The name should start with upper letter or lower letter, characters can only contain \"0-9, a-z, A-Z, -, _, .\"": "名称应以大写字母或小写字母开头,且字符只能包含“0-9、a-z、A-Z、-、_、.”。", "The name should start with upper letter, lower letter or chinese, and be a string of 1 to 128, characters can only contain \"0-9, a-z, A-Z, \"-'_()[].\".": "名称应以大写字母,小写字母或中文开头,最长为128字符,且只包含“0-9, a-z, A-Z, \"'-_()[].”。", "The name should start with upper letter, lower letter or chinese, and be a string of 1 to 128, characters can only contain \"0-9, a-z, A-Z, \"-'_()[].:^\".": "名称应以大写字母,小写字母或中文开头,最长为128字符,且只包含“0-9, a-z, A-Z, \"'-_()[].:^”。", "The name should start with upper letter, lower letter or chinese, and be a string of 1 to 128, characters can only contain \"0-9, a-z, A-Z, \"-'_.\".": "名称应以大写字母,小写字母或中文开头,最长为128字符,且只包含“0-9, a-z, A-Z, \"-'_.”。", diff --git a/src/pages/container-infra/containers/ClusterTemplates/actions/StepCreate/StepNetwork/index.jsx b/src/pages/container-infra/containers/ClusterTemplates/actions/StepCreate/StepNetwork/index.jsx index f8a3154f..cb5e4cbe 100644 --- a/src/pages/container-infra/containers/ClusterTemplates/actions/StepCreate/StepNetwork/index.jsx +++ b/src/pages/container-infra/containers/ClusterTemplates/actions/StepCreate/StepNetwork/index.jsx @@ -50,7 +50,8 @@ export class StepNetwork extends Base { } get subnetList() { - const { fixedNetwork: { selectedRowKeys = [] } = {} } = this.state; + const selectedRowKeys = + this.props.context?.fixedNetwork?.selectedRowKeys || []; return (this.subnetNetworkStore.list.data || []).filter( (it) => selectedRowKeys[0] === it.network_id ); @@ -75,10 +76,6 @@ export class StepNetwork extends Base { return acceptedDrivers; } - get nameForStateUpdate() { - return ['fixedNetwork']; - } - get defaultValue() { let values = {}; @@ -112,20 +109,14 @@ export class StepNetwork extends Base { floating_ip_enabled, }; if (fixed_network) { - values.fixedNetwork = { + values.fixedNetwork = this.props.context.fixedNetwork || { selectedRowKeys: [fixed_network], }; } if (fixed_subnet) { - const { subnetInitValue } = this.state; - - if (subnetInitValue) { - values.fixedSubnet = subnetInitValue; - } else { - values.fixedSubnet = { - selectedRowKeys: [fixed_subnet], - }; - } + values.fixedSubnet = { + selectedRowKeys: [fixed_subnet], + }; } } @@ -134,7 +125,6 @@ export class StepNetwork extends Base { get formItems() { const { extra: { network_driver } = {} } = this.props; - const { subnetInitValue } = this.state; return [ { @@ -208,18 +198,10 @@ export class StepNetwork extends Base { ], columns: networkColumns(this), onChange: (value) => { - this.setState( - { - fixedNetwork: value, - subnetInitValue: { - selectedRowKeys: [], - selectedRows: [], - }, - }, - () => { - this.formRef.current.resetFields(['fixedSubnet']); - } - ); + this.updateContext({ + fixedNetwork: value, + }); + this.updateFormValue('fixedSubnet', null); }, }, { @@ -227,7 +209,6 @@ export class StepNetwork extends Base { label: t('Fixed Subnet'), type: 'select-table', data: this.subnetList, - initValue: subnetInitValue, filterParams: [ { label: t('Name'), diff --git a/src/pages/container-infra/containers/ClusterTemplates/actions/StepCreate/index.jsx b/src/pages/container-infra/containers/ClusterTemplates/actions/StepCreate/index.jsx index 5cf58a03..f3d5aff5 100644 --- a/src/pages/container-infra/containers/ClusterTemplates/actions/StepCreate/index.jsx +++ b/src/pages/container-infra/containers/ClusterTemplates/actions/StepCreate/index.jsx @@ -114,9 +114,11 @@ export class StepCreate extends StepAction { } const body = { + ...rest, labels: requestLabels, external_network_id: externalNetwork.selectedRowKeys[0], - ...rest, + fixed_network: fixedNetwork ? fixedNetwork.selectedRowKeys[0] : null, + fixed_subnet: fixedSubnet ? fixedSubnet.selectedRowKeys[0] : null, }; if (flavor) { body.flavor_id = flavor.selectedRowKeys[0]; @@ -130,12 +132,6 @@ export class StepCreate extends StepAction { if (keypair) { body.keypair_id = keypair.selectedRowKeys[0]; } - if (fixedNetwork) { - body.fixed_network = fixedNetwork.selectedRowKeys[0]; - } - if (fixedSubnet) { - body.fixed_subnet = fixedSubnet.selectedRowKeys[0]; - } if (this.isEdit) { return this.store.update({ id: this.params.id }, body); } diff --git a/src/pages/container-infra/containers/Clusters/actions/StepCreate/StepInfo/index.jsx b/src/pages/container-infra/containers/Clusters/actions/StepCreate/StepInfo/index.jsx index 4ce824bf..dbfee9e7 100644 --- a/src/pages/container-infra/containers/Clusters/actions/StepCreate/StepInfo/index.jsx +++ b/src/pages/container-infra/containers/Clusters/actions/StepCreate/StepInfo/index.jsx @@ -58,15 +58,31 @@ export class StepInfo extends Base { return values; } + clusterNameValidator = (rule, value) => { + const pattern = /^[a-zA-Z][a-zA-Z0-9_.-]*$/; + if (!value) { + // eslint-disable-next-line prefer-promise-reject-errors + return Promise.reject(''); + } + if (!pattern.test(value)) { + return Promise.reject( + t( + 'The name should start with upper letter or lower letter, characters can only contain "0-9, a-z, A-Z, -, _, ."' + ) + ); + } + return Promise.resolve(); + }; + get formItems() { return [ { name: 'name', label: t('Cluster Name'), - type: 'input-name', + type: 'input', placeholder: t('Please input cluster name'), - isInstance: true, required: true, + validator: this.clusterNameValidator, }, { name: 'clusterTemplate', diff --git a/src/pages/container-infra/containers/Clusters/actions/StepCreate/StepLabel/index.jsx b/src/pages/container-infra/containers/Clusters/actions/StepCreate/StepLabel/index.jsx index 88ad2997..dcd6b914 100644 --- a/src/pages/container-infra/containers/Clusters/actions/StepCreate/StepLabel/index.jsx +++ b/src/pages/container-infra/containers/Clusters/actions/StepCreate/StepLabel/index.jsx @@ -25,6 +25,20 @@ export class StepLabel extends Base { return t('Labels'); } + get defaultValue() { + const values = {}; + const { context: { clusterTemplate = {} } = {} } = this.props; + const { selectedRows = [] } = clusterTemplate; + const { labels = {} } = selectedRows[0] || {}; + values.additionalLabels = Object.keys(labels || {}).map((key) => ({ + value: { + key, + value: labels[key], + }, + })); + return values; + } + get formItems() { return [ { @@ -38,4 +52,4 @@ export class StepLabel extends Base { } } -export default inject('rootStore')(observer(StepLabel)); \ No newline at end of file +export default inject('rootStore')(observer(StepLabel)); diff --git a/src/pages/container-infra/containers/Clusters/actions/StepCreate/StepNodeSpec/index.jsx b/src/pages/container-infra/containers/Clusters/actions/StepCreate/StepNodeSpec/index.jsx index 2573afc7..6f189437 100644 --- a/src/pages/container-infra/containers/Clusters/actions/StepCreate/StepNodeSpec/index.jsx +++ b/src/pages/container-infra/containers/Clusters/actions/StepCreate/StepNodeSpec/index.jsx @@ -80,11 +80,11 @@ export class StepNodeSpec extends Base { } get formItems() { - const { context: { clusterTemplate = {} } = {} } = this.props; + const { context: { clusterTemplate = {}, keypair } = {} } = this.props; const { selectedRows = [] } = clusterTemplate; const { master_flavor_id, flavor_id, keypair_id, selfKeypair } = selectedRows[0] || {}; - const { initKeyPair } = this.state; + const { initKeyPair = keypair } = this.state; const templateHasSelfKeypair = keypair_id && selfKeypair; const templateInitKeypair = { selectedRowKeys: [keypair_id],