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

fix 3711 anyOf/oneOf remove old fields from previous schema #3714

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core/test/oneOf.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,7 @@ describe('oneOf', () => {

sinon.assert.calledWithMatch(onChange.lastCall, {
formData: {
craftTypes: [{ keywords: [undefined], title: undefined, daysOfYear: undefined }],
craftTypes: [{ keywords: [undefined], title: undefined }],
},
});
});
Expand Down
12 changes: 10 additions & 2 deletions packages/utils/src/schema/sanitizeDataForNewSchema.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import get from 'lodash/get';
import has from 'lodash/has';
import omitBy from 'lodash/omitBy';
import isUndefined from 'lodash/isUndefined';

import { FormContextType, GenericObjectType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '../types';
import { PROPERTIES_KEY, REF_KEY } from '../constants';
Expand Down Expand Up @@ -137,8 +139,14 @@ export default function sanitizeDataForNewSchema<
});

newFormData = {
...data,
Copy link
Member

Choose a reason for hiding this comment

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

@cwendtxealth These changes are very similar to #3443 (comment). In that PR I requested the developer to ensure that none of the other issues were regressed. Are you willing to do that legwork?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I should be able to validate those issues if they have reproducible steps

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just from some initial testing it does look like removing some undefined fields causes some issues with how getDefaultFormState fills out formData. Might need to look at a different place to remove the undefined fields.

Copy link
Member

Choose a reason for hiding this comment

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

@cwendtxealth I'm on vacation for a week starting today. My thoughts are that, perhaps we add another flag to the experimental_defaultFormStateBehavior that deals with this behavior somehow.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we talk about this at one of the Friday meetings?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That sounds good!

...removeOldSchemaData,
// remove fields from old schema and then sanitize undefined
...omitBy(
{
...data,
...removeOldSchemaData,
},
isUndefined
),
...nestedData,
};
// First apply removing the old schema data, then apply the nested data, then apply the old data keys to keep
Expand Down