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(form): validator 中的 value 类型更新为 any #2406

Merged
merged 2 commits into from
Jul 3, 2024

Conversation

oasis-cloud
Copy link
Collaborator

@oasis-cloud oasis-cloud commented Jul 3, 2024

🤔 这个变动的性质是?

  • 日常 bug 修复

🔗 相关 Issue

#2339

Summary by CodeRabbit

  • 新功能

    • 在表单组件中添加了新的校验器函数,用于验证输入值的长度是否超过5个字符。
  • 改进

    • 更新了表单项规则接口中的校验器函数,现在可以接受任何类型的值,而不仅仅是字符串。

Copy link

coderabbitai bot commented Jul 3, 2024

Walkthrough

此次更改的核心在于修正和改进表单验证功能。主要包括为表单规则添加新的验证器函数,以及在 FormItemRule 接口中,将 validator 函数的参数类型从 string 改为 any,以增加类型灵活性。这样,可以适应不同类型的表单输入,而不仅限于字符串类型。

Changes

文件路径 改动概要
src/…/form/demos/taro/demo1.tsx 添加了新的验证器函数,并从 @/packages/formitem/types 导入 FormItemRuleWithoutValidator
src/…/formitem/types.ts FormItemRule 接口中的 validator 函数参数类型从 string 修改为 any
src/…/form/demos/h5/demo1.tsx 在表单组件的 rules 数组中引入新的验证器函数,验证输入值的长度是否超过 5 个字符。

Sequence Diagram(s)

不适用于此次变更。

Possibly related issues

  • jdf2e/nutui-react#2339: 此问题指出 FormItem 组件中的 validator 参数类型错误。此次变更通过将 validator 函数参数类型从 string 改为 any,解决了该问题。

Poem

白兔修代码,
表单验无忧。
类型更灵活,
所有用户求。
验证诚意足,
问题皆解透。

Tip

AI model upgrade

gpt-4o model for reviews and chat is now live

OpenAI claims that this model is better at understanding and generating code than the previous models. Please join our Discord Community to provide any feedback or to report any issues.


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between eca8ad8 and 82be780.

Files selected for processing (1)
  • src/packages/form/demos/h5/demo1.tsx (2 hunks)
Additional comments not posted (1)
src/packages/form/demos/h5/demo1.tsx (1)

3-3: 导入声明看起来不错!

导入 FormItemRuleWithoutValidator 是为了在验证规则中使用。确保这个导入在其他地方没有引起问题。


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:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

codecov bot commented Jul 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.98%. Comparing base (642285b) to head (82be780).

Additional details and impacted files
@@            Coverage Diff             @@
##             next    #2406      +/-   ##
==========================================
+ Coverage   85.96%   85.98%   +0.02%     
==========================================
  Files         217      217              
  Lines       22828    22828              
  Branches     2537     2540       +3     
==========================================
+ Hits        19623    19629       +6     
+ Misses       3200     3194       -6     
  Partials        5        5              

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

@oasis-cloud oasis-cloud linked an issue Jul 3, 2024 that may be closed by this pull request
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: 1

Comment on lines +31 to +38
{
validator: (
ruleCfg: FormItemRuleWithoutValidator,
value: string
) => {
return value.length > 5
},
},
Copy link

Choose a reason for hiding this comment

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

请更新验证器函数中的 value 类型。

验证器函数中的 value 类型应与 FormItemRule 接口中的更新保持一致。

-                value: string
+                value: any
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{
validator: (
ruleCfg: FormItemRuleWithoutValidator,
value: string
) => {
return value.length > 5
},
},
{
validator: (
ruleCfg: FormItemRuleWithoutValidator,
value: any
) => {
return value.length > 5
},
},

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

Comment on lines +25 to +32
{
validator: (
ruleCfg: FormItemRuleWithoutValidator,
value: string
) => {
return value.length > 5
},
},
Copy link

Choose a reason for hiding this comment

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

验证函数的实现需要改进。

  1. 验证函数的 value 参数类型应该与 FormItemRule 接口中的更新保持一致,即 any 类型。
  2. 验证函数返回布尔值,但没有提供错误消息。应该使用 callback 函数返回错误消息。
            {
-              validator: (
-                ruleCfg: FormItemRuleWithoutValidator,
-                value: string
-              ) => {
-                return value.length > 5
-              },
+              validator: (
+                ruleCfg: FormItemRuleWithoutValidator,
+                value: any,
+                callback: (error?: string) => void
+              ) => {
+                if (value.length > 5) {
+                  callback('字段A不能超过5个字');
+                } else {
+                  callback();
+                }
+              },
            },
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{
validator: (
ruleCfg: FormItemRuleWithoutValidator,
value: string
) => {
return value.length > 5
},
},
{
validator: (
ruleCfg: FormItemRuleWithoutValidator,
value: any,
callback: (error?: string) => void
) => {
if (value.length > 5) {
callback('字段A不能超过5个字');
} else {
callback();
}
},
},

@xiaoyatong xiaoyatong merged commit f980240 into jdf2e:next Jul 3, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FormItem 组件 rules 都 validator 类型错误
2 participants