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(FormItem): 修复initialValue属性初始化未被正确加入到Formstore中导致的问题 #2247

Merged
merged 8 commits into from
May 24, 2024

Conversation

Alex-huxiyang
Copy link
Collaborator

@Alex-huxiyang Alex-huxiyang commented May 13, 2024

Taro和H5同样的改动

  • 日常 bug 修复

Summary by CodeRabbit

  • 新功能

    • 增加了表单项和表单初始值设置的功能。
  • 测试

    • 添加了针对表单项和表单初始值设置的测试用例,包括表单和表单项同时设置初始值及提交的场景。

Copy link

codecov bot commented May 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.79%. Comparing base (d4c0049) to head (9903def).
Report is 4 commits behind head on next.

Additional details and impacted files
@@           Coverage Diff           @@
##             next    #2247   +/-   ##
=======================================
  Coverage   85.78%   85.79%           
=======================================
  Files         217      217           
  Lines       22783    22795   +12     
  Branches     2481     2485    +4     
=======================================
+ Hits        19545    19557   +12     
  Misses       3233     3233           
  Partials        5        5           

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

Copy link

coderabbitai bot commented May 16, 2024

Walkthrough

此次更新主要集中在表单和表单项的初始值设置功能。为表单项和表单添加了初始值的测试,并在FormItem组件的componentDidMount方法中增加了逻辑,以根据特定条件设置字段的初始值。

Changes

文件路径 变更摘要
src/packages/form/__tests__/form.spec.tsx 添加了测试用例,以验证表单和表单项的初始值设置,包括提交时的场景。
src/packages/formitem/formitem.taro.tsx 更新了FormItem类的componentDidMount方法,增加了根据特定条件设置字段初始值的逻辑。
src/packages/formitem/formitem.tsx FormItem类的componentDidMount方法中添加了逻辑,以根据特定条件设置字段值。

🐰✨

表单初始值,今朝新添,
测试覆盖,万事皆安。
逻辑更新,组件绽放,
代码如诗,程序如画。


Recent Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between eeda421 and 9903def.
Files selected for processing (3)
  • src/packages/form/tests/form.spec.tsx (1 hunks)
  • src/packages/formitem/formitem.taro.tsx (2 hunks)
  • src/packages/formitem/formitem.tsx (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • src/packages/form/tests/form.spec.tsx
  • src/packages/formitem/formitem.taro.tsx
  • src/packages/formitem/formitem.tsx

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:

Note: Auto-reply has been disabled for this repository by the repository owner. 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.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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

@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: 2

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between d4c0049 and 8cccfdd.
Files selected for processing (2)
  • src/packages/formitem/formitem.taro.tsx (2 hunks)
  • src/packages/formitem/formitem.tsx (1 hunks)
Additional Context Used
GitHub Check Runs (1)
codecov/patch failure (2)

src/packages/formitem/formitem.tsx: [warning] 82-82: src/packages/formitem/formitem.tsx#L82
Added line #L82 was not covered by tests


src/packages/formitem/formitem.tsx: [warning] 84-85: src/packages/formitem/formitem.tsx#L84-L85
Added lines #L84 - L85 were not covered by tests

Additional comments not posted (6)
src/packages/formitem/formitem.tsx (3)

76-85: 代码看起来不错!请确保所有调用 setFieldsValue 的地方都符合新的逻辑。


Line range hint 111-111: 代码看起来不错!


Line range hint 157-157: 代码看起来不错!

src/packages/formitem/formitem.taro.tsx (3)

76-85: 代码看起来不错!请确保所有调用 setFieldsValue 的地方都符合新的逻辑。


111-111: 代码看起来不错!


Line range hint 157-157: 代码看起来不错!

src/packages/formitem/formitem.tsx Outdated Show resolved Hide resolved
src/packages/formitem/formitem.taro.tsx Outdated Show resolved Hide resolved
@pull-request-size pull-request-size bot added size/M and removed size/S labels May 16, 2024
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

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 8cccfdd and b36cab4.
Files selected for processing (1)
  • src/packages/form/tests/form.spec.tsx (1 hunks)
Additional comments not posted (3)
src/packages/form/__tests__/form.spec.tsx (3)

25-36: 新增的测试用例验证了在 Form.Item 中设置 initialValue 的功能,测试逻辑正确。


38-49: 新增的测试用例验证了在 FormForm.Item 中同时设置 initialValue 的功能,测试逻辑正确。


38-49: 新增的测试用例验证了在 FormForm.Item 中同时设置不同的 initialValue 的功能,测试逻辑正确。

Copy link
Collaborator

@oasis-cloud oasis-cloud left a comment

Choose a reason for hiding this comment

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

需要覆盖到 reset 方法

@@ -73,6 +73,10 @@
}

componentDidMount() {
const { setFieldsValue } = this.context
if (this.props.initialValue) {
setFieldsValue({ [this.props.name || '']: this.props.initialValue })
Copy link
Collaborator

Choose a reason for hiding this comment

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

应该使用 setInitialValues,来设置初始值,并需要检查 初始值中是否已经设置过此字段,如果设置了,则跳过 formitem 的设置逻辑。可以参考 form 设置 initialvalues 的方式。

@oasis-cloud oasis-cloud merged commit 23e64e0 into next May 24, 2024
5 checks passed
@oasis-cloud oasis-cloud deleted the hxy/0513/form branch July 2, 2024 09:33
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.

Form表单Form.Item的initialValue不会赋值到formInstance.store,导致initialValue校验失败
3 participants