Skip to content

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

Closed
xueyitt wants to merge 6 commits into
vbenjs:mainfrom
xueyitt:main
Closed

setValues合并算法支持嵌套对象赋值,解决嵌套对象无法正常初始化问题#6315
xueyitt wants to merge 6 commits into
vbenjs:mainfrom
xueyitt:main

Conversation

@xueyitt
Copy link
Copy Markdown
Contributor

@xueyitt xueyitt commented May 30, 2025

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

Summary by CodeRabbit

  • Bug Fixes
    • Improved how form values are merged when updating, ensuring better handling of nested objects, arrays, and special data types.
  • Refactor
    • Enhanced the merging logic for form values to provide more accurate and reliable updates.

setValues合并算法支持嵌套对象赋值,解决嵌套对象无法正常初始化问题
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 30, 2025

⚠️ No Changeset found

Latest commit: ea32895

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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 30, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The update replaces the use of a generic createMerge utility in the FormApi class's setValues method with a custom deep merge function, fieldMergeFn. This function merges objects recursively with special handling for arrays, primitives, Date, and Dayjs types, and introduces pickFields to filter merged values by schema fields before setting them.

Changes

File(s) Change Summary
packages/@core/ui-kit/form-ui/src/form-api.ts Replaced createMerge with a custom deep merge function fieldMergeFn in setValues; added pickFields helper to filter fields by schema.

Poem

In the warren of code, a merge was reborn,
Deep in the fields where the carrots are shorn.
Arrays leap ahead, objects dig down,
Dates and Dayjs wear a clever crown.
Now values combine with a hop and a cheer—
The form’s never looked so crystal clear! 🥕


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 600a9ed and ea32895.

📒 Files selected for processing (1)
  • packages/@core/ui-kit/form-ui/src/form-api.ts (1 hunks)
✨ 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
Copy Markdown
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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7e4abc2 and 600a9ed.

📒 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)
🪛 Biome (1.9.4)
packages/@core/ui-kit/form-ui/src/form-api.ts

[error] 310-310: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 311-311: expected , but instead found :

Remove :

(parse)


[error] 314-315: expected , but instead found filterFields

Remove filterFields

(parse)


[error] 315-315: expected , but instead found :

Remove :

(parse)


[error] 315-315: expected , but instead found shouldValidate

Remove shouldValidate

(parse)


[error] 315-315: expected , but instead found :

Remove :

(parse)


[error] 317-317: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)

🪛 GitHub Actions: CI
packages/@core/ui-kit/form-ui/src/form-api.ts

[error] 303-303: SyntaxError: Unexpected keyword or identifier at line 303, likely related to 'async' keyword usage.

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: post-update (ubuntu-latest)
  • GitHub Check: post-update (windows-latest)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (3)
packages/@core/ui-kit/form-ui/src/form-api.ts (3)

314-370: Excellent implementation of custom deep merge algorithm.

The fieldMergeFn function provides a sophisticated deep merge strategy that properly handles the requirements for nested object assignment:

  • Preserves existing values when source is null/undefined
  • Directly replaces arrays (avoiding complex array merging issues)
  • Recursively merges objects while excluding Date/Dayjs objects
  • Maintains type safety with proper object detection

This addresses the PR objective of supporting nested object assignment much better than the previous createMerge approach.

🧰 Tools
🪛 Biome (1.9.4)

[error] 314-315: expected , but instead found filterFields

Remove filterFields

(parse)


[error] 315-315: expected , but instead found :

Remove :

(parse)


[error] 315-315: expected , but instead found shouldValidate

Remove shouldValidate

(parse)


[error] 315-315: expected , but instead found :

Remove :

(parse)


[error] 317-317: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


372-416: Well-designed utility for nested field extraction.

The pickFields function elegantly handles nested field paths (e.g., 'user.address.city') and builds the appropriate nested structure. The implementation correctly:

  • Splits field paths and traverses nested objects
  • Only assigns values for existing paths
  • Creates intermediate objects as needed
  • Gracefully handles missing paths

This complements the merge algorithm perfectly for filtering schema-defined fields.


418-425:

Details

❓ Verification inconclusive

Verify the integration of new merge algorithm with existing workflow.

The integration looks correct - it merges form values with new fields using fieldMergeFn, then filters the result through pickFields before calling existing handleStringToArrayFields and form.setValues. However, ensure this change doesn't break existing form validation or field processing logic.


🏁 Script executed:

#!/bin/bash
# Description: Search for any existing tests or usage of setValues method to verify compatibility
# Expected: Find test cases and usage patterns that should still work with the new implementation

# Search for setValues method usage in tests
rg -A 10 "setValues" --type ts --type js | head -50

# Search for any references to createMerge that might have been missed
rg "createMerge" --type ts --type js

Length of output: 3676


Verify form merge flow and test coverage

The updated flow in packages/@core/ui-kit/form-ui/src/form-api.ts (lines 418–425) applies fieldMergeFnpickFieldshandleStringToArrayFieldsform.setValues. I searched for existing form.setValues calls and found usage in:

  • apps/web-ele/src/views/demos/form/basic.vue
  • apps/web-ele/src/views/_core/authentication/login.vue
  • playground/src/views/examples/modal/form-modal-demo.vue

No direct unit tests cover this merged workflow, and createMerge is only defined (but not used elsewhere) in packages/@core/base/shared/src/utils/merge.ts.

• Add or update unit tests for form-api.ts to include scenarios with merged defaults, filtered fields, string-to-array conversion, and validation.
• Manually verify key form examples listed above to ensure no regressions in value setting or validation.

Comment thread packages/@core/ui-kit/form-ui/src/form-api.ts
@jinmao88
Copy link
Copy Markdown
Collaborator

jinmao88 commented Jun 8, 2025

根据AI提示 完善一下

@xueyitt xueyitt closed this Jun 9, 2025
@xueyitt
Copy link
Copy Markdown
Contributor Author

xueyitt commented Jun 9, 2025

同步了下本地代码 多copy了个方法

@github-actions github-actions Bot locked and limited conversation to collaborators Jul 10, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants