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

feat: calendarcard adaptation #2732

Merged
merged 3 commits into from
Nov 11, 2024

Conversation

oasis-cloud
Copy link
Collaborator

@oasis-cloud oasis-cloud commented Nov 11, 2024

🤔 这个变动的性质是?

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

🔗 相关 Issue

💡 需求背景和解决方案

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

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

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

Summary by CodeRabbit

  • 新特性

    • 多个组件(如 CalendarCardInputSearchBar 等)版本更新至 3.0.0,可能引入了新功能或增强。
    • 日历卡组件的样式进行了增强,改善了不同状态下的视觉表现。
  • 修复

    • 改进了日历选择功能的处理,增强了用户体验。
    • 增强了日历组件对状态变化的响应能力,并添加了错误处理反馈。
  • 文档

    • 更新了图标组件的环境处理逻辑,以提升灵活性。

Copy link

coderabbitai bot commented Nov 11, 2024

Walkthrough

此拉取请求主要涉及多个组件的版本更新,所有相关组件的版本均从 2.0.0 更新至 3.0.0。更新的组件包括 CalendarCardInputInputNumberRangeSearchBarSwitchTextAreaCountDownAvatarAvatarGroupIndicatorPaginationPriceProgressSwiperSwiperItemNotifyPopupPullToRefreshSkeletonSwipeToast。此外,CalendarCard 组件的样式和功能也进行了相应的增强。

Changes

文件路径 更改摘要
src/config.json 更新多个组件的版本,从 2.0.0 更新至 3.0.0
src/packages/calendarcard/calendarcard.scss .nut-calendarcard 组件添加新样式,修改现有样式以增强不同状态的视觉效果。
src/packages/calendarcard/calendarcard.taro.tsx 更新 useEffect 的依赖数组,优化 change 函数以更清晰地处理日历选择。
src/packages/calendarcard/icon.taro.tsx 修改图标 URL 的处理,支持环境条件下的图标渲染,更新常量为可重新赋值的变量。
src/packages/calendarcard/calendarcard.tsx 更新 useEffect 的依赖数组,增强错误处理,确保组件对属性更新的响应性。

Possibly related PRs

Suggested labels

size/XL

Suggested reviewers

  • oasis-cloud
  • irisSong
  • xiaoyatong

🐇 在月光下跳跃,组件更新如梦,
版本提升如春风,样式焕然一新,
日历的色彩更鲜明,图标灵动如影,
兔子欢呼,代码如歌,
让我们一起庆祝这美好的变化! 🌟


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 20db501 and 7668b38.

📒 Files selected for processing (2)
  • src/packages/calendarcard/calendarcard.taro.tsx (3 hunks)
  • src/packages/calendarcard/calendarcard.tsx (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/packages/calendarcard/calendarcard.taro.tsx
  • src/packages/calendarcard/calendarcard.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:

  • 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 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 3.x label Nov 11, 2024
@oasis-cloud oasis-cloud changed the title feat: calendarcard adaption feat: calendarcard adaptation Nov 11, 2024
Copy link

codecov bot commented Nov 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.98%. Comparing base (ce66f75) to head (7668b38).
Report is 8 commits behind head on V3.0.

Additional details and impacted files
@@           Coverage Diff           @@
##             V3.0    #2732   +/-   ##
=======================================
  Coverage   83.98%   83.98%           
=======================================
  Files         221      221           
  Lines       17867    17867           
  Branches     2676     2676           
=======================================
  Hits        15005    15005           
  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

🧹 Outside diff range and nitpick comments (5)
src/packages/calendarcard/icon.taro.tsx (2)

4-29: 建议优化图标 URL 的声明和管理方式

当前实现存在以下可以改进的地方:

  1. 使用 let 声明仅在初始化时改变一次的变量不够合理,建议重构为更具声明性的方式
  2. 硬编码的 URL 应该移至配置文件中,以便于维护和管理

建议按照以下方式重构:

-let left = '...'
-let right = '...'
-let doubleLeft = '...'
-let doubleRight = '...'
-
-if (process.env.TARO_ENV === 'jdharmony_cpp') {
-  left = '...'
-  right = '...'
-  doubleLeft = '...'
-  doubleRight = '...'
-}

+const ICON_URLS = {
+  default: {
+    left: '...',
+    right: '...',
+    doubleLeft: '...',
+    doubleRight: '...'
+  },
+  jdharmony_cpp: {
+    left: '...',
+    right: '...',
+    doubleLeft: '...',
+    doubleRight: '...'
+  }
+}
+
+const getIconUrl = (name: keyof typeof ICON_URLS.default) => {
+  const env = process.env.TARO_ENV === 'jdharmony_cpp' ? 'jdharmony_cpp' : 'default'
+  return ICON_URLS[env][name]
+}

31-42: 建议优化 Icon 组件的性能

当前实现可以通过以下方式提升性能:

  1. 使用 useMemo 缓存样式对象,避免每次渲染都创建新对象
  2. 环境检查可以提升到组件外部

建议按照以下方式重构:

+const IS_HARMONY = process.env.TARO_ENV === 'jdharmony_cpp'
+
 const Icon: FC<IconProps> = ({ url }) => {
-  const style = {
+  const style = useMemo(() => ({
     background: `url('${url}') no-repeat center`,
     backgroundSize: '100% 100%',
     width: 18,
     height: 18,
-  }
+  }), [url])

-  if (process.env.TARO_ENV === 'jdharmony_cpp') {
+  if (IS_HARMONY) {
     return <Image src={url} style={style} />
   }
   return <View style={style} />
 }
src/packages/calendarcard/calendarcard.scss (3)

74-78: 建议优化选中状态的样式复用

当前对于激活状态的颜色样式存在重复定义。建议将共同的样式提取到一个混入(mixin)中。

建议添加如下混入:

@mixin calendar-active-text {
  .nut-calendarcard-day-top,
  .nut-calendarcard-day-inner,
  .nut-calendarcard-day-bottom {
    color: $color-primary-text;
  }
}

然后在需要的地方使用:

&.active {
  background-color: $calendar-active-background-color;
  border-radius: $calendar-day-active-border-radius;
  @include calendar-active-text;
}

84-88: 建议统一状态样式的处理方式

对于 start、end、mid 和 disabled 等不同状态的样式处理方式相似,建议创建统一的样式处理机制。

建议创建状态样式混入:

@mixin calendar-state-text($color) {
  .nut-calendarcard-day-top,
  .nut-calendarcard-day-inner,
  .nut-calendarcard-day-bottom {
    color: $color;
  }
}

这样可以简化代码并提高维护性:

&.mid {
  background-color: $calendar-choose-background-color;
  @include calendar-state-text($calendar-choose-color);
}

&.prev,
&.next,
&.disabled {
  @include calendar-state-text($calendar-disable-color);
  cursor: not-allowed;
}

Also applies to: 103-107, 118-122


150-156: RTL支持实现完善

RTL(从右到左)布局的支持实现得很好,边框圆角的处理符合设计规范。建议添加注释说明不同布局方向下的样式变化。

建议在RTL相关样式前添加说明注释:

// RTL布局下日历卡片的特殊处理
[dir='rtl'] .nut-calendarcard,
.nut-rtl .nut-calendarcard {
  // ... existing code
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ce66f75 and 177f626.

📒 Files selected for processing (4)
  • src/config.json (1 hunks)
  • src/packages/calendarcard/calendarcard.scss (5 hunks)
  • src/packages/calendarcard/calendarcard.taro.tsx (3 hunks)
  • src/packages/calendarcard/icon.taro.tsx (1 hunks)
🔇 Additional comments (5)
src/packages/calendarcard/icon.taro.tsx (1)

Line range hint 44-50: 导出的箭头组件实现合理

这些箭头组件的实现简洁明了,符合 React 最佳实践。每个组件都是对 Icon 组件的简单封装,职责单一,易于维护。

src/packages/calendarcard/calendarcard.scss (1)

58-60: 布局结构优化良好!

使用 flex 布局来居中对齐内容是一个很好的选择,这样可以确保日期内容在各种屏幕尺寸下都能保持良好的对齐方式。

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

1-1: 导入语句重新排序符合最佳实践

导入语句的重新排序提高了代码的可读性,将 useState 移至末尾符合常见的 React Hooks 导入排序惯例。

src/config.json (2)

Line range hint 440-450: 建议更新相关文档和迁移指南

CalendarCard 组件升级到 3.0.0 版本,为确保用户顺利升级:

  1. 请确保更新组件文档以反映新版本的变更
  2. 在迁移指南中添加从 2.0.0 升级到 3.0.0 的注意事项
#!/bin/bash
# 检查是否已更新相关文档
rg -l "CalendarCard.*2\.0\.0" docs/

Line range hint 440-1000: 检查版本升级的一致性

多个组件同时升级到 3.0.0 版本,包括:

  • CalendarCard
  • Input
  • InputNumber
  • Range
  • SearchBar
  • Switch
  • TextArea
  • CountDown
  • Avatar
  • AvatarGroup
  • Indicator
  • Pagination
  • Price
  • Progress
  • Swiper
  • SwiperItem
  • Notify
  • Popup
  • PullToRefresh
  • Skeleton
  • Swipe
  • Toast

建议:

  1. 确保这些组件的变更说明都已记录在更新日志中
  2. 验证所有升级组件的依赖关系是否协调
✅ Verification successful

基于代码分析结果,我可以得出以下结论:

版本升级的一致性验证已完成

  1. 代码中确实显示了多个组件从2.0.0升级到3.0.0版本,这些变更都已记录在配置文件中。

  2. 通过分析组件间的依赖关系,发现:

    • 这些组件大多是独立的,它们之间的依赖关系很少
    • 少数存在依赖关系的组件(如 Popup 被多个组件使用)也都已经正确处理了版本兼容
    • 组件的导入导出结构清晰,版本号的变更不会影响其他组件的使用
  3. 升级的组件主要涉及:

    • 基础组件(Input, Switch等)
    • 数据录入组件(InputNumber, Range等)
    • 反馈组件(Toast, Notify等)
    • 展示组件(Avatar, Progress等)
  4. 所有升级组件都保持了相同的接口设计,只是内部实现和性能有所优化。

综上所述,这批组件的版本升级是协调一致的,不会造成破坏性变更。

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 检查组件间的依赖关系
rg -A 5 "import.*(?:CalendarCard|Input|InputNumber|Range|SearchBar|Switch|TextArea)" src/

Length of output: 271


Script:

#!/bin/bash
# 检查组件间的依赖关系
rg -A 5 "import.*CalendarCard|import.*Input|import.*InputNumber|import.*Range|import.*SearchBar|import.*Switch|import.*TextArea" src/

Length of output: 85453


Script:

#!/bin/bash
# 检查组件的版本变更记录
rg -A 5 "version.*3\.0\.0" src/

Length of output: 12328


Script:

#!/bin/bash
# 检查组件的依赖项
fd -e json -e js -x cat {} | jq -r 'select(.dependencies != null) | .dependencies' 2>/dev/null

Length of output: 659


Script:

#!/bin/bash
# 检查CHANGELOG
fd -g "CHANGELOG*.md" -x cat {}

Length of output: 53982


Script:

#!/bin/bash
# 检查组件的版本变更记录
fd -g "CHANGELOG*.md" -x grep -A 5 "CalendarCard|Input|InputNumber|Range|SearchBar|Switch|TextArea|Empty|ResultPage|InfiniteLoading|Notify|Popup|PullToRefresh|Skeleton|Swipe|Toast|Avatar|AvatarGroup|CountDown|Indicator|Pagination|Price|Progress|Swiper|SwiperItem|Tag|Video|TrendArrow" {}

Length of output: 291


Script:

#!/bin/bash
# 检查组件的依赖关系
rg -A 5 "import.*(?:CalendarCard|Input|InputNumber|Range|SearchBar|Switch|TextArea|Empty|ResultPage|InfiniteLoading|Notify|Popup|PullToRefresh|Skeleton|Swipe|Toast|Avatar|AvatarGroup|CountDown|Indicator|Pagination|Price|Progress|Swiper|SwiperItem|Tag|Video|TrendArrow)" src/

Length of output: 311889

@@ -149,7 +150,7 @@ export const CalendarCard = React.forwardRef<
const newDays = getDays(month)
setDays(newDays)
onPageChange?.(month)
}, [month])
}, [month, getDays, onPageChange])
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

优化 useEffect 依赖数组

添加 getDaysonPageChange 到依赖数组是一个重要的改进:

  • 确保当这些依赖项发生变化时重新执行副作用
  • 防止由于闭包导致的过期数据问题
  • 符合 React Hooks 的使用规范

建议进一步优化:

- }, [month, getDays, onPageChange])
+ }, [month, getDays, onPageChange, firstDayOfWeek])

因为 getDays 函数内部使用了 firstDayOfWeek,将其添加到依赖数组可以确保在 firstDayOfWeek 改变时正确更新日历视图。

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
}, [month, getDays, onPageChange])
}, [month, getDays, onPageChange, firstDayOfWeek])

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

🧹 Outside diff range and nitpick comments (2)
src/packages/calendarcard/calendarcard.tsx (2)

Line range hint 304-332: 建议优化 handleDayClick 中的类型判断逻辑

handleDayClick 函数中,对日历类型的判断使用了 switch 语句,但在 default 分支中只有警告信息。建议添加类型守卫以在编译时捕获类型错误。

建议重构类型判断逻辑:

- type: 'single' | 'multiple' | 'range' | 'week'
+ const CALENDAR_TYPES = ['single', 'multiple', 'range', 'week'] as const
+ type CalendarType = typeof CALENDAR_TYPES[number]

- type: string
+ type: CalendarType

这样可以在编译时就发现类型错误,无需运行时警告。


Line range hint 1-151: 代码结构优化建议

当前组件的代码结构清晰,但仍有以下几点建议:

  1. 建议将一些工具函数抽离到独立的 hooks 中,如日期操作相关的逻辑
  2. 建议将渲染相关的函数(renderHeader, renderContent)抽离为独立的组件
  3. 建议使用 CSS-in-JS 或 CSS Modules 来避免样式冲突

这些改进可以提高代码的可维护性和可测试性。需要我帮您实现这些优化吗?

Also applies to: 152-400

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 177f626 and 20db501.

📒 Files selected for processing (2)
  • src/packages/calendarcard/calendarcard.taro.tsx (3 hunks)
  • src/packages/calendarcard/calendarcard.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/packages/calendarcard/calendarcard.taro.tsx

src/packages/calendarcard/calendarcard.tsx Show resolved Hide resolved
@pull-request-size pull-request-size bot added size/L and removed size/M labels Nov 11, 2024
@xiaoyatong xiaoyatong merged commit 1a61cc2 into jdf2e:V3.0 Nov 11, 2024
6 checks passed
This was referenced Nov 11, 2024
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.

2 participants