From 903faa256c8cca770837d546186375a7ad351e44 Mon Sep 17 00:00:00 2001 From: Bogdan Fazakas Date: Fri, 13 Oct 2023 08:25:40 +0300 Subject: [PATCH 1/3] add validation to custom docker image fields --- .../InputElement/ContainerInput/_validation.ts | 12 ++++++++++++ src/components/Publish/_validation.ts | 10 ++++++++++ 2 files changed, 22 insertions(+) create mode 100644 src/components/@shared/FormInput/InputElement/ContainerInput/_validation.ts diff --git a/src/components/@shared/FormInput/InputElement/ContainerInput/_validation.ts b/src/components/@shared/FormInput/InputElement/ContainerInput/_validation.ts new file mode 100644 index 0000000000..4a2a512358 --- /dev/null +++ b/src/components/@shared/FormInput/InputElement/ContainerInput/_validation.ts @@ -0,0 +1,12 @@ +import { MetadataAlgorithmContainer } from '@components/Publish/_types' +import * as Yup from 'yup' +import { SchemaLike } from 'yup/lib/types' + +export const validationAlgorithmContianerParameters: { + [key in keyof MetadataAlgorithmContainer]: SchemaLike +} = { + entrypoint: Yup.string().required(), + image: Yup.string().required(), + tag: Yup.string().required(), + checksum: Yup.string().required() +} diff --git a/src/components/Publish/_validation.ts b/src/components/Publish/_validation.ts index 62a385ea29..cb36de2b9b 100644 --- a/src/components/Publish/_validation.ts +++ b/src/components/Publish/_validation.ts @@ -4,6 +4,7 @@ import { getMaxDecimalsValidation } from '@utils/numbers' import * as Yup from 'yup' import { testLinks } from '@utils/yup' import { validationConsumerParameters } from '@components/@shared/FormInput/InputElement/ConsumerParameters/_validation' +import { validationAlgorithmContianerParameters } from '@components/@shared/FormInput/InputElement/ContainerInput/_validation' // TODO: conditional validation // e.g. when algo is selected, Docker image is required @@ -25,6 +26,15 @@ const validationMetadata = { .required('Required'), author: Yup.string().required('Required'), tags: Yup.array().nullable(), + dockerImage: Yup.string().when('type', { + is: 'algorithm', + then: Yup.array() + .of(Yup.object().shape(validationAlgorithmContianerParameters)) + .required('Required'), + otherwise: Yup.array() + .nullable() + .transform((value) => value || null) + }), termsAndConditions: Yup.boolean() .required('Required') .isTrue('Please agree to the Terms and Conditions.'), From 363e3047e699c8143d3c8ec3acedbc0077cc85bc Mon Sep 17 00:00:00 2001 From: Bogdan Fazakas Date: Fri, 13 Oct 2023 11:09:54 +0300 Subject: [PATCH 2/3] updated validation logic --- .../InputElement/ContainerInput/_validation.ts | 12 ------------ src/components/Publish/_validation.ts | 15 +++++++++------ 2 files changed, 9 insertions(+), 18 deletions(-) delete mode 100644 src/components/@shared/FormInput/InputElement/ContainerInput/_validation.ts diff --git a/src/components/@shared/FormInput/InputElement/ContainerInput/_validation.ts b/src/components/@shared/FormInput/InputElement/ContainerInput/_validation.ts deleted file mode 100644 index 4a2a512358..0000000000 --- a/src/components/@shared/FormInput/InputElement/ContainerInput/_validation.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { MetadataAlgorithmContainer } from '@components/Publish/_types' -import * as Yup from 'yup' -import { SchemaLike } from 'yup/lib/types' - -export const validationAlgorithmContianerParameters: { - [key in keyof MetadataAlgorithmContainer]: SchemaLike -} = { - entrypoint: Yup.string().required(), - image: Yup.string().required(), - tag: Yup.string().required(), - checksum: Yup.string().required() -} diff --git a/src/components/Publish/_validation.ts b/src/components/Publish/_validation.ts index cb36de2b9b..5e6e49b2f9 100644 --- a/src/components/Publish/_validation.ts +++ b/src/components/Publish/_validation.ts @@ -28,12 +28,15 @@ const validationMetadata = { tags: Yup.array().nullable(), dockerImage: Yup.string().when('type', { is: 'algorithm', - then: Yup.array() - .of(Yup.object().shape(validationAlgorithmContianerParameters)) - .required('Required'), - otherwise: Yup.array() - .nullable() - .transform((value) => value || null) + then: Yup.string().required('Required') + }), + dockerImageCustomChecksum: Yup.string().when('type', { + is: 'algorithm', + then: Yup.string().required('Required') + }), + dockerImageCustomEntrypoint: Yup.string().when('type', { + is: 'algorithm', + then: Yup.string().required('Required') }), termsAndConditions: Yup.boolean() .required('Required') From 07dc3ac6183c65459db4cdadb3f9f4cfe0502d44 Mon Sep 17 00:00:00 2001 From: Bogdan Fazakas Date: Fri, 13 Oct 2023 11:17:40 +0300 Subject: [PATCH 3/3] fix build --- src/components/Publish/_validation.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/Publish/_validation.ts b/src/components/Publish/_validation.ts index 5e6e49b2f9..cd5a6b83c8 100644 --- a/src/components/Publish/_validation.ts +++ b/src/components/Publish/_validation.ts @@ -4,7 +4,6 @@ import { getMaxDecimalsValidation } from '@utils/numbers' import * as Yup from 'yup' import { testLinks } from '@utils/yup' import { validationConsumerParameters } from '@components/@shared/FormInput/InputElement/ConsumerParameters/_validation' -import { validationAlgorithmContianerParameters } from '@components/@shared/FormInput/InputElement/ContainerInput/_validation' // TODO: conditional validation // e.g. when algo is selected, Docker image is required