jsonforms icon indicating copy to clipboard operation
jsonforms copied to clipboard

React MUI : Allow the translation of enum value used for elementLabelProp

Open Maxouwell opened this issue 1 year ago • 3 comments

Describe the bug

At the moment, when an enum field is used in a elementLabelProp option, the raw enum value is used, without allowing to translate it via the translate function. image

Expected behavior

The value should be sent to the translate function for customizing.

Steps to reproduce the issue

Create a JsonForms with :

Json Schema

{
  type: 'array',
  items: {
    type: 'object',
    properties: {
      message: {
        type: 'string',
        maxLength: 3,
      },
      messageType: {
        type: 'string',
        enum: ['MSG_TYPE_1', 'MSG_TYPE_2'],
      },
    },
  },
}

UI Schema :

{
  type: 'Control',
  scope: '#',
  options: {
    elementLabelProp: 'messageType',
    detail: {
      type: 'HorizontalLayout',
      elements: [
        { type: 'Control', scope: '#/properties/message' },
        { type: 'Control', scope: '#/properties/messageType' },
      ],
    },
  },
}

Data :

[
  {
    message: 'El Barto was here',
    messageType: 'MSG_TYPE_1',
  },
  {
    message: 'Yolo',
  },
]

Screenshots

No response

Which Version of JSON Forms are you using?

v.3.2.1

Framework

React

RendererSet

Material

Additional context

I think an old bug was repurposed to highlight this behavior but I can't find it anymore.

Maxouwell avatar Feb 19 '24 15:02 Maxouwell

Hi @Maxouwell , thanks for bringing this up :) I agree that this would be a nice extension to the behavior of the ExpandPanelRenderer. Would you like to contribute this?

lucas-koehler avatar Feb 22 '24 09:02 lucas-koehler

Hi @lucas-koehler ! Has you've seen, I already submited a PR for this :)

As a side question, what would be the best way to check with you if something is a bug or not ? I came across some odd behavior while doing the PR that I'm not sure if it was intended. Should I open a bug for each one ? (on the top of my mind, MaterialEnumArrayRenderer that could have a FormLabel, and a description, and that does not support const value (but it means having withJsonFormsMultiEnumProps addind const support, and it impact the core and the other type of renderer, which I'm not able to fix/expand))

Maxouwell avatar Feb 23 '24 21:02 Maxouwell

Hi @Maxouwell , generally opening issues is the best way to do that. If the behavior is intended the issue can always be closed again and we have a searchable record of the behavior :) In your concrete example, I would not classift the MaterialEnumArrayRenderer not having a FormLabel or description a bug. More like a feature that could be extended. However, it is of course still fine to open an issue for that to document and possibly fix it.

lucas-koehler avatar Feb 26 '24 09:02 lucas-koehler

Thanks @sdirix for your help on theses PR !

Maxouwell avatar Apr 19 '24 19:04 Maxouwell