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: 受控模式下返回的selectedOptions进行校验处理 #2951

Merged
merged 2 commits into from
Jan 23, 2025

Conversation

irisSong
Copy link
Collaborator

@irisSong irisSong commented Jan 20, 2025

#2924

Summary by CodeRabbit

  • 新功能
    • 优化日期选择器组件的日期选择逻辑
    • 改进了日期、月日和日期时间类型的选项处理方式
    • 增强了选择日期时的选项设置准确性

Copy link

coderabbitai bot commented Jan 20, 2025

变更概览

演练

这个变更修改了 DatePicker 组件中的 handlePickerChange 函数。新增的条件块检查 selectedOptions 数组的长度和 rangeType 的类型。对于 'date'、'month-day' 或 'datetime' 类型,函数使用 formatOption 创建 dayOption,并根据不同的 rangeType 更新 selectedOptions 数组中的特定元素。

变更

文件路径 变更摘要
src/packages/datepicker/datepicker.taro.tsx handlePickerChange 函数中新增条件块,根据 rangeType 更新 selectedOptions 数组
src/packages/datepicker/datepicker.tsx 类似地修改 handlePickerChange 函数,增加日期选项处理逻辑

可能相关的 PR

建议标签

2.x

建议审阅者

  • xiaoyatong
  • oasis-cloud

诗歌

🐰 日期选择器,魔法般精巧
选项跳舞,时间轻轻飘
月、日、时刻,精准入怀
代码如诗,跳动的节奏
兔子微笑,变更已完成 🕰️


📜 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 1800f12 and 43a6c5d.

📒 Files selected for processing (2)
  • src/packages/datepicker/datepicker.taro.tsx (1 hunks)
  • src/packages/datepicker/datepicker.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/packages/datepicker/datepicker.taro.tsx
  • src/packages/datepicker/datepicker.tsx
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build

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. (Beta)
  • @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.

@github-actions github-actions bot added the 2.x label Jan 20, 2025
Copy link

codecov bot commented Jan 20, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.20%. Comparing base (2571c8d) to head (43a6c5d).
Report is 6 commits behind head on next.

Additional details and impacted files
@@            Coverage Diff             @@
##             next    #2951      +/-   ##
==========================================
+ Coverage   84.02%   84.20%   +0.18%     
==========================================
  Files         220      267      +47     
  Lines       17917    18125     +208     
  Branches     2628     2671      +43     
==========================================
+ Hits        15055    15263     +208     
  Misses       2857     2857              
  Partials        5        5              

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

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 16fb6e5 and 1800f12.

📒 Files selected for processing (2)
  • src/packages/datepicker/datepicker.taro.tsx (1 hunks)
  • src/packages/datepicker/datepicker.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (1)
src/packages/datepicker/datepicker.taro.tsx (1)

273-286: 代码变更与 Web 版本保持一致!

Taro 版本的修复与 Web 版本完全一致,这确保了在不同环境下组件行为的一致性。

Comment on lines 273 to 286

if (
selectedOptions.length >= 2 &&
(rangeType === 'date' ||
rangeType === 'month-day' ||
rangeType === 'datetime')
) {
const dayOption = formatOption('day', day)
if (rangeType === 'month-day') {
selectedOptions[1] = dayOption
} else {
selectedOptions[2] = dayOption
}
}
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

需要补充 selectedOptions 数组更新逻辑的测试用例!

当前测试文件缺少对新增逻辑的覆盖。建议添加以下测试场景:

  • 验证 'date' 类型时 selectedOptions[2] 的日期更新
  • 验证 'month-day' 类型时 selectedOptions[1] 的日期更新
  • 验证 'datetime' 类型时 selectedOptions[2] 的日期更新
  • 验证当 selectedOptions.length < 2 时的边界情况

示例测试用例位置:src/packages/datepicker/__test__/datepicker.spec.tsx

🔗 Analysis chain

修复了 selectedOptions 的校验和更新逻辑!

代码变更正确地处理了不同日期类型下 selectedOptions 数组中日期选项的更新。这个修复确保了在受控模式下返回的选项数据的准确性。

建议:

  1. 为这个修复添加单元测试,覆盖以下场景:
    • 'date' 类型的日期选择
    • 'month-day' 类型的日期选择
    • 'datetime' 类型的日期选择
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 检查是否存在相关的测试用例
rg -l "test.*date.*selectedOptions|test.*month-day.*selectedOptions|test.*datetime.*selectedOptions" --type ts --type tsx

Length of output: 151


Script:

#!/bin/bash
# Search for test files related to datepicker
echo "=== Searching in .ts files ==="
rg -l "test.*datepicker.*selectedOptions" --type ts

echo "=== Looking for datepicker test files ==="
fd "datepicker.*(test|spec)\.(ts|tsx)$"

echo "=== Searching content in potential test files ==="
rg "selectedOptions.*date|selectedOptions.*month-day|selectedOptions.*datetime" --type ts -A 5

Length of output: 518


Script:

#!/bin/bash
# View the content of the test file
echo "=== Datepicker test file content ==="
cat src/packages/datepicker/__test__/datepicker.spec.tsx

Length of output: 4978

Copy link
Collaborator

@xiaoyatong xiaoyatong left a comment

Choose a reason for hiding this comment

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

需要关注下 datehour 的情况

@irisSong
Copy link
Collaborator Author

需要关注下 datehour 的情况
已修改

@xiaoyatong xiaoyatong merged commit 3300424 into next Jan 23, 2025
6 checks passed
@xiaoyatong xiaoyatong deleted the next-picker-issue branch January 23, 2025 06:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants