Skip to content

Conversation

zombieJ
Copy link
Member

@zombieJ zombieJ commented Jul 11, 2025

close #752
fix ant-design/ant-design#53981

Summary by CodeRabbit

  • 新功能
    • 当通过表单方法设置字段值时,该字段会自动标记为已触碰(touched)。
  • 测试
    • 增强了相关测试用例,验证设置字段值后字段的触碰状态变化是否符合预期。

Copy link

coderabbitai bot commented Jul 11, 2025

Walkthrough

本次变更在 FormStore 类的 setFieldValue 方法中,调用 setFields 时新增了 touched: true 属性,从而在设置字段值时同步将该字段标记为已触碰。同时,相关测试用例增加了对 touched 状态的断言,确保行为符合预期。

Changes

文件/分组 变更摘要
src/useForm.ts FormStore.setFieldValue 方法中,调用 setFields 时增加 touched: true 标记。
tests/index.test.tsx 增加断言,验证 setFieldValue 前后字段的 touched 状态变化,确保仅被设置的字段被标记为 touched。

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant FormStore
    participant Field

    User->>FormStore: setFieldValue(fieldName, value)
    FormStore->>FormStore: setFields([{ name: fieldName, value, touched: true }])
    FormStore->>Field: 更新字段值和 touched 状态
Loading

Assessment against linked issues

Objective Addressed Explanation
优化 setFieldValue 设置字段值时同步标记 touched 状态,确保行为一致 (#752, #53981)
修正/新增测试,验证 setFieldValue 后 touched 状态正确 (#752)

Possibly related PRs

Poem

兔子点点小爪爪,
字段 touched 记得加。
setFieldValue 不再傻,
一致行为人人夸。
测试通过笑哈哈,
代码整齐没疏漏,
兔子乐在新变化! 🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

tests/index.test.tsx

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the config "prettier" to extend from. Please check that the name of the config is correct.

The config "prettier" was referenced from the config file in "/.eslintrc.js".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.

src/useForm.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the config "prettier" to extend from. Please check that the name of the config is correct.

The config "prettier" was referenced from the config file in "/.eslintrc.js".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.


📜 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 b0209d0 and 4273430.

📒 Files selected for processing (2)
  • src/useForm.ts (1 hunks)
  • tests/index.test.tsx (2 hunks)
🔇 Additional comments (4)
src/useForm.ts (1)

815-815: 正确实现了 setFieldValue 应该标记字段为已触碰的需求

添加 touched: true 属性确保了通过 setFieldValue 程序化设置字段值时,该字段会被标记为已触碰状态。这符合用户期望,因为程序化的字段值更改应该与用户交互具有相同的行为表现。

tests/index.test.tsx (3)

888-890: 良好的测试覆盖:验证初始触碰状态

正确验证了字段的初始触碰状态为 false,为后续测试 setFieldValue 的行为建立了基准。


902-905: 全面验证了 setFieldValue 的触碰状态行为

测试用例正确验证了调用 setFieldValue 后目标字段的触碰状态变为 true,确保了新功能按预期工作。


907-909: 优秀的边界情况测试:验证其他字段不受影响

测试验证了其他字段的触碰状态保持不变,确保 setFieldValue 的影响范围精确且不会产生副作用。这是一个重要的测试用例,证明了实现的准确性。

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-set

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 auto-generate unit tests to generate unit tests for 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

vercel bot commented Jul 11, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
field-form ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 11, 2025 3:38am

Copy link

codecov bot commented Jul 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.53%. Comparing base (b0209d0) to head (4273430).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #759   +/-   ##
=======================================
  Coverage   99.53%   99.53%           
=======================================
  Files          19       19           
  Lines        1287     1287           
  Branches      319      319           
=======================================
  Hits         1281     1281           
  Misses          6        6           

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@zombieJ zombieJ merged commit 6d539aa into master Jul 11, 2025
13 checks passed
@zombieJ zombieJ deleted the fix-set branch July 11, 2025 06:17
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.

The behavior of form.setFieldValue and form.setFieldsValue is inconsistent.
1 participant