Skip to content
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

Special characters being removed from 'Group' label #1699

Closed
sifthedog opened this issue Feb 18, 2021 · 3 comments · Fixed by #1701
Closed

Special characters being removed from 'Group' label #1699

sifthedog opened this issue Feb 18, 2021 · 3 comments · Fixed by #1701

Comments

@sifthedog
Copy link
Contributor

sifthedog commented Feb 18, 2021

Describe the bug
Setting an uiSchema with "type": "Group" will remove any special character (including accents/diacritics) of the label properties, such as ã, õ, é, -, etc. It also will capitalize every first letter of the sentence:

'this is a test' => 'This Is A Test'
'joão' => 'Joao'

In the screenshots below, you can notice that this does not happen for the Array Renderer. You can notice that the "Destinatários" is formatted accordingly to its label, including the letter 'á'.

To Reproduce
Steps to reproduce the behavior:

  1. Create a regular UiSchema with type being set to "Group";
  2. Use material-renderer (haven't tested with any other);
  3. Add a label to this Group containing any special character, such as ã, õ, é, -, etc;
  4. Check the render;

Expected behavior
I'd expect the label to be exactly the same as the one I typed, without setting any capital letters and removing special characters

Screenshots
UiSchema
Rendered

Browser:

  • Chrome
  • Version 88.0.4324.150

Used Setup:

  • Framework: React
  • RendererSet: Material

Additional context
I've made some digging already and found out what is causing this. Inside of the MaterialObjectRenderer, we can find this excert:

  if (isEmpty(path)) {
    detailUiSchema.type = 'VerticalLayout';
  } else {
    (detailUiSchema as GroupLayout).label = startCase(
      isPlainLabel(label) ? label : label.default
    );
  }

startCase is imported from lodash and it does remove any special characters. It looks like startCase does not need to be there. I've modified the code already and a solution would be:

(detailUiSchema as GroupLayout).label = (isPlainLabel(label) ? label : label.default).split(' ').map(s => _.capitalize(s)).join(' ');

This way is using lodash but I still do not think JsonForms should capitalize the first letters of the label. So an yet better solution (in my opinion) would be:

    (detailUiSchema as GroupLayout).label = isPlainLabel(label) ? label : label.default;

Not sure if this workaround won't mess with already existing features, tho'. Shall I make a PR with this fix?

Sorry about my English.

@sdirix
Copy link
Member

sdirix commented Feb 19, 2021

Hi @sifthedog, thanks for the report and the analysis! You're right, the Group's label is inconsistent with all other ui schema labels. I think this was just an oversight, there is no reason to modify the user given label at all. We usually only do this for implicit labels, for example where no label or title is given and we need to derive the label from the property name.

Therefore I like the last suggestion best. Would be great if you could open a PR :)

@sdirix
Copy link
Member

sdirix commented Mar 10, 2021

We should even improve upon the current fix and not adapt the label at all when there is a detail ui schema.

@sdirix sdirix reopened this Mar 10, 2021
@sdirix sdirix added this to the next milestone Mar 10, 2021
@sdirix
Copy link
Member

sdirix commented Mar 11, 2021

Follow up: #1712

@sdirix sdirix closed this as completed Mar 11, 2021
@sdirix sdirix modified the milestones: next, 2.5.1 Mar 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants