diff --git a/.changeset/shy-buses-mix.md b/.changeset/shy-buses-mix.md index c92b119664..b7db90d03c 100644 --- a/.changeset/shy-buses-mix.md +++ b/.changeset/shy-buses-mix.md @@ -2,4 +2,4 @@ '@backstage/plugin-scaffolder-react': minor --- -refactor `createAsyncValidators` to be recursive +refactor `createAsyncValidators` to be recursive to ensure validators are called in nested schemas. diff --git a/packages/app/src/components/scaffolder/customScaffolderExtensions.tsx b/packages/app/src/components/scaffolder/customScaffolderExtensions.tsx index fc37ff9e96..c521bcf86c 100644 --- a/packages/app/src/components/scaffolder/customScaffolderExtensions.tsx +++ b/packages/app/src/components/scaffolder/customScaffolderExtensions.tsx @@ -68,7 +68,7 @@ export const LowerCaseValuePickerFieldExtension = scaffolderPlugin.provide( const MockDelayComponent = ( props: NextFieldExtensionComponentProps<{ test?: string }>, ) => { - const { onChange, formData, rawErrors = [] } = props; + const { onChange, formData, rawErrors } = props; return ( onChange({ test: value })} margin="normal" - error={rawErrors.length > 0 && !formData} + error={rawErrors?.length > 0 && !formData} /> ); }; diff --git a/plugins/scaffolder-react/src/next/components/Stepper/Stepper.tsx b/plugins/scaffolder-react/src/next/components/Stepper/Stepper.tsx index a1ad289a1a..9242ef0086 100644 --- a/plugins/scaffolder-react/src/next/components/Stepper/Stepper.tsx +++ b/plugins/scaffolder-react/src/next/components/Stepper/Stepper.tsx @@ -38,7 +38,7 @@ import { useFormDataFromQuery } from '../../hooks'; import { FormProps } from '../../types'; import { LayoutOptions } from '../../../layouts'; import { useTransformSchemaToProps } from '../../hooks/useTransformSchemaToProps'; -import { hasErrors } from './guards'; +import { hasErrors } from './utils'; const useStyles = makeStyles(theme => ({ backButton: { diff --git a/plugins/scaffolder-react/src/next/components/Stepper/createAsyncValidators.ts b/plugins/scaffolder-react/src/next/components/Stepper/createAsyncValidators.ts index 92774084b2..eec1f368c6 100644 --- a/plugins/scaffolder-react/src/next/components/Stepper/createAsyncValidators.ts +++ b/plugins/scaffolder-react/src/next/components/Stepper/createAsyncValidators.ts @@ -28,10 +28,9 @@ function isObject(value: JsonValue | undefined): value is JsonObject { /** * @internal */ -export type FormValidation = Record< - string, - FieldValidation | Record ->; +export type FormValidation = { + [name: string]: FieldValidation | FormValidation; +}; export const createAsyncValidators = ( rootSchema: JsonObject, @@ -64,10 +63,7 @@ export const createAsyncValidators = ( formValidation[key] = fieldValidation; } } else if (isObject(value)) { - formValidation[key] = (await validate(formData, path, value)) as Record< - string, - FieldValidation - >; + formValidation[key] = await validate(formData, path, value); } } diff --git a/plugins/scaffolder-react/src/next/components/Stepper/guards.ts b/plugins/scaffolder-react/src/next/components/Stepper/utils.ts similarity index 100% rename from plugins/scaffolder-react/src/next/components/Stepper/guards.ts rename to plugins/scaffolder-react/src/next/components/Stepper/utils.ts