Skip to content

fix(calendar): 类型修订#3292

Merged
Miles-hxy merged 2 commits intojdf2e:feat_v3.xfrom
xiaoyatong:fix3/7calendar
Jul 4, 2025
Merged

fix(calendar): 类型修订#3292
Miles-hxy merged 2 commits intojdf2e:feat_v3.xfrom
xiaoyatong:fix3/7calendar

Conversation

@xiaoyatong
Copy link
Collaborator

@xiaoyatong xiaoyatong commented Jul 1, 2025

🤔 这个变动的性质是?

  • 新特性提交
  • 日常 bug 修复
  • 站点、文档改进
  • 演示代码改进
  • 组件样式/交互改进
  • TypeScript 定义更新
  • 包体积优化
  • 性能优化
  • 功能增强
  • 国际化改进
  • 重构
  • 代码风格优化
  • 测试用例
  • 分支合并
  • 其他改动(是关于什么的改动?)

🔗 相关 Issue

💡 需求背景和解决方案

☑️ 请求合并前的自查清单

⚠️ 请自检并全部勾选全部选项⚠️

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • TypeScript 定义已补充或无须补充
  • fork仓库代码是否为最新避免文件冲突
  • Files changed 没有 package.json lock 等无关文件

Summary by CodeRabbit

  • 新功能

    • 日历组件的 onDayClick 回调参数由单个字符串调整为字符串数组,支持多日期选择。
    • CalendarDay 类型新增可选的 monthyear 属性。
  • 样式

    • 日历相关演示组件的 select 回调参数类型同步为字符串数组。
  • 重构

    • 日历和日历项组件的回调函数默认参数类型统一为无参数函数,提升一致性。
    • 日期工具函数内部属性命名规范化,与全局保持一致。

@github-actions github-actions bot added 3.x Target branch 3.x action:review This PR needs more reviews (less than 2 approvals) labels Jul 1, 2025
@coderabbitai
Copy link

coderabbitai bot commented Jul 1, 2025

"""

Walkthrough

此次变更统一了日历组件及相关演示、类型定义中关于日期点击回调(onDayClick)的参数类型,由原先的单个字符串调整为字符串数组。同时,部分默认回调函数参数类型也做了相应简化,相关类型定义与属性命名进行了同步更新。

Changes

文件/分组 变更摘要
src/packages/calendar/calendar.tsx
src/packages/calendar/calendar.taro.tsx
onDayClick 回调参数类型由 string 改为 string[],相关默认回调签名同步调整
src/packages/calendar/demos/h5/demo1.tsx
src/packages/calendar/demos/h5/demo2.tsx
src/packages/calendar/demos/h5/demo8.tsx
src/packages/calendar/demos/taro/demo1.tsx
src/packages/calendar/demos/taro/demo2.tsx
src/packages/calendar/demos/taro/demo8.tsx
演示代码中 select 回调参数类型由 string 改为 string[]
src/packages/calendaritem/calendaritem.tsx
src/packages/calendaritem/calendaritem.taro.tsx
onDayClickonConfirmonPageChange 回调类型与默认实现调整,onDayClick 由单字符串参数改为字符串数组
src/types/spec/calendar/base.ts CalendarDay 类型新增可选 monthyear 属性,onDayClick 回调签名同步为 string[]
src/packages/calendar/tests/calendar.spec.tsx CalendarDay 类型导入路径由 @/packages/calendar/types 改为 @/types
src/utils/date.ts getPreMonthDates 返回对象属性名由 preYear/preMonth 改为 year/month

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CalendarComponent
    participant ParentComponent

    User->>CalendarComponent: 点击日期
    CalendarComponent->>ParentComponent: onDayClick(selectedDates: string[])
Loading

Suggested reviewers

  • Alex-huxiyang
  • oasis-cloud

Poem

小兔挥爪改日历,
单日变数组,类型齐。
回调参数皆统一,
代码整洁更欢喜。
月年属性新登场,
跳跃时光不迷离!
🐰✨
"""


📜 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 42ba37d and 417887a.

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

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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.

@codecov
Copy link

codecov bot commented Jul 1, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.14%. Comparing base (f819320) to head (417887a).
Report is 2 commits behind head on feat_v3.x.

Additional details and impacted files
@@            Coverage Diff             @@
##           feat_v3.x    #3292   +/-   ##
==========================================
  Coverage      88.13%   88.14%           
==========================================
  Files            290      290           
  Lines          19111    19110    -1     
  Branches        2960     2960           
==========================================
  Hits           16844    16844           
+ Misses          2262     2261    -1     
  Partials           5        5           

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@xiaoyatong xiaoyatong requested a review from Miles-hxy July 1, 2025 02:28
@xiaoyatong xiaoyatong changed the title fix(calendar): 类型续订 fix(calendar): 类型修订 Jul 1, 2025
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

🔭 Outside diff range comments (2)
src/packages/calendaritem/calendaritem.tsx (1)

690-691: 请为 CalendarState.currDateArray 指定明确类型

目前在以下文件的 CalendarState 接口中,currDateArray 都被声明为 any,与 onDayClick(data: string[])(以及同样接收 string[]onConfirm)签名不匹配。请将其改为与业务需求一致的类型,并确保所有赋值和调用都保持一致:

  • src/packages/calendaritem/calendaritem.taro.tsx
  • src/packages/calendaritem/calendaritem.tsx

建议修改:

interface CalendarState {
-  currDateArray: any
+  currDateArray: string[]
}

如果业务需要二维数组,则改为 string[][] 并同步更新 onDayClick/onConfirm 的签名与调用处。

src/packages/calendaritem/calendaritem.taro.tsx (1)

689-689: 修正 CalendarState.currDateArray 类型与 onDayClick 签名不一致

目前在 src/packages/calendaritem/calendaritem.taro.tsx 中:

  • 接口定义
    interface CalendarState {
      currDateArray: any
    }
  • 回调签名
    export interface CalendarItemProps {
      onDayClick: (data: string[]) => void
      
    }
  • 调用方式
    onDayClick && onDayClick(state.currDateArray)

存在以下问题:

  1. currDateArray 定义为 any,无法保证传入 onDayClick 时一定是 string[]
  2. 在“range”模式下,state.currDateArray 实际为 string[][];在“single”或“week”模式下,又为 string[]。这与固定的 (data: string[]) => void 签名不匹配,可能导致类型或运行时逻辑错误。

建议:

  • CalendarState.currDateArray 明确定义为 string[],并对不同类型做必要的扁平或拆分处理;
  • 或者将 onDayClick 的签名改为 (data: string[] | string[][]) => void,并在组件调用前做合理的数据转换。

请在以下位置进行修复:

  • src/packages/calendaritem/calendaritem.taro.tsx(接口定义及调用处)
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f819320 and 42ba37d.

📒 Files selected for processing (13)
  • src/packages/calendar/__tests__/calendar.spec.tsx (1 hunks)
  • src/packages/calendar/calendar.taro.tsx (2 hunks)
  • src/packages/calendar/calendar.tsx (2 hunks)
  • src/packages/calendar/demos/h5/demo1.tsx (1 hunks)
  • src/packages/calendar/demos/h5/demo2.tsx (1 hunks)
  • src/packages/calendar/demos/h5/demo8.tsx (1 hunks)
  • src/packages/calendar/demos/taro/demo1.tsx (1 hunks)
  • src/packages/calendar/demos/taro/demo2.tsx (1 hunks)
  • src/packages/calendar/demos/taro/demo8.tsx (1 hunks)
  • src/packages/calendaritem/calendaritem.taro.tsx (2 hunks)
  • src/packages/calendaritem/calendaritem.tsx (2 hunks)
  • src/types/spec/calendar/base.ts (2 hunks)
  • src/utils/date.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
src/packages/calendar/__tests__/calendar.spec.tsx (2)
Learnt from: Alex-huxiyang
PR: jdf2e/nutui-react#2416
File: src/packages/uploader/uploader.taro.tsx:230-230
Timestamp: 2024-07-05T02:58:57.992Z
Learning: When changes are made to the `fileList` state in the `src/packages/uploader/uploader.taro.tsx` file, ensure to generate unit tests to cover these changes.
Learnt from: xiaoyatong
PR: jdf2e/nutui-react#2990
File: src/packages/pickerview/__test__/pickerview.spec.tsx:0-0
Timestamp: 2025-02-25T02:21:32.906Z
Learning: In React component tests, avoid using setTimeout with fixed delays. Instead, use act() to wrap async state updates and waitFor() for assertions, which makes tests more stable and reliable.
🧬 Code Graph Analysis (1)
src/types/spec/calendar/base.ts (1)
src/types/base/atoms.ts (1)
  • SimpleValue (1-1)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: test
  • GitHub Check: build
  • GitHub Check: lint
🔇 Additional comments (16)
src/packages/calendar/__tests__/calendar.spec.tsx (1)

4-4: 导入路径优化得当

CalendarDay 类型的导入路径从包特定路径调整为共享类型路径,这是良好的代码组织实践,有助于类型定义的集中管理。

src/packages/calendar/demos/h5/demo1.tsx (1)

25-27: 回调参数类型更新正确

select 函数参数类型从 string 更新为 string[],与日历组件 onDayClick 回调的类型规范保持一致。函数体的日志输出逻辑无需调整。

src/packages/calendar/demos/h5/demo8.tsx (1)

20-22: 类型定义更新一致

select 函数参数类型正确更新为 string[],与日历组件的回调签名改进保持同步。日志输出功能不受影响。

src/packages/calendar/demos/taro/demo8.tsx (1)

20-22: 跨平台类型一致性良好

Taro 版本的 select 函数参数类型更新与 H5 版本保持一致,确保了跨平台的类型规范统一。

src/packages/calendar/demos/taro/demo2.tsx (1)

20-22: 类型更新完整一致

select 函数参数类型更新完成了 Taro 平台 demo 的类型规范统一,与其他演示文件保持一致的回调签名。

src/packages/calendar/demos/taro/demo1.tsx (1)

24-26: 类型更新符合预期

参数类型从 string 更新为 string[] 与日历组件 API 的整体更新保持一致,函数体的 console.log 实现对数组类型也能正常工作。

src/packages/calendar/demos/h5/demo2.tsx (1)

20-22: 类型更新保持一致性

与其他演示文件保持一致,将 select 函数参数类型从 string 更新为 string[],实现逻辑无需修改。

src/utils/date.ts (1)

261-262: 属性命名标准化

将属性名从 preYear/preMonth 统一为 year/month,与 CalendarDay 接口的命名保持一致,提高了代码的一致性。

src/packages/calendar/calendar.tsx (2)

34-34: 回调签名更新 - 注意破坏性变更

onDayClick 回调的参数类型从 string 更新为 string[]。此变更与类型定义保持一致,但这是一个破坏性变更,升级的用户需要相应调整其回调函数实现。

建议确认所有使用此组件的地方都已更新以适配新的回调签名。


90-92: 内部函数签名保持一致

select 函数参数类型更新与 onDayClick 回调保持一致,确保了内部实现的类型安全性。

src/types/spec/calendar/base.ts (1)

8-9: 接口扩展合理

CalendarDay 接口添加可选的 monthyear 属性,支持了日期工具函数的属性名标准化,类型定义使用 SimpleValue 保持了灵活性。

src/packages/calendar/calendar.taro.tsx (1)

33-35: LGTM! 默认属性类型简化合理。

将默认回调函数简化为无参数函数是合理的做法,这样可以避免类型不匹配的问题,同时保持了向后兼容性。

src/packages/calendaritem/calendaritem.tsx (2)

64-64: 接口变更合理,提升了类型安全性。

onDayClick 的参数类型从 string 更新为 string[] 更好地反映了实际的使用场景,特别是在多选和范围选择模式下。


88-91: 默认属性简化得当。

将回调函数的默认实现简化为无参数函数避免了类型冲突,是一个很好的重构决策。

src/packages/calendaritem/calendaritem.taro.tsx (2)

65-65: 接口更新与其他组件保持一致。

onDayClick 参数类型从 string 更新为 string[],与 H5 版本的 CalendarItem 保持一致,确保了 API 的统一性。


89-92: 默认属性优化合理。

统一简化回调函数的默认实现,与其他组件的重构保持一致,提升了代码的维护性。

onClose: () => void
onConfirm: (param: string) => void
onDayClick: (data: string) => void
onDayClick: (data: string[]) => void
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

回调类型更新一致性问题

BaseCalendar 接口中的 onDayClick 已更新为接受 string[],但注意到第83行的 BaseCalendarItem 接口中的 onDayClick 仍然是 string 类型,这可能导致类型不一致。

请检查 BaseCalendarItem 接口中的 onDayClick 是否也需要更新为 string[] 类型以保持一致性:


🏁 Script executed:

#!/bin/bash
# 检查 BaseCalendarItem 接口的使用情况
rg -A 3 -B 3 "BaseCalendarItem.*onDayClick"

Length of output: 45


为进一步确认 BaseCalendarItem 接口中是否定义了 onDayClick 及其具体类型,请执行以下脚本:


🏁 Script executed:

#!/bin/bash
# 查找 BaseCalendarItem 接口定义及其 onDayClick 属性
rg -n "interface BaseCalendarItem" src/types/spec/calendar/base.ts
rg -A 5 -B 5 "interface BaseCalendarItem" src/types/spec/calendar/base.ts
rg -n "onDayClick" src/types/spec/calendar/base.ts

Length of output: 608


请同步更新 BaseCalendarItem.onDayClick 回调签名

为保持 BaseCalendarBaseCalendarItem 接口的一致性,需要将后者的 onDayClick 参数类型从单个 string 调整为 string[]

  • 文件:src/types/spec/calendar/base.ts
    位置:约第 83 行
-  onDayClick: (data: string) => void
+  onDayClick: (data: string[]) => void

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In src/types/spec/calendar/base.ts around line 83, update the onDayClick
callback signature in the BaseCalendarItem interface to accept a parameter of
type string[] instead of a single string. This change ensures consistency with
the BaseCalendar interface's onDayClick definition at line 54. Locate the
onDayClick method in BaseCalendarItem and modify its parameter type accordingly.

Comment on lines +90 to 92
const select = (param: string[]) => {
onDayClick && onDayClick(param)
}
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

确认参数类型变更的一致性。

select 函数参数类型从 string 更新为 string[],与 onDayClick 回调的新签名保持一致。这是一个破坏性变更,需要确保所有调用方都已相应更新。

请运行以下脚本验证所有 onDayClick 的使用都已更新为新的签名:


🏁 Script executed:

#!/bin/bash
# 描述:检查所有 onDayClick 的使用是否与新签名一致
# 预期:只应该找到接受 string[] 参数的回调

# 搜索 onDayClick 的所有使用
rg -A 3 -B 1 "onDayClick" --type tsx --type ts

Length of output: 74


我们发现 rg --type tsx 报错“不识别的文件类型”,改用文件 glob 过滤重跑一遍:


🏁 Script executed:

#!/bin/bash
# 使用 --glob 同时匹配 .ts 和 .tsx 文件,展示上下文行
rg -n -C 3 "onDayClick" --glob '*.ts' --glob '*.tsx'

Length of output: 21085


确保 onDayClick 签名在类型声明中一致

我们已验证:

  • src/packages/calendar/calendar.tsxcalendar.taro.tsx 中的 select 函数均使用了 string[] 参数并传递给 onDayClick
  • CalendarItem、CalendarCard 组件及所有示例代码(demos/h5demos/taro)的 onDayClick 调用均已传入数组类型

但在类型声明文件 src/types/spec/calendar/base.ts 中仍然存在旧的签名:

// src/types/spec/calendar/base.ts:83
onDayClick: (data: string) => void

请将上述声明更新为:

onDayClick: (data: string[]) => void

以保持整体 API 的一致性。

🧰 Tools
🪛 Biome (1.9.4)

[error] 91-91: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🤖 Prompt for AI Agents
In src/types/spec/calendar/base.ts around line 83, update the type declaration
of onDayClick from accepting a single string parameter to accepting an array of
strings. Change the signature from onDayClick: (data: string) => void to
onDayClick: (data: string[]) => void to ensure consistency with the
implementation in calendar.taro.tsx and other related components.

@xiaoyatong
Copy link
Collaborator Author

#2510 这个issue


const select = (param: string) => {
const select = (param: string[]) => {
onDayClick && onDayClick(param)
Copy link
Collaborator

Choose a reason for hiding this comment

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

和上面定义的onDayClick: () => {},类型似乎不一致

@Miles-hxy Miles-hxy merged commit 6063eb3 into jdf2e:feat_v3.x Jul 4, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3.x Target branch 3.x action:review This PR needs more reviews (less than 2 approvals) size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants