-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(557) - Enforce required name and type in beans forms #832
Conversation
96f3501
to
f5e9297
Compare
53204d8
to
2ef7776
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job @tplevko , we just need to remove the submitRef
references and we're good to go
@@ -12,6 +12,8 @@ interface CustomAutoFormProps extends IDataTestID { | |||
omitFields?: string[]; | |||
onChangeModel?: (model: unknown) => void; | |||
onChange?: (path: string, value: unknown) => void; | |||
handleConfirm?: () => void; | |||
submitRef?: React.RefObject<HTMLButtonElement>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The submitRef
property is not used in this component 😃
submitRef?: React.RefObject<HTMLButtonElement>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for catching that - a residue from my previous attempt :D
props.onCreateBean(beanModel as RegistryBeanDefinition); | ||
const handleConfirm = useCallback(async () => { | ||
// validation updates the bean model, so we need to clone it to avoid creating the bean with default values | ||
const beanModelTmp = { ...beanModel }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, we're just copying the outer object, if beanModel
has nested properties, those would still have the new value, so should use either cloneDeep
from lodash
or structuredClone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, sounds like this could cause issues - updated
// validation updates the bean model, so we need to clone it to avoid creating the bean with default values | ||
const beanModelTmp = { ...beanModel }; | ||
const valid = await submitRef.current?.form.validate(); | ||
if (valid === undefined || valid === null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[pro-tip]: We have the isDefined
util to validate these two options at once
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, will try to remember this utility, looks better now.
@@ -15,9 +15,11 @@ interface MetadataEditorProps { | |||
metadata: any; | |||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | |||
onChangeModel: (model: any) => void; | |||
handleConfirm?: () => void; | |||
submitRef?: React.RefObject<HTMLButtonElement>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can remove this one
submitRef?: React.RefObject<HTMLButtonElement>; | |
submitRef?: React.RefObject<HTMLButtonElement>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed, thanks!
@@ -121,6 +128,8 @@ export const MetadataEditor: FunctionComponent<PropsWithChildren<MetadataEditorP | |||
disabled={isFormDisabled()} | |||
sortFields={true} | |||
ref={fieldsRefs} | |||
handleConfirm={props.handleConfirm} | |||
submitRef={props.submitRef} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And same here 😃
submitRef={props.submitRef} |
@@ -135,8 +144,10 @@ export const MetadataEditor: FunctionComponent<PropsWithChildren<MetadataEditorP | |||
disabled={isFormDisabled()} | |||
sortFields={true} | |||
ref={fieldsRefs} | |||
handleConfirm={props.handleConfirm} | |||
submitRef={props.submitRef} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here
submitRef={props.submitRef} |
fixes #557
vokoscreenNG-2024-02-13_12-36-35.mp4