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: 日历滚动的时候 最后一个月日历副标题不准确 #2486

Open
wants to merge 1 commit into
base: next
Choose a base branch
from

Conversation

yangqianlu
Copy link
Contributor

@yangqianlu yangqianlu commented Jul 26, 2024

🤔 这个变动的性质是?

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

🔗 相关 Issue

#2384

💡 需求背景和解决方案

具体问题:将日历滚动到最后一个月份,上面的副标题展示的日期不是最后一个月的日期
实现方案:
根据以下情况给日历的容器增加高度 使得能滚动到最后一个月
1.在popup里展示+底部按钮
2.在popup里展示+无底部按钮
3.平铺展示

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

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

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

Summary by CodeRabbit

  • 新功能

    • 日历组件的高度调整机制得到增强,现在可以根据最后一个月的数据行数和弹出状态动态调整高度。
    • 改善了当前月份的索引计算逻辑,使其更加简洁,响应用户的滚动操作更流畅。
  • 错误修复

    • 修正了关于当前月份更新的逻辑,减少了潜在的索引管理错误。

Copy link

coderabbitai bot commented Jul 26, 2024

Walkthrough

此次变更主要增强了 CalendarItem 组件的高度计算逻辑,使其能够根据最后一个月的数据行数和弹出状态动态调整高度。新实现引入了一个 HEIGHT_ITEM 变量,以确保日历的容器高度适应当前状态,从而改善了用户交互体验和滚动行为的响应性。

Changes

文件 修改摘要
src/packages/calendaritem/calendaritem.taro.tsx 调整了 containerHeightavgHeight 的计算逻辑,以动态处理日历项的高度。简化了基于滚动位置更新当前月份的逻辑。
src/packages/calendaritem/calendaritem.tsx 引入了动态高度调整机制,优化了基于行数和状态的高度计算,简化了当前月份索引更新的条件。

Poem

在日历中跳跃,兔子欢声笑语,
高度灵动,体验新奇,
条件简化,月影轻易,
滚动自如,心情如意。
哦,日历,春风满怀,
兔子祝福,愉快常在! 🐰✨


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 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 Jul 26, 2024

Codecov Report

Attention: Patch coverage is 57.89474% with 8 lines in your changes missing coverage. Please review.

Project coverage is 86.12%. Comparing base (7719a59) to head (1ec11bd).

Files Patch % Lines
src/packages/calendaritem/calendaritem.tsx 57.89% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             next    #2486      +/-   ##
==========================================
+ Coverage   86.06%   86.12%   +0.06%     
==========================================
  Files         217      217              
  Lines       22859    22850       -9     
  Branches     2549     2552       +3     
==========================================
+ Hits        19673    19680       +7     
+ Misses       3181     3165      -16     
  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: 8

Comment on lines +450 to +459
let HEIGHT_ITEM = 60 // 一行日历的高度
const LAST_MONTN_HAS_SIX_LINE = lastItem.monthData.length > 35
if (popup && autoBackfill) {
HEIGHT_ITEM = LAST_MONTN_HAS_SIX_LINE ? 60 : 80
} else if (popup && !autoBackfill) {
// 在popup里展示 且底部有确认按钮
HEIGHT_ITEM = LAST_MONTN_HAS_SIX_LINE ? 0 : 60
} else {
HEIGHT_ITEM = LAST_MONTN_HAS_SIX_LINE ? 120 : 140
}
Copy link

Choose a reason for hiding this comment

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

建议:为新的高度调整逻辑添加测试

新的高度调整逻辑缺乏测试覆盖。建议为以下情况添加测试:

  1. popupautoBackfill 都为真。
  2. popup 为真。
  3. popupautoBackfill 都为假。

是否需要我为这些情况生成测试代码或创建 GitHub issue 来跟踪此任务?

Tools
GitHub Check: codecov/patch

[warning] 453-453: src/packages/calendaritem/calendaritem.tsx#L453
Added line #L453 was not covered by tests


[warning] 458-459: src/packages/calendaritem/calendaritem.tsx#L458-L459
Added lines #L458 - L459 were not covered by tests

Comment on lines +460 to +462
// 让整个日历区域变高 确保能滚动到最后一个日历
const containerHeight =
lastItem.cssHeight + lastItem.scrollTop + HEIGHT_ITEM
Copy link

Choose a reason for hiding this comment

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

建议:为新的容器高度计算逻辑添加测试

新的容器高度计算逻辑缺乏测试覆盖。建议为以下情况添加测试:

  1. popupautoBackfill 都为真。
  2. popup 为真。
  3. popupautoBackfill 都为假。

是否需要我为这些情况生成测试代码或创建 GitHub issue 来跟踪此任务?

Comment on lines +545 to +546
// avgHeight变小 确保current能取到最后一个月的索引
const current = Math.floor(scrollTop / avgHeight)
Copy link

Choose a reason for hiding this comment

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

建议:为新的滚动位置逻辑添加测试

新的滚动位置逻辑缺乏测试覆盖。建议为以下情况添加测试:

  1. 滚动到最后一个月。
  2. 滚动到中间月份。
  3. 滚动到第一个月。

是否需要我为这些情况生成测试代码或创建 GitHub issue 来跟踪此任务?

Tools
GitHub Check: codecov/patch

[warning] 545-546: src/packages/calendaritem/calendaritem.tsx#L545-L546
Added lines #L545 - L546 were not covered by tests

Comment on lines +548 to +550
if (current === monthsData.length - 1) {
setDefaultRange(monthsNum, current)
return
Copy link

Choose a reason for hiding this comment

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

建议:为新的默认范围更新逻辑添加测试

新的默认范围更新逻辑缺乏测试覆盖。建议为以下情况添加测试:

  1. 滚动到最后一个月。
  2. 滚动到中间月份。
  3. 滚动到第一个月。

是否需要我为这些情况生成测试代码或创建 GitHub issue 来跟踪此任务?

Tools
GitHub Check: codecov/patch

[warning] 548-550: src/packages/calendaritem/calendaritem.tsx#L548-L550
Added lines #L548 - L550 were not covered by tests

Comment on lines +450 to +459
let HEIGHT_ITEM = 60 // 一行日历的高度
const LAST_MONTN_HAS_SIX_LINE = lastItem.monthData.length > 35
if (popup && autoBackfill) {
HEIGHT_ITEM = LAST_MONTN_HAS_SIX_LINE ? 60 : 80
} else if (popup && !autoBackfill) {
// 在popup里展示 且底部有确认按钮
HEIGHT_ITEM = LAST_MONTN_HAS_SIX_LINE ? 0 : 60
} else {
HEIGHT_ITEM = LAST_MONTN_HAS_SIX_LINE ? 120 : 140
}
Copy link

Choose a reason for hiding this comment

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

建议:为新的高度调整逻辑添加测试

新的高度调整逻辑缺乏测试覆盖。建议为以下情况添加测试:

  1. popupautoBackfill 都为真。
  2. popup 为真。
  3. popupautoBackfill 都为假。

是否需要我为这些情况生成测试代码或创建 GitHub issue 来跟踪此任务?

Comment on lines +460 to +462
// 让整个日历区域变高 确保能滚动到最后一个日历
const containerHeight =
lastItem.cssHeight + lastItem.scrollTop + HEIGHT_ITEM
Copy link

Choose a reason for hiding this comment

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

建议:为新的容器高度计算逻辑添加测试

新的容器高度计算逻辑缺乏测试覆盖。建议为以下情况添加测试:

  1. popupautoBackfill 都为真。
  2. popup 为真。
  3. popupautoBackfill 都为假。

是否需要我为这些情况生成测试代码或创建 GitHub issue 来跟踪此任务?

Comment on lines +547 to +548
// avgHeight变小 确保current能取到最后一个月的索引
const current = Math.floor(scrollTop / avgHeight)
Copy link

Choose a reason for hiding this comment

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

建议:为新的滚动位置逻辑添加测试

新的滚动位置逻辑缺乏测试覆盖。建议为以下情况添加测试:

  1. 滚动到最后一个月。
  2. 滚动到中间月份。
  3. 滚动到第一个月。

是否需要我为这些情况生成测试代码或创建 GitHub issue 来跟踪此任务?

Comment on lines +548 to +550
const current = Math.floor(scrollTop / avgHeight)
if (current < 0) return
if (!monthsData[current + 1]) return
const nextTop = monthsData[current + 1].scrollTop
const nextHeight = monthsData[current + 1].cssHeight
if (current === 0) {
if (scrollTop >= nextTop) {
current += 1
}
} else if (current > 0 && current < monthsNum - 1) {
if (scrollTop >= nextTop) {
current += 1
}
if (scrollTop < monthsData[current].scrollTop) {
current -= 1
}
} else {
const viewPosition = Math.round(scrollTop + viewHeight)
if (current + 1 <= monthsNum && viewPosition >= nextTop + nextHeight) {
current += 1
}
if (current >= 1 && scrollTop < monthsData[current - 1].scrollTop) {
current -= 1
}
if (current === monthsData.length - 1) {
Copy link

Choose a reason for hiding this comment

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

建议:为新的默认范围更新逻辑添加测试

新的默认范围更新逻辑缺乏测试覆盖。建议为以下情况添加测试:

  1. 滚动到最后一个月。
  2. 滚动到中间月份。
  3. 滚动到第一个月。

是否需要我为这些情况生成测试代码或创建 GitHub issue 来跟踪此任务?

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.

有一个问题需要考虑,定高后,怎么灵活配置高度?

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.

2 participants