-
Notifications
You must be signed in to change notification settings - Fork 379
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
add a deep ui schema generator #1666
Conversation
…his to give a better Form uiSchema edit experiance.
Thank you for the contribution! |
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.
Hi @weiner, I had a look at the PR.
Regarding the code, I don't think we need a separate "deep" generator. The PR mostly consists of copied code and in the future we would need to make sure that any change is done in both the normal and the deep generator. Instead I would prefer additional parameters to the existing generator with which the behavior can be influenced.
Generally speaking I'm not sure whether we need the functionality at all. You specifically mentioned the JSON Forms editor as a use case. There this PR would serve to avoid using the object renderer, which is a plus in the current state as the object renderer is pretty basic and has a bug. However instead of avoiding the object renderer I would rather see it fixed and enhanced. Another effect of this PR is that arrays are never rendered as tables but always with nested layouts. I'm not sure whether this is preferable over the default table rendering.
So in short: I would rather improve the JSON Forms editor than adding functionality to the JSON Forms core to avoid temporary quirky use cases of the editor.
Do you agree with this reasoning? Are there other use cases where you would see a "deep" generator as useful?
return layout; | ||
} | ||
if (types[0] === 'array') { | ||
const layout: Layout = createLayout('Control'); |
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.
Why not use createControlElement
?
if (types[0] === 'array') { | ||
const layout: Layout = createLayout('Control'); | ||
delete layout.elements; | ||
// @ts-ignore |
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.
I would like to avoid // @ts-ignore
wherever possible
layoutType, | ||
rootSchema | ||
); | ||
if (inArrayUiSchema) { |
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.
Isn't this always truthy?
I'll close this PR for now. Let me know when you have further questions. In general I would be interested in a generic way to let the user influence UI Schema generation, i.e. to allow to pass a generator function to JSON Forms. |
I vote for an option to generate a "deep" UI Schema. |
@sdirix I think my use case will be exactly the reason for this deep nested generator:
Please give some advice if you can, thank you!! PS1: Please check the generated markup for the whole new layout
|
Hi @bangank36, Questions like these are rather suited for the forum. Discussions within closed issues are rarely found by anyone. First we need to clarify the purpose of the The nice thing about this requirement is:
The The renderer could then look like this (not tested) const NavigatorLayoutRenderer = (props) => {
const controls = useMemo(() => generateControls(props.schema), [props.schema]);
return (
<NavigatorProvider initialPath="/">
<NavigatorScreen path="/">
<p>{{props.label}}</p>
{{Object.keys(props.schema.properties).map(propertyKey => (
<NavigatorButton path={`/${propertyKey}`} key={propertyKey}>
Navigate to {{propertyKey}}.
</NavigatorButton>
)}}
</NavigatorScreen>
{{Object.keys(props.schema.properties).map(propertyKey => (
<NavigatorScreen path={`/${propertyKey}`} key={propertyKey}>
<JsonFormsDispatch schema={schema} uischema={controls[propertyKey]} path={props.path}/>
</NavigatorScreen>
)}}
</NavigatorProvider>);
}
const generateControls = (schema) => {
const result = {};
Object.keys(schema.properties).forEach(key => {
result[key] = { type: 'Control', scope: `#/properties/${encode(key)}` };
});
return result;
} So I don't see any need for some deep UI Schema generation and only a single custom renderer is needed. Does this make sense to you? Edit: Follow up discussion here: https://jsonforms.discourse.group/t/render-nested-forms-in-flat-structure/1591/5 |
Add a deep ui schema generator.
Motivation:
It is easier to customize the form UI in the json form editor when you can see all UI elements used and not just the one on the root level.
This PR adds a deep ui schema generator which can be used by the json form edtor / a component embedding json from editor.
Thanks for this awesome project.