-
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 omitExtraData bugs for nested empties and nonspecified objects #1419
Fix omitExtraData bugs for nested empties and nonspecified objects #1419
Conversation
src/utils.js
Outdated
@@ -873,43 +873,34 @@ export function toIdSchema( | |||
|
|||
export function toPathSchema(schema, name = "", definitions, formData = {}) { | |||
const pathSchema = { | |||
$name: name, | |||
$name: name.replace(/\.$/, ""), |
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 is this needed?
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.
As a result of refactoring and because the initial call starts with name as an empty string, I ended up with a period prepended to all of the $name
s, so I swapped it such that the period is appended, then removed when the $name
value is set. e.g. here
changes `${name}.${i}`
to `${name}${i}.`
.
Now that I think about it, it was honestly was kind of an arbitrary change. If you think the old style is more clear, I can change it back.
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 think you can change it to the old style, unless there are any additional advantages to this new style.
My PR #1418 also does this, although the way it does so isn't very good -- it relies on looking for the first "." in the string (which could be an issue with specially-named keys later). Your method seems better! |
…onschema-form into feature/omitExtraData-array-of-empties
@epicfaace I added your tests, and if I understand correctly, |
Yes.
There are tests at the end of Form_test.js that are not within the |
By the way, the test that is failing is due to issues with form defaults when omitExtraData and/or liveOmit are true. I fixed them in the other PR with these changes: https://github.com/mozilla-services/react-jsonschema-form/pull/1418/files#diff-07a63ede6fe55fca89398d42da737369R249-R253 |
Yeah I see what you are doing, but I think that that logic can be moved to |
@Tonexus ok, but if |
@epicfaace That's a good point, if Also, right now it looks like |
Yes, please do.
Sounds good, thanks! |
@epicfaace Actually, should On a side note, a lot of the logic in |
@epicfaace I'm now having issues with the very last test case in the file. Can you explain the reasoning for that one? It looks like it is correctly applying the new |
Yeah, you're right. For the very last test case, you're right, I think the test case is wrong. I based it off an original test that tested based on an external (props-based) formData change, which used It may be good to split this up; for each test in the final "Schema and formData updates" |
@epicfaace Ok, made those changes. There are now 4 new tests for each combo of |
Oh, I remember why pathSchema was initially part of the state. The idea was that it could be passed on to widgets/fields eventually, so that they would be able to know the "path" of the formData that they refer to. However, given that pathSchema is only computed live when |
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.
Looks good! Just a few more things.
src/utils.js
Outdated
if ( | ||
schema.hasOwnProperty("items") && | ||
Array.isArray(formData) && | ||
formData.length > 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.
This line is probably not necessary (line 885)
@epicfaace Added most of the requested changes. See review comment. |
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 think we're good! Thanks for all your work on this.
You can use the playground link for the deploy preview of this PR: https://deploy-preview-1419--rjsf.netlify.com/ |
Reasons for making this change
Fixes #1388 and fixes #1396. Alternative to #1418.
Modifies behavior of
toPathSchema
inutils.js
(afaik the function is only used in omitting the extra data, let me know if this breaks anything else) to create$name
key for arrays as well to be consistent with behavior for objects. Modifies behavior ofgetFieldNames
inForm.js
to also add a path to the array of paths if that path points to something empty. Refactors the surrounding code to be more concise and, hopefully, readable. Adds tests foromitExtraData
andliveOmit
.Checklist