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

Improve label handling in MasterListComponent #1786

Merged
merged 2 commits into from
Jul 15, 2021

Conversation

eneufeld
Copy link
Member

The MasterListComponent did only show labels for object lists.
Furthermore the options property in the uischema was mandatory.
Also the property to use as label for objects had to be provided.

The fix now handles primitives, a missing options property and
in the case of a missing labelRef the first primitive property
is used. If no primitive property is available the first property in
the schema is used.

Fix #1779

@eneufeld eneufeld requested a review from sdirix July 13, 2021 16:45
@coveralls
Copy link

coveralls commented Jul 13, 2021

Coverage Status

Coverage increased (+0.04%) to 88.642% when pulling c61a24c on eneufeld:bug-1779 into a83b128 on eclipsesource:master.

Copy link
Member

@sdirix sdirix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix and the additional improvements! Noticed some minor issues.

Comment on lines 252 to 259
const getFirstUsableProperty = (schema: JsonSchema): string => {
const prop = Object.entries(schema?.properties).find(e => {
if(e[1].type === 'object' || e[1].properties) return false;
if(e[1].type === 'array' || e[1].items) return false;
return true;
});
return prop ? prop[0] : Object.keys(schema?.properties)[0];
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a utility for this in @jsonforms/core which you can import: getFirstPrimitiveProp.

Comment on lines 174 to 175
controlElement.options?.detail ||
findUISchema(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not directly related to this PR but I just noticed this issue here: findUISchema already checks the options.detail, so we don't need to do this manually. Especially as our API also allows the strings DEFAULT, GENERATED and REGISTERED as valid detail values ;)

We can just hand over the controlElement as the next parameter after 'VerticalLayout', i.e.

const detailUISchema = findUISchema(
  props.uischemas,
  schema,
  `${controlElement.scope}/items`,
  props.path,
  'VerticalLayout',
  controlElement,
);

The MasterListComponent did only show labels for object lists.
Furthermore the options property in the uischema was mandatory.
Also the property to use as label for objects had to be provided.

The fix now handles primitives, a missing options property and
in the case of a missing `labelRef` the first primitive property
is used. If no primitive property is available the fallback text
'No label set' will be shown.

Fix eclipsesource#1779
controlElement.options.labelRef
);
const isPrimitive = d && typeof d !== 'object';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is false for 0 and empty strings ''

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix, JS and auto conversion of types ...

registerExamples([
{
name: '1779',
label: 'List With Detail primitive (string)',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
label: 'List With Detail primitive (string)',
label: 'List With Detail primitive (number)',

@sdirix sdirix merged commit d6edf4b into eclipsesource:master Jul 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle primitive labeling in angular-material MasterListComponent
3 participants