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(AnyOfControl): fix missing default combinator value bug #75

Merged
merged 6 commits into from
Apr 24, 2024

Conversation

DrewHoo
Copy link
Contributor

@DrewHoo DrewHoo commented Apr 22, 2024

This PR fixes a couple problems:

  1. When an AnyOf field is required, the selected combinator subschema should satisfy the FormItem's required rule. Removing the name property from the FormItem in AnyOfControl fixes this
  2. When an AnyOf subschema object is rendered, it needs default values created (these properties can help differentiate subschemas from one another). There appears to be an upstream bug that makes creating this default value a little more complicated (calls to handleChange are inexplicably ignored if they happen before the AnyOfControl renders a second time).

@DrewHoo DrewHoo marked this pull request as ready for review April 23, 2024 13:35
Copy link

codecov bot commented Apr 23, 2024

Codecov Report

Attention: Patch coverage is 83.33333% with 6 lines in your changes are missing coverage. Please review.

Project coverage is 76.78%. Comparing base (8ce89ee) to head (e01c02e).

Files Patch % Lines
src/common/FormStateWrapper.tsx 83.33% 1 Missing and 1 partial ⚠️
src/controls/combinators/AnyOfControl.tsx 83.33% 1 Missing and 1 partial ⚠️
.../controls/combinators/CombinatorSchemaSwitcher.tsx 33.33% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #75      +/-   ##
==========================================
+ Coverage   76.52%   76.78%   +0.25%     
==========================================
  Files          36       36              
  Lines         409      435      +26     
  Branches       69       75       +6     
==========================================
+ Hits          313      334      +21     
- Misses         76       77       +1     
- Partials       20       24       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@DrewHoo DrewHoo changed the title Fix(AnyOfControl): fix missing default combinator value bug fix(AnyOfControl): fix missing default combinator value bug Apr 23, 2024
const [renderCount, setRenderCount] = useState(1)

useEffect(() => {
// this is a janky workaround for two problems
Copy link
Contributor

Choose a reason for hiding this comment

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

is the plan to work on the fix in @jsonforms/react next?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, I'm going to file a bug though. I'm not interested in fixing it upstream because ideally we have a different approach altogether for default creation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What we're doing in the closed-source renderer is worse:

  1. we're giving the FormItem a name for a field that doesn't correspond to a property we want in the form
  2. we're setting a value for that field in a useEffect so form validation doesn't complain (TBC I made this change back in December when the bug was blocking release of splitters)

handleChange(path, newData)
}
}
if (renderCount === 1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

does this count work properly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep! this code makes the test pass

Copy link
Contributor

@elenajdanova elenajdanova left a comment

Choose a reason for hiding this comment

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

I'm approving. I see what you did but I still have questions.

  • How it wasn't an issue in the mercury-web?
  • Did you happen to have a chance to prove this is working in Add Asset form?

@DrewHoo DrewHoo merged commit 768d8c4 into main Apr 24, 2024
4 of 5 checks passed
@DrewHoo DrewHoo deleted the b/fix-missing-default-combinator-value-bug branch April 24, 2024 19:07
Copy link

🎉 This PR is included in version 1.15.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@DrewHoo
Copy link
Contributor Author

DrewHoo commented Apr 24, 2024

Did you happen to have a chance to prove this is working in Add Asset form?

Yes, I built the package locally and installed it to ensure it behaves as expected. Also my PR in mercury-web introduces a test that fails without the change included in this version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants