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 :when rules change trigger validate #727

Closed
wants to merge 1 commit into from
Closed

fix :when rules change trigger validate #727

wants to merge 1 commit into from

Conversation

sakuraee
Copy link

@sakuraee sakuraee commented Oct 5, 2024

Fixes: ant-design/ant-design#51008

Summary by CodeRabbit

  • 新功能
    • 增强了字段组件的动态验证能力,确保字段的验证状态始终与其属性保持同步。
  • 样式
    • 进行了小幅格式调整,移除了不必要的空白和注释。

Copy link

vercel bot commented Oct 5, 2024

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 Oct 5, 2024 4:09pm

Copy link

coderabbitai bot commented Oct 5, 2024

Walkthrough

此次更改在Field类组件中引入了一个新的方法componentDidUpdate,该方法用于检测rules属性的变化。通过使用rc-util中的isEqual函数比较前后rules,如果检测到变化,则调用validateRules方法以重新验证字段。这一更改使组件能够动态响应验证规则的变化,确保字段的验证状态与其属性保持同步。此外,还进行了轻微的格式调整,如去除不必要的空白和注释,但这些并不影响代码的功能或逻辑。

Changes

文件 更改摘要
src/Field.tsx 添加了public componentDidUpdate({ rules: prevRules })方法;进行了一些格式调整。

Assessment against linked issues

Objective Addressed Explanation
当rules为空数组时,能正确的将错误信息去掉 (51008)

Poem

在田野间跳跃的兔子,
规则变动我不怕,
错误信息轻轻去,
验证更新乐无涯!
兔子欢快舞蹈,
代码清晰如晨霞。 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 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

@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

🧹 Outside diff range and nitpick comments (2)
src/Field.tsx (2)

163-167: 新增的 componentDidUpdate 方法有效解决了问题,但可以进行小优化

这个新增的方法很好地解决了当规则变为空数组时验证错误仍然存在的问题。实现逻辑正确,符合 PR 的目标。

不过,我们可以对条件检查进行一个小的优化:

建议将条件检查改为:

- if (!isEqual(prevRules,this.props.rules)) {
+ if (!isEqual(prevRules, this.props.rules)) {

这样可以改善代码的可读性,保持一致的代码风格。


Line range hint 1-1000: 总体评估:变更有效且影响范围可控

此次修改通过添加 componentDidUpdate 方法成功解决了 PR 中描述的问题。具体来说:

  1. 新增的方法与现有的 Field 类结构集成良好。
  2. 变更没有对代码的其他部分产生负面影响。
  3. 实现逻辑符合预期,能够在规则发生变化时触发重新验证。

建议:

  1. 考虑添加单元测试,以确保这个新功能在各种场景下都能正常工作。
  2. 更新相关文档,说明这个新的行为,特别是对于动态改变规则的用户来说可能很重要。
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 38c629a and 00c59af.

📒 Files selected for processing (1)
  • src/Field.tsx (1 hunks)


public componentDidUpdate({ rules: prevRules }) {
if (!isEqual(prevRules,this.props.rules)) {
this.validateRules();
Copy link
Member

Choose a reason for hiding this comment

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

这个不对的,validateRules 和 validateTrigger 相关。ant-design/ant-design#51008 里遇到的是手工调用 validateFields 没有更新的问题。而不是 rules 更新后没有自动更新的问题。

Copy link
Author

Choose a reason for hiding this comment

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

奥奥我理解错了......我再看看

@sakuraee sakuraee closed this Oct 10, 2024
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.

动态规则rules为空时,已校验出的错误无法被消除
2 participants