Skip to content

mapStateToCellProps does not translate error messages #2090

@codefactor

Description

@codefactor

Describe the bug

When creating custom Cells, the errors prop is always the untranslated message, and not the value returned by the translateError function of our JsonFormsI18nState object.

Expected behavior

The errors passed by mapStateToCellProps should be passed through translateError to get project-level translations.

Steps to reproduce the issue

  1. Create your own cell renderer that expects to get the error message
  2. Create a form that uses the cell, and define a custom translateError function
  3. Check the error message that the cell renderer gets
  4. See that the cell does not get the translations from the translateError

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 a valueStateMessage 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:

const errors = formatErrorMessage(
union(getErrorAt(path, schema)(state).map(error => error.message))
);

The only solution/workaround appears to have our TextCell to formulate the error message by directly calling mapStateToControlProps 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions