fantonangeli commented on code in PR #3367:
URL:
https://github.com/apache/incubator-kie-tools/pull/3367#discussion_r2580762697
##########
packages/runtime-tools-components/src/components/FormRenderer/FormRenderer.tsx:
##########
@@ -51,14 +51,26 @@ export const FormRenderer =
React.forwardRef<FormRendererApi, IOwnProps & OUIAPr
};
}, [formApiRef]);
+ const normalizeBooleans = (model: any, schema: any) => {
+ const normalized = { ...model };
+ Object.keys(schema.properties || {}).forEach((key) => {
+ const prop = schema.properties[key];
+ if (prop.type === "boolean") {
+ normalized[key] = !!model[key];
+ }
+ });
+ return normalized;
+ };
+
const bridge = new JSONSchemaBridge(formSchema, (formModel) => {
// Converting back all the JS Dates into String before validating the
model
const newModel = ModelConversionTool.convertDateToString(formModel,
formSchema);
- return validator.validate(newModel);
+ const booleanSafeModel = normalizeBooleans(newModel, formSchema);
+ return validator.validate(booleanSafeModel);
});
- // Converting Dates that are in string format into JS Dates so they can be
correctly bound to the uniforms DateField
- const formData = ModelConversionTool.convertStringToDate(model,
formSchema);
+ // Converting Dates that are in string format into JS Dates so they can be
correctly bound to the uniforms DateField and doing the same for boolField
+ const formData =
normalizeBooleans(ModelConversionTool.convertDateToString(model, formSchema),
formSchema);
Review Comment:
Changing from `convertStringToDate` to `convertDateToString` can create bugs.
I would suggest to extend the functionalities of `ModelConversionTool`
(packages/runtime-tools-components/src/utils/ModelConversionTool.ts) to have
everything in the same place.
##########
packages/uniforms-patternfly/tests/BoolField.test.tsx:
##########
Review Comment:
Because now we have the conversion logic, can you please add a test to
verify it works well.
You can have a look at this code which tests the conversion string->date:
https://github.com/apache/incubator-kie-tools/blob/6a0ee07f97acd91f176b86bfe3cd56366bc69a67/packages/uniforms-patternfly/tests/DateField.test.tsx#L97
##########
packages/runtime-tools-components/src/components/FormRenderer/FormRenderer.tsx:
##########
Review Comment:
The correct test-schema for the field is:
```
"boolField": {
"type": "boolean",
"defaultValue": true
}
```
This schema should generate a checked boolean, but in this branch the
`defaultValue` is ignored.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]