From 782b172e7c91748738720edb988256d3d6df4845 Mon Sep 17 00:00:00 2001 From: solovevayaroslavna Date: Mon, 20 Mar 2023 09:03:21 +0400 Subject: [PATCH 1/2] PMM-11292-invalid-int32-create-update-dbcluster: message in validator function --- .../DBClusterAdvancedOptions/DBClusterAdvancedOptions.utils.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/public/app/percona/dbaas/components/DBCluster/EditDBClusterPage/DBClusterAdvancedOptions/DBClusterAdvancedOptions.utils.ts b/public/app/percona/dbaas/components/DBCluster/EditDBClusterPage/DBClusterAdvancedOptions/DBClusterAdvancedOptions.utils.ts index 77b8920c6efdf..c871403c4a549 100644 --- a/public/app/percona/dbaas/components/DBCluster/EditDBClusterPage/DBClusterAdvancedOptions/DBClusterAdvancedOptions.utils.ts +++ b/public/app/percona/dbaas/components/DBCluster/EditDBClusterPage/DBClusterAdvancedOptions/DBClusterAdvancedOptions.utils.ts @@ -28,5 +28,8 @@ export const canGetExpectedResources = ( }; export const nodesValidator = (value?: string): string | undefined => { + if (value && +value > 2147483647) { + return 'The number of nodes is too large'; + } return value === '2' ? 'Only 1, 3 or more nodes allowed' : undefined; }; From 71d39984e75de23331da310c8a31a9451d8e77df Mon Sep 17 00:00:00 2001 From: solovevayaroslavna Date: Mon, 20 Mar 2023 09:16:16 +0400 Subject: [PATCH 2/2] PMM-11292-invalid-int32-create-update-dbcluster: move int32 to validators.ts --- .../DBClusterAdvancedOptions.tsx | 4 ++-- .../DBClusterAdvancedOptions.utils.ts | 3 --- public/app/percona/shared/helpers/validators.test.tsx | 10 ++++++++++ public/app/percona/shared/helpers/validators.ts | 7 +++++++ 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/public/app/percona/dbaas/components/DBCluster/EditDBClusterPage/DBClusterAdvancedOptions/DBClusterAdvancedOptions.tsx b/public/app/percona/dbaas/components/DBCluster/EditDBClusterPage/DBClusterAdvancedOptions/DBClusterAdvancedOptions.tsx index 1328dfc7b7068..e783da8b441b1 100644 --- a/public/app/percona/dbaas/components/DBCluster/EditDBClusterPage/DBClusterAdvancedOptions/DBClusterAdvancedOptions.tsx +++ b/public/app/percona/dbaas/components/DBCluster/EditDBClusterPage/DBClusterAdvancedOptions/DBClusterAdvancedOptions.tsx @@ -66,10 +66,10 @@ export const DBClusterAdvancedOptions: FC = ({ const [loadingExpectedResources, setLoadingExpectedResources] = useState(false); const mounted = { current: true }; - const { required, min } = validators; + const { required, min, int32 } = validators; const { change } = form; const diskValidators = [required, min(MIN_DISK_SIZE)]; - const nodeValidators = [required, min(MIN_NODES), nodesValidator]; + const nodeValidators = [required, min(MIN_NODES), nodesValidator, int32]; const parameterValidators = [required, min(MIN_RESOURCES), resourceValidator]; const { name, kubernetesCluster, topology, resources, memory, cpu, databaseType, disk, nodes, single } = values; const resourcesInputProps = { step: '0.1' }; diff --git a/public/app/percona/dbaas/components/DBCluster/EditDBClusterPage/DBClusterAdvancedOptions/DBClusterAdvancedOptions.utils.ts b/public/app/percona/dbaas/components/DBCluster/EditDBClusterPage/DBClusterAdvancedOptions/DBClusterAdvancedOptions.utils.ts index c871403c4a549..77b8920c6efdf 100644 --- a/public/app/percona/dbaas/components/DBCluster/EditDBClusterPage/DBClusterAdvancedOptions/DBClusterAdvancedOptions.utils.ts +++ b/public/app/percona/dbaas/components/DBCluster/EditDBClusterPage/DBClusterAdvancedOptions/DBClusterAdvancedOptions.utils.ts @@ -28,8 +28,5 @@ export const canGetExpectedResources = ( }; export const nodesValidator = (value?: string): string | undefined => { - if (value && +value > 2147483647) { - return 'The number of nodes is too large'; - } return value === '2' ? 'Only 1, 3 or more nodes allowed' : undefined; }; diff --git a/public/app/percona/shared/helpers/validators.test.tsx b/public/app/percona/shared/helpers/validators.test.tsx index b62af3e245a26..ef4ed601abf4a 100644 --- a/public/app/percona/shared/helpers/validators.test.tsx +++ b/public/app/percona/shared/helpers/validators.test.tsx @@ -214,3 +214,13 @@ describe('validators compose', () => { expect(validate(120, {})).toEqual(errorMessage); }); }); + +describe('Validate int32 test', () => { + it('Validator should return undefined if the passed value is int32', () => { + // TODO + }); + + it('Validator should return error if the passed value is not int32', () => { + // TODO + }); +}); diff --git a/public/app/percona/shared/helpers/validators.ts b/public/app/percona/shared/helpers/validators.ts index b973e443ea52b..e65a15f3eab97 100644 --- a/public/app/percona/shared/helpers/validators.ts +++ b/public/app/percona/shared/helpers/validators.ts @@ -109,6 +109,13 @@ export const validators = { return result; }, + int32: (value: string) => { + if (Math.abs(+value) <= 2147483647) { + return undefined; + } + + return `The number of nodes is too large`; + }, }; export default validators;