-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
fix(@rjsf/core): Nested allOf blocks with multiple if/then/else statements fail to render correctly #2839
fix(@rjsf/core): Nested allOf blocks with multiple if/then/else statements fail to render correctly #2839
Changes from 6 commits
d9c2c84
173dd16
4d4a05d
e025609
3511d4b
515ff2e
7ae0e20
4c76f16
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -767,6 +767,33 @@ export function retrieveSchema(schema, rootSchema = {}, formData = {}) { | |
return resolveCondition(schema, rootSchema, formData); | ||
} | ||
|
||
// For each level of the dependency, we need to recursively determine the appropriate resolved schema given the current state of formData. | ||
// Otherwise, nested allOf subschemas will not be correctly displayed. | ||
if (resolvedSchema.properties) { | ||
const properties = {}; | ||
|
||
Object.entries(resolvedSchema.properties).forEach(entries => { | ||
const propName = entries[0]; | ||
const propSchema = entries[1]; | ||
nickgros marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const rawPropData = formData && formData[propName]; | ||
const propData = isObject(rawPropData) ? rawPropData : {}; | ||
const resolvedPropSchema = retrieveSchema( | ||
propSchema, | ||
rootSchema, | ||
propData | ||
); | ||
|
||
properties[propName] = resolvedPropSchema; | ||
|
||
if ( | ||
propSchema !== resolvedPropSchema && | ||
resolvedSchema.properties !== properties | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, this is possible ONLY when the recursive call of retrieveSchema returns a modified schema for the specific property. Otherwise resolvedSchema will be returned unchanged. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I follow that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea of this check is to reduce creation of shallow copy for the retrieved schemas. So if a schema isn't computed schema (doesn't have any if/then/else) it will be returned unchanged (and reference equality check will be enough for this condition) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry if I'm being unclear, but essentially I don't think you will ever have referential equality between There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, let me explain. Before loop we initialize There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤦♂️ I finally see it now! Thank you for this explanation (and for bearing with me)! |
||
) { | ||
resolvedSchema = { ...resolvedSchema, properties }; | ||
} | ||
}); | ||
} | ||
|
||
if ("allOf" in schema) { | ||
try { | ||
resolvedSchema = mergeAllOf({ | ||
|
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.
Could you add a comment clarifying why we have to do this new step, and what exactly we're doing? It's hard to follow exactly what's going on.
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.
Something like "For each level of the dependency, we need to recursively determine the appropriate resolved schema given the current state of formData, otherwise nested
allOf
subschemas will not be correctly displayed"?@AlimovSV wrote the original code here, so may want to word this more appropriately?
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.
finding the right words is not my best side :) I like your description
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.
@nickgros Hopefully this comment resolves your query...