rename guards to utils

Signed-off-by: Paul Cowan <paul.cowan@cutting.scot>
This commit is contained in:
Paul Cowan
2023-02-06 16:44:37 +00:00
parent 1b3a9bc042
commit 79dac4ac1e
5 changed files with 8 additions and 12 deletions
+1 -1
View File
@@ -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.
@@ -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 (
<TextField
label="test"
@@ -76,7 +76,7 @@ const MockDelayComponent = (
value={formData?.test ?? ''}
onChange={({ target: { value } }) => onChange({ test: value })}
margin="normal"
error={rawErrors.length > 0 && !formData}
error={rawErrors?.length > 0 && !formData}
/>
);
};
@@ -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: {
@@ -28,10 +28,9 @@ function isObject(value: JsonValue | undefined): value is JsonObject {
/**
* @internal
*/
export type FormValidation = Record<
string,
FieldValidation | Record<string, FieldValidation>
>;
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);
}
}