-
Notifications
You must be signed in to change notification settings - Fork 373
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
Conversation
There was a problem hiding this 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.
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]; | ||
} |
There was a problem hiding this comment.
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
.
controlElement.options?.detail || | ||
findUISchema( |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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 ''
There was a problem hiding this comment.
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 ...
packages/examples/src/1779.ts
Outdated
registerExamples([ | ||
{ | ||
name: '1779', | ||
label: 'List With Detail primitive (string)', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
label: 'List With Detail primitive (string)', | |
label: 'List With Detail primitive (number)', |
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 propertyis used. If no primitive property is available the first property in
the schema is used.
Fix #1779