fix: Adding corrected code documentation for custom field extension

Signed-off-by: Thomas Viaud <t.viaud@elsevier.com>
This commit is contained in:
Thomas Viaud
2021-10-27 17:38:37 +01:00
parent 88a01d9320
commit 08de4fa957
@@ -27,20 +27,21 @@ You can create your own Field Extension by using the
```tsx
//packages/app/scaffolder/MyCustomExtension/MyCustomExtension.tsx
import React from 'react';
import { FieldProps, FieldValidation } from '@rjsf/core';
import FormControl from '@material-ui/core/FormControl';
import { KubernetesValidatorFunctions } from '@backstage/catalog-model';
/*
This is the actual component that will get rendered in the form
*/
export const MyCustomExtension = ({ onChange, required }: FieldProps<string>) => {
return (
<FormControl
margin="normal"
required={required}
error={rawErrors?.length > 0 && !formData}
onChange={onChange}
>
)
export const MyCustomExtension = ({ onChange, rawErrors, required, formData }: FieldProps<string>) => {
return (
<FormControl
margin="normal"
required={required}
error={rawErrors?.length > 0 && !formData}
onChange={onChange} />
)
};
/*
@@ -49,24 +50,24 @@ export const MyCustomExtension = ({ onChange, required }: FieldProps<string>) =>
*/
export const myCustomValidation = (
value: string,
validation: FieldValidation,
value: string,
validation: FieldValidation,
) => {
if (!KubernetesValidatorFunctions.isValidObjectName(value)) {
validation.addError(
'must start and end with an alphanumeric character, and contain only alphanumeric characters, hyphens, underscores, and periods. Maximum length is 63 characters.',
);
}
if (!KubernetesValidatorFunctions.isValidObjectName(value)) {
validation.addError(
'must start and end with an alphanumeric character, and contain only alphanumeric characters, hyphens, underscores, and periods. Maximum length is 63 characters.',
);
}
};
```
```tsx
// packages/app/scaffolder/MyCustomExtension/extensions.ts
/*
/*
This is where the magic happens and creates the custom field extension.
Note that if you're writing extensions part of a separate plugin,
Note that if you're writing extensions part of a separate plugin,
then please use `plugin.provide` from there instead and export it part of your `plugin.ts` rather than re-using the `scaffolder.plugin`.
*/