Skip to content

feat: setValues合并算法支持嵌套对象赋值,解决嵌套对象无法正常初始化问题 #6352

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

1455668754
Copy link

@1455668754 1455668754 commented Jun 9, 2025

setValues合并算法支持嵌套对象赋值,解决嵌套对象无法正常初始化问题

Summary by CodeRabbit

  • New Features

    • Improved handling of form value updates with enhanced merging and filtering logic, ensuring more precise updates when setting form values.
  • Bug Fixes

    • Resolved issues where form updates could unintentionally overwrite or omit nested fields, leading to more reliable form behavior.

Copy link

changeset-bot bot commented Jun 9, 2025

⚠️ No Changeset found

Latest commit: 5aa1316

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Jun 9, 2025

Walkthrough

The update replaces the previous object merging utility in the form API with a custom deep merge function and introduces a new helper to pick specific fields from objects using nested paths. The setValues method now merges and filters form values more explicitly before updating the form, ensuring only schema-defined fields are set.

Changes

File(s) Change Summary
packages/@core/ui-kit/form-ui/src/form-api.ts Replaced merge utility with custom deep merge (fieldMergeFn), added pickFields helper, and updated setValues to use these for controlled merging and filtering of form values.

Poem

In the garden of code where the forms gently grow,
A merge now runs deeper, as new helpers bestow.
Only fields that belong, in the schema they stay,
With careful selection, stray values kept at bay.
A rabbit hops by, with a satisfied cheer—
"Your forms are now tidier, the path is more clear!" 🐇

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/@core/ui-kit/form-ui/src/form-api.ts (1)

368-397: Consider adding support for array indices in field paths.

The current implementation doesn't support array indices in paths (e.g., 'items.0.name'). If your form schemas use array fields with indexed access, consider extending the function to handle numeric keys.

Would you like me to provide an implementation that supports array indices in field paths?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e6bfbce and 5aa1316.

📒 Files selected for processing (1)
  • packages/@core/ui-kit/form-ui/src/form-api.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/@core/ui-kit/form-ui/src/form-api.ts (2)
packages/@core/base/shared/src/utils/inference.ts (1)
  • isObject (160-160)
packages/@core/base/shared/src/utils/date.ts (2)
  • isDate (20-22)
  • isDayjsObject (24-26)
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Test (windows-latest)
  • GitHub Check: Check (ubuntu-latest)
  • GitHub Check: Check (windows-latest)
  • GitHub Check: Lint (windows-latest)
  • GitHub Check: post-update (windows-latest)
  • GitHub Check: post-update (ubuntu-latest)
🔇 Additional comments (3)
packages/@core/ui-kit/form-ui/src/form-api.ts (3)

295-351: LGTM! The deep merge implementation handles nested objects correctly.

The fieldMergeFn function properly implements deep merging with appropriate handling for arrays, Date/Dayjs objects, and null/undefined values. This aligns well with the PR objective of supporting nested object assignment.


399-403: Well-structured implementation for filtered nested object merging.

The approach of first merging with fieldMergeFn and then filtering with pickFields ensures that nested objects are properly merged while maintaining schema integrity. This effectively solves the nested object initialization problem mentioned in the PR objectives.


379-379: Fix the falsy value handling in field extraction.

The condition value && typeof value === 'object' will incorrectly skip falsy values like 0, false, or empty strings. This could lead to data loss when extracting fields with falsy values.

Apply this diff to fix the falsy value handling:

-          if (value && typeof value === 'object' && key in value) {
+          if (value !== null && value !== undefined && typeof value === 'object' && key in value) {

Likely an incorrect or invalid review comment.

@jinmao88
Copy link
Collaborator

能否提供一个测试demo

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.

2 participants