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: made small changes to utility functions to fix #3997, #4314 and #4322 #4329

Merged
merged 8 commits into from
Oct 21, 2024

Conversation

heath-freenome
Copy link
Member

@heath-freenome heath-freenome commented Oct 5, 2024

Reasons for making this change

Fixes #3977, #4314, #4322

  • In @rjsf/utils, made the following changes:
    • Added mergeDefaultsIntoFormData option to Experimental_DefaultFormStateBehavior type to control how to handle merging of defaults
    • Updated mergeDefaultsWithFormData() to add new optional defaultSupercedesUndefined that when true uses the defaults rather than undefined formData
    • Updated getDefaultFormState() to pass true to mergeDefaultsWithFormData for defaultSupercedesUndefined when mergeDefaultsIntoFormData has the value useDefaultIfFormDataUndefined
    • Updated getClosestMatchingOption() to improve the scoring function so that an object container that matches a key gets an extra point
  • In @rjsf/core, updated MultiSchemaField to call onChange after setting the new option in state rather than before
  • In the playground, added controls for the new mergeDefaultsIntoFormData option
    • Moved the Show Error List component over one column, making it inline radio buttons rather than a select
  • Updated the CHANGELOG.md accordingly

Checklist

  • I'm updating documentation
  • I'm adding or updating code
    • I've added and/or updated tests. I've run npx nx run-many --target=build --exclude=@rjsf/docs && npm run test:update to update snapshots, if needed.
    • I've updated docs if needed
    • I've updated the changelog with a description of the PR
  • I'm adding a new feature
    • I've updated the playground with an example use of the feature
Screenshot 2024-10-18 at 3 32 49 PM

@reshmarevi-kv
Copy link

please merge this pr fast

@heath-freenome
Copy link
Member Author

please merge this pr fast

I am having to deal with a regression that was detected in testing and my job is quite busy. Working as fast as I can, sorry

@heath-freenome heath-freenome changed the title Fix: made small changes to utility functions to fix #3997 and #4322 Fix: made small changes to utility functions to fix #3997, #4314 and #4322 Oct 18, 2024
@heath-freenome
Copy link
Member Author

Ok, in order to avoid regressions, I added a new, optional mergeDefaultsIntoFormData prop to Experimental_DefaultFormStateBehavior which can be used to fix the issue seen in #4322

Copy link
Contributor

@nickgros nickgros left a comment

Choose a reason for hiding this comment

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

LGTM, assuming CI passes once docs build is fixed!

packages/docs/docs/api-reference/utility-functions.md Outdated Show resolved Hide resolved
Comment on lines +24 to +26
it('should return default when formData is undefined and defaultSupercedesUndefined true', () => {
expect(mergeDefaultsWithFormData({}, undefined, undefined, true)).toEqual({});
});
Copy link
Contributor

Choose a reason for hiding this comment

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

May want to add a case where null is returned when formData is null

…rjsf-team#4322

Fixes rjsf-team#3997 and rjsf-team#4322
- In `@rjsf/utils`, made the following changes:
  - Updated `mergeDefaultsWithFormData()` to not overwrite a default when the formData has an undefined value
  - Updated `getClosestMatchingOption()` to improve the scoring function so that an object container that matches a key gets an extra point
- In `@rjsf/core`, updated `MultiSchemaField` to call `onChange` after setting the new option in state rather than before
- Updated the `CHANGELOG.md` accordingly
…ta` prop to the `Experimental_DefaultFormStateBehavior`

- Updated `mergeDefaultsWithFormData()` to add new optional `defaultSupercedesUndefined` that when true uses the defaults rather than `undefined` formData
- Updated `getDefaultFormState()` to pass true to `mergeDefaultsWithFormData` for `defaultSupercedesUndefined` when `mergeDefaultsIntoFormData` has the value `useDefaultIfFormDataUndefined`
- Updated the documentation for the new capabilities
- Updated the playground to add controls for the new `mergeDefaultsIntoFormData` option
  - moved the `Show Error List` component over one column, making it inline radio buttons rather than a select
@heath-freenome heath-freenome merged commit 27e6956 into rjsf-team:main Oct 21, 2024
5 checks passed
@heath-freenome heath-freenome deleted the fix-3997-and-4322 branch October 21, 2024 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

schema with "oneOf" and default value - acts weird
3 participants