setValues合并算法支持嵌套对象赋值,解决嵌套对象无法正常初始化问题#6315
Conversation
setValues合并算法支持嵌套对象赋值,解决嵌套对象无法正常初始化问题
|
|
Caution Review failedThe pull request is closed. WalkthroughThe update replaces the use of a generic Changes
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 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
fieldMergeFnfunction 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
createMergeapproach.🧰 Tools
🪛 Biome (1.9.4)
[error] 314-315: expected
,but instead foundfilterFieldsRemove filterFields
(parse)
[error] 315-315: expected
,but instead found:Remove :
(parse)
[error] 315-315: expected
,but instead foundshouldValidateRemove 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
pickFieldsfunction 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 throughpickFieldsbefore calling existinghandleStringToArrayFieldsandform.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 jsLength 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) appliesfieldMergeFn→pickFields→handleStringToArrayFields→form.setValues. I searched for existingform.setValuescalls 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
createMergeis only defined (but not used elsewhere) inpackages/@core/base/shared/src/utils/merge.ts.• Add or update unit tests for
form-api.tsto 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.
|
根据AI提示 完善一下 |
|
同步了下本地代码 多copy了个方法 |
setValues合并算法支持嵌套对象赋值,解决嵌套对象无法正常初始化问题
Summary by CodeRabbit