diff --git a/src/components/Progress/index.jsx b/src/components/Progress/index.jsx index 49e1e5c0..4998ba70 100644 --- a/src/components/Progress/index.jsx +++ b/src/components/Progress/index.jsx @@ -59,7 +59,7 @@ export default class index extends Component { if (label) { options.showInfo = false; } - const tip = value === undefined ? '-' : `${value}%`; + const tip = [undefined, null, ''].includes(value) ? '-' : `${value}%`; return ( diff --git a/src/containers/TabDetail/index.jsx b/src/containers/TabDetail/index.jsx index 1169afc2..5641c466 100644 --- a/src/containers/TabDetail/index.jsx +++ b/src/containers/TabDetail/index.jsx @@ -246,7 +246,7 @@ export default class DetailBase extends React.Component { if (unit) { return getUnitRender(dataConf)(value); } - if (value === undefined || value === '') { + if ([undefined, null, ''].includes(value)) { return '-'; } return value; diff --git a/src/pages/network/containers/Certificate/actions/Create.jsx b/src/pages/network/containers/Certificate/actions/Create.jsx index 0b33402f..6ca5236f 100644 --- a/src/pages/network/containers/Certificate/actions/Create.jsx +++ b/src/pages/network/containers/Certificate/actions/Create.jsx @@ -68,7 +68,7 @@ export class CreateAction extends ModalAction { } validateDomain = (rule, value) => { - if (value === undefined || value === '') return Promise.resolve(); + if ([undefined, null, ''].includes(value)) return Promise.resolve(); const domains = value.split(','); const allCorrect = domains.every((it) => it.length <= 100 && isDomain(it)); if (domains.length > 30 || !allCorrect) { diff --git a/src/utils/table.jsx b/src/utils/table.jsx index 9d6fae3c..ee528170 100644 --- a/src/utils/table.jsx +++ b/src/utils/table.jsx @@ -262,7 +262,7 @@ export const getUnitRender = (column) => { } if (unit) { return (value) => { - if (value === undefined || value === null) { + if ([undefined, null, ''].includes(value)) { return '-'; } return `${value}${unit}`; diff --git a/src/utils/validate.js b/src/utils/validate.js index 1631f3d5..d2923e80 100644 --- a/src/utils/validate.js +++ b/src/utils/validate.js @@ -384,7 +384,7 @@ export const macAddressMessage = t( const asciiMessage = t('Please enter a valid ASCII code'); export const databaseNameValidate = (rule, value) => { - if (!rule.required && value === undefined) { + if (!rule.required && [undefined, null, ''].includes(value)) { return Promise.resolve(true); } if (isDatabaseName(value)) { @@ -394,7 +394,7 @@ export const databaseNameValidate = (rule, value) => { }; export const databaseUserNameValidate = (rule, value) => { - if (!rule.required && value === undefined) { + if (!rule.required && [undefined, null, ''].includes(value)) { return Promise.resolve(true); } if (['os_admin', 'root'].includes(value)) { @@ -433,7 +433,7 @@ export const emailValidate = (rule, value) => { }; const nameValidate = (rule, value) => { - if (!rule.required && value === undefined) { + if (!rule.required && [undefined, null, ''].includes(value)) { return Promise.resolve(true); } if (isName(value)) { @@ -443,7 +443,7 @@ const nameValidate = (rule, value) => { }; const nameValidateWithoutChinese = (rule, value) => { - if (!rule.required && value === undefined) { + if (!rule.required && [undefined, null, ''].includes(value)) { return Promise.resolve(true); } if (isNameWithoutChinese(value)) { @@ -455,7 +455,7 @@ const nameValidateWithoutChinese = (rule, value) => { }; const fileNameValidate = (rule, value) => { - if (!rule.required && value === undefined) { + if (!rule.required && [undefined, null, ''].includes(value)) { return Promise.resolve(true); } if (isFilename(value)) { @@ -465,7 +465,7 @@ const fileNameValidate = (rule, value) => { }; const swiftFileNameValidate = (rule, value) => { - if (!rule.required && value === undefined) { + if (!rule.required && [undefined, null, ''].includes(value)) { return Promise.resolve(true); } if (isSwiftFilename(value)) { @@ -475,7 +475,7 @@ const swiftFileNameValidate = (rule, value) => { }; const keypairNameValidate = (rule, value) => { - if (!rule.required && value === undefined) { + if (!rule.required && [undefined, null, ''].includes(value)) { return Promise.resolve(true); } if (isKeypairName(value)) { @@ -485,7 +485,7 @@ const keypairNameValidate = (rule, value) => { }; const stackNameValidate = (rule, value) => { - if (!rule.required && value === undefined) { + if (!rule.required && [undefined, null, ''].includes(value)) { return Promise.resolve(true); } if (isStackName(value)) { @@ -495,7 +495,7 @@ const stackNameValidate = (rule, value) => { }; const crontabNameValidate = (rule, value) => { - if (!rule.required && value === undefined) { + if (!rule.required && [undefined, null, ''].includes(value)) { return Promise.resolve(true); } if (isCrontabName(value)) { @@ -505,7 +505,7 @@ const crontabNameValidate = (rule, value) => { }; const imageNameValidate = (rule, value) => { - if (!rule.required && value === undefined) { + if (!rule.required && [undefined, null, ''].includes(value)) { return Promise.resolve(true); } if (isImageName(value)) { @@ -515,7 +515,7 @@ const imageNameValidate = (rule, value) => { }; const instanceNameValidate = (rule, value) => { - if (!rule.required && value === undefined) { + if (!rule.required && [undefined, null, ''].includes(value)) { return Promise.resolve(true); } if (isInstanceName(value)) {