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
mapStateToCellProps
does not translate error messages
#2090
Comments
https://codesandbox.io/s/romantic-lederberg-63c4td?file=/src/App.jsx In the above simple/contrived example, I've created 2 custom renderers - one for a We see in the red box that the text is not being passed through translation, and that we only get the default developer-only english message. But the green box we see the message is wrapped so it's working as expected. |
Here is a gist for a function to wrap my custom Cells with to get a translated error message: To use this solution the Cell // BEFORE
const CustomTextCell = withJsonFormsCellProps(
withVanillaCellProps(CustomTextCellRenderer)
);
// AFTER
const CustomTextCell = withJsonFormsCellPropsWithI18nError(
withVanillaCellProps(CustomTextCellRenderer)
); We can consider the above a kind of hack because it requires the Wrapper logic to do duplicate logic that the mapStateToCellProps has already done. I believe the true fix here is to call jsonforms/packages/core/src/util/cell.ts Lines 151 to 153 in 1b22f55
const t = getTranslator()(state);
const te = getErrorTranslator()(state);
const errors = getCombinedErrorMessage(errors, te, t, schema, uischema, path); But I guess that the authors here have purposely done this for some reason, and I guess it's because most Cell type renderers don't even read the useless |
This was discussed in our forum. In summary: The |
Probably later today I can propose a PR for this, as the fix is already documented here it should be straight forward. |
@sdirix , I looked through other unit tests for Any assistance here to get me started running a test? Here's what I did so far:
I am getting errors like this when running
|
Thanks for the PR!
It's a high priority item for the near future 👍 |
@sdirix , |
@sdirix ,
Then ran like this:
And the build got further this time but failed:
Since it failed on the |
Looks like an actual error as it also occurs in our CI. |
@sdirix , |
It seems you were able to reproduce the problems in a docker container, right? So in that case you can simply use our VS Code Dev Container |
@sdirix , Thanks, I figured out how to make my container approach re-run the tests without npm install every time, which was my issue before. I will consider giving the VS Code Dev Container a try if I do more contributions to this project. |
Fixed with #2098 |
Describe the bug
When creating custom Cells, the
errors
prop is always the untranslated message, and not the value returned by thetranslateError
function of ourJsonFormsI18nState
object.Expected behavior
The
errors
passed bymapStateToCellProps
should be passed throughtranslateError
to get project-level translations.Steps to reproduce the issue
Screenshots
I don't have any screenshots.
In which browser are you experiencing the issue?
any
Which Version of JSON Forms are you using?
v3.0.0
Framework
Core
RendererSet
Other (please specify in the Additional context field)
Additional context
We're creating our own custom renderers, where the low-level input controls need the error message. For an example of the input control itself see the following:
https://sap.github.io/ui5-webcomponents-react/?path=/docs/inputs-input--default-story
This component uses a
<ui5-input>
web component which has avalueStateMessage
field to specify the error message that only displays once you focus into the input and shows as a tooltip on the control.We've created a custom
TextCell
that uses the above Input control internally; however, we've noticed that none of the messages that show up here are ever translated. Upon investigation this appears to be a bug at the@jsonforms/core
layer here:jsonforms/packages/core/src/util/cell.ts
Lines 151 to 153 in 1b22f55
The only solution/workaround appears to have our
TextCell
to formulate the error message by directly callingmapStateToControlProps
after pulling the ctx object which is not a clean solution. I suspect that with typical renderers the Cell components don't read the errors prop, so this may never have been brought up before.The text was updated successfully, but these errors were encountered: