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: needConfirm false should not trigger open in SinglePicker #914

Merged
merged 1 commit into from
Feb 27, 2025

Conversation

zombieJ
Copy link
Member

@zombieJ zombieJ commented Feb 27, 2025

fix ant-design/ant-design#52973

Summary by CodeRabbit

  • Bug Fixes
    • 优化了选择器组件的交互逻辑:当操作无需确认时,选择器不再自动展开,避免了意外触发,确保用户操作更加精准和流畅,整体体验更为直观。

Copy link

vercel bot commented Feb 27, 2025

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

Name Status Preview Comments Updated (UTC)
picker ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 27, 2025 3:33am

Copy link

coderabbitai bot commented Feb 27, 2025

Walkthrough

该变更主要涉及三个方面:从 jest.config.js 中移除了 setupFiles 属性,仅保留覆盖率相关配置;在 src/PickerInput/SinglePicker.tsx 中删除了在特定条件下自动调用 triggerOpen(true); 的代码,从而改变了 picker 的状态切换逻辑;同时在 tests/new-range.spec.tsx 中新增了测试用例,用于验证在 !needConfirm 状态下 DayPicker 组件的行为。

Changes

文件 更改摘要
jest.config.js 移除 setupFiles: ['./tests/setup.js'] 配置;其他配置保持不变。
src/PickerInput/SinglePicker.tsx 移除 useLayoutEffect 中的 triggerOpen(true);,防止在特定条件下自动打开选择器。
tests/new-range.spec.tsx 添加新测试用例 not trigger open when !needConfirm,验证 DayPicker 组件在无需确认时 onOpenChange 的行为。

Sequence Diagram(s)

sequenceDiagram
  participant User as 用户
  participant DayPicker as DayPicker 组件
  participant Callback as onOpenChange 回调
  
  User->>DayPicker: 打开选择器
  DayPicker->>Callback: 调用 onOpenChange(true)
  User->>DayPicker: 点击外部区域
  DayPicker->>Callback: 调用 onOpenChange(false)
Loading
sequenceDiagram
  participant Component as SinglePicker 组件
  participant Hook as useLayoutEffect
  
  Component->>Hook: 检查条件(复杂选择器、无需确认、panel操作)
  Note right of Hook: 之前会调用 triggerOpen(true)
  Hook--)Component: 现不再触发 triggerOpen 调用
  Component->>Component: 直接执行 triggerConfirm() 进行确认逻辑
Loading

Possibly related PRs

Suggested reviewers

  • afc163

Poem

嗨,我是一只小兔子在代码园中蹦跳,
发现配置精简,如同草丛里的跳跃。
Picker 的逻辑改变,安静而温柔,
测试用例奏响,确保稳如老树。
我的心随代码欢唱,🐰
在新变更中畅快跳跃!

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/new-range.spec.tsx

Oops! Something went wrong! :(

ESLint: 8.57.1

Error: Cannot read config file: /.eslintrc.js
Error: Cannot find module '@umijs/fabric/dist/eslint'
Require stack:

  • /.eslintrc.js
  • /node_modules/.pnpm/@eslint[email protected]/node_modules/@eslint/eslintrc/dist/eslintrc.cjs
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/lib/cli-engine/cli-engine.js
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/lib/eslint/eslint.js
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/lib/eslint/index.js
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/lib/cli.js
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/bin/eslint.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1248:15)
    at Function.resolve (node:internal/modules/helpers:145:19)
    at Object. (/.eslintrc.js:2:21)
    at Module._compile (node:internal/modules/cjs/loader:1546:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1691:10)
    at Module.load (node:internal/modules/cjs/loader:1317:32)
    at Module._load (node:internal/modules/cjs/loader:1127:12)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:217:24)
    at Module.require (node:internal/modules/cjs/loader:1339:12)

📜 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 8a420c4 and b88d12c.

📒 Files selected for processing (3)
  • jest.config.js (0 hunks)
  • src/PickerInput/SinglePicker.tsx (0 hunks)
  • tests/new-range.spec.tsx (1 hunks)
💤 Files with no reviewable changes (2)
  • jest.config.js
  • src/PickerInput/SinglePicker.tsx
🔇 Additional comments (1)
tests/new-range.spec.tsx (1)

789-813: 测试用例清晰地验证了 needConfirm 为 false 时的行为

这个测试用例很好地验证了当 needConfirm 设置为 false 时,点击日期单元格不会自动触发 picker 的重新打开,同时确保了点击外部区域能正确关闭 picker。测试覆盖了 PR 描述中提到的修复点,确保 SinglePicker 在 needConfirmfalse 的情况下有正确的行为。

测试逻辑结构合理:

  1. 模拟打开 picker
  2. 验证 onOpenChange 被调用并传入 true
  3. 点击日期单元格
  4. 模拟点击外部区域关闭 picker
  5. 验证 onOpenChange 再次被调用并传入 false

这与 PR 中提到的修复(从 SinglePicker.tsx 中移除自动调用 triggerOpen(true) 的代码)是匹配的。

✨ Finishing Touches
  • 📝 Generate Docstrings

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 generate docstrings to generate docstrings 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

codecov bot commented Feb 27, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.79%. Comparing base (ec4f698) to head (b88d12c).
Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #914      +/-   ##
==========================================
+ Coverage   98.71%   98.79%   +0.07%     
==========================================
  Files          64       64              
  Lines        2652     2649       -3     
  Branches      736      708      -28     
==========================================
- Hits         2618     2617       -1     
+ Misses         31       29       -2     
  Partials        3        3              

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

@zombieJ zombieJ merged commit 7bf946c into master Feb 27, 2025
12 checks passed
@zombieJ zombieJ deleted the fix-confirm branch February 27, 2025 03:37
zombieJ added a commit that referenced this pull request Feb 27, 2025
* fix: needConfirm false should not trigger open in SinglePicker (#914)

* chore: clean up

* chore: update script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant