Skip to content

Comments

refactor(fixednav): 优化组件徽标的实现方式,解决原有不对称问题#3061

Merged
oasis-cloud merged 2 commits intojdf2e:feat_v3.xfrom
irisSong:bugfix_fixednav
Mar 7, 2025
Merged

refactor(fixednav): 优化组件徽标的实现方式,解决原有不对称问题#3061
oasis-cloud merged 2 commits intojdf2e:feat_v3.xfrom
irisSong:bugfix_fixednav

Conversation

@irisSong
Copy link
Collaborator

@irisSong irisSong commented Mar 7, 2025

🤔 这个变动的性质是?

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

🔗 相关 Issue

💡 需求背景和解决方案

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

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

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

Summary by CodeRabbit

  • 新功能
    • 在固定导航项中引入了徽标显示,当项内包含数字时会直观呈现提示信息。
  • 重构
    • 优化了导航项的渲染逻辑,使组件结构更加清晰和模块化。
  • 样式调整
    • 移除部分已不再需要的样式定义,进一步简化了组件的外观。

@coderabbitai
Copy link

coderabbitai bot commented Mar 7, 2025

Walkthrough

这次更改主要针对 FixedNav 组件中列表项的渲染逻辑以及样式调整。SCSS 文件中移除了 .nut-fixednav-list-item 作用域内 .b 的样式;而在 Taro 与 TSX 版本的 FixedNav 组件中,新增了 renderListItem 方法,并引入 Badge 组件来处理带有数字标记的列表项,从而提升了代码的模块化和可读性。

Changes

File(s) Summary of Changes
src/packages/fixednav/fixednav.scss 删除了 .nut-fixednav-list-item 作用域内 .b 的样式定义,包括定位、尺寸、字体、内边距等属性。
src/packages/fixednav/fixednav.taro.tsx,
src/packages/fixednav/fixednav.tsx
新增了 renderListItem 方法封装列表项渲染逻辑,引入 Badge 组件,根据是否存在 num 属性决定是否包装列表项,优化了组件的渲染结构。

Sequence Diagram(s)

sequenceDiagram
    participant FN as FixedNav 组件
    participant RL as renderListItem 方法
    participant BG as Badge 组件
    participant UI as UI 显示

    FN->>+RL: 调用 renderListItem(item, index)
    alt item 包含 num 属性
        RL->>+BG: 包装列表项,传递 num 属性
        BG-->>-UI: 渲染带徽标的列表项
    else
        RL-->>UI: 直接渲染列表项
    end
Loading

Suggested reviewers

  • xiaoyatong
  • oasis-cloud

Poem

我是小兔子,跳跃在代码间,
每个改动都是妙趣横生的篇章,
样式和逻辑齐头并进,
Badge 与列表如影随形,
在这代码园中欢快歌唱! 🐰🌟

✨ 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.
    • 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.

@github-actions github-actions bot added action:review This PR needs more reviews (less than 2 approvals) 3.x Target branch 3.x labels Mar 7, 2025
@irisSong irisSong requested review from oasis-cloud and xiaoyatong and removed request for oasis-cloud March 7, 2025 03:51
@codecov
Copy link

codecov bot commented Mar 7, 2025

Codecov Report

Attention: Patch coverage is 94.73684% with 1 line in your changes missing coverage. Please review.

Project coverage is 86.07%. Comparing base (8cc0c1f) to head (5c284ce).
Report is 3 commits behind head on feat_v3.x.

Files with missing lines Patch % Lines
src/packages/fixednav/fixednav.tsx 94.73% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           feat_v3.x    #3061   +/-   ##
==========================================
  Coverage      86.06%   86.07%           
==========================================
  Files            275      275           
  Lines          18234    18243    +9     
  Branches        2751     2754    +3     
==========================================
+ Hits           15694    15703    +9     
  Misses          2535     2535           
  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.

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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8cc0c1f and 5c284ce.

📒 Files selected for processing (3)
  • src/packages/fixednav/fixednav.scss (0 hunks)
  • src/packages/fixednav/fixednav.taro.tsx (3 hunks)
  • src/packages/fixednav/fixednav.tsx (3 hunks)
💤 Files with no reviewable changes (1)
  • src/packages/fixednav/fixednav.scss
🧰 Additional context used
🪛 Biome (1.9.4)
src/packages/fixednav/fixednav.taro.tsx

[error] 101-101: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)


[error] 105-105: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

src/packages/fixednav/fixednav.tsx

[error] 102-102: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)


[error] 106-106: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

🪛 GitHub Check: codecov/patch
src/packages/fixednav/fixednav.tsx

[warning] 70-70: src/packages/fixednav/fixednav.tsx#L70
Added line #L70 was not covered by tests

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
🔇 Additional comments (5)
src/packages/fixednav/fixednav.taro.tsx (2)

9-9: 良好的组件依赖引入

添加 Badge 组件的导入很合适,这有助于实现带有数字标记的列表项。


62-77: 代码结构优化良好

将列表项渲染逻辑提取到独立函数中是很好的重构,提高了代码的可读性和可维护性。

src/packages/fixednav/fixednav.tsx (3)

8-8: 良好的组件依赖引入

添加 Badge 组件的导入很合适,这有助于实现带有数字标记的列表项。


62-77: 代码结构优化良好

将列表项渲染逻辑提取到独立函数中是很好的重构,提高了代码的可读性和可维护性。

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 70-70: src/packages/fixednav/fixednav.tsx#L70
Added line #L70 was not covered by tests


69-70:

Details

❓ Verification inconclusive

增加测试覆盖率

新添加的 icon 渲染逻辑未被测试覆盖,建议添加相应测试用例。


🏁 Script executed:

#!/bin/bash
# 检查是否存在针对 icon 渲染逻辑的测试
rg -A 3 "icon.*isValidElement|isValidElement.*icon" src/packages/fixednav/__tests__

Length of output: 85


建议补充针对 icon 渲染逻辑的单元测试
src/packages/fixednav/fixednav.tsx 中新增的 icon 渲染逻辑,目前在 src/packages/fixednav/__tests__ 中未发现对应的测试用例。请补充相应的单元测试,以确保该逻辑在未来的修改中不被误破坏。

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 70-70: src/packages/fixednav/fixednav.tsx#L70
Added line #L70 was not covered by tests

Comment on lines +99 to 108
<>
{item.num ? (
<Badge value={item.num} top={8} right={6}>
{renderListItem(item, index)}
</Badge>
) : (
<img src={item.icon} alt="" />
<>{renderListItem(item, index)}</>
)}
<View className={`${classPrefix}-list-text`}>
{item.text}
</View>
{item.num && <View className="b">{item.num}</View>}
</View>
</>
)
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

修复 React Fragment 中缺少 key 属性的问题

在使用列表渲染时,每个 React Fragment 都需要添加 key 属性。

建议使用以下修复方案:

              return (
-                <>
+                <React.Fragment key={item.id || index}>
                  {item.num ? (
-                    <Badge value={item.num} top={8} right={6}>
+                    <Badge value={item.num} top={8} right={6} key={`badge-${item.id || index}`}>
                      {renderListItem(item, index)}
                    </Badge>
                  ) : (
-                    <>{renderListItem(item, index)}</>
+                    <React.Fragment key={`item-${item.id || index}`}>{renderListItem(item, index)}</React.Fragment>
                  )}
-                </>
+                </React.Fragment>
              )
📝 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
<>
{item.num ? (
<Badge value={item.num} top={8} right={6}>
{renderListItem(item, index)}
</Badge>
) : (
<img src={item.icon} alt="" />
<>{renderListItem(item, index)}</>
)}
<View className={`${classPrefix}-list-text`}>
{item.text}
</View>
{item.num && <View className="b">{item.num}</View>}
</View>
</>
)
return (
<React.Fragment key={item.id || index}>
{item.num ? (
<Badge value={item.num} top={8} right={6} key={`badge-${item.id || index}`}>
{renderListItem(item, index)}
</Badge>
) : (
<React.Fragment key={`item-${item.id || index}`}>{renderListItem(item, index)}</React.Fragment>
)}
</React.Fragment>
)
🧰 Tools
🪛 Biome (1.9.4)

[error] 101-101: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)


[error] 105-105: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

Comment on lines +100 to +108
<>
{item.num ? (
<Badge value={item.num} top={8} right={6}>
{renderListItem(item, index)}
</Badge>
) : (
<img src={item.icon} alt="" />
<>{renderListItem(item, index)}</>
)}
<div className={`${classPrefix}-list-text`}>{item.text}</div>
{item.num && <div className="b">{item.num}</div>}
</div>
</>
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

修复 React Fragment 中缺少 key 属性的问题

在使用列表渲染时,每个 React Fragment 都需要添加 key 属性。

建议使用以下修复方案:

              return (
-                <>
+                <React.Fragment key={item.id || index}>
                  {item.num ? (
-                    <Badge value={item.num} top={8} right={6}>
+                    <Badge value={item.num} top={8} right={6} key={`badge-${item.id || index}`}>
                      {renderListItem(item, index)}
                    </Badge>
                  ) : (
-                    <>{renderListItem(item, index)}</>
+                    <React.Fragment key={`item-${item.id || index}`}>{renderListItem(item, index)}</React.Fragment>
                  )}
-                </>
+                </React.Fragment>
              )
📝 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
<>
{item.num ? (
<Badge value={item.num} top={8} right={6}>
{renderListItem(item, index)}
</Badge>
) : (
<img src={item.icon} alt="" />
<>{renderListItem(item, index)}</>
)}
<div className={`${classPrefix}-list-text`}>{item.text}</div>
{item.num && <div className="b">{item.num}</div>}
</div>
</>
return (
<React.Fragment key={item.id || index}>
{item.num ? (
<Badge value={item.num} top={8} right={6} key={`badge-${item.id || index}`}>
{renderListItem(item, index)}
</Badge>
) : (
<React.Fragment key={`item-${item.id || index}`}>
{renderListItem(item, index)}
</React.Fragment>
)}
</React.Fragment>
)
🧰 Tools
🪛 Biome (1.9.4)

[error] 102-102: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)


[error] 106-106: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

@oasis-cloud oasis-cloud merged commit 8bcfe9e into jdf2e:feat_v3.x Mar 7, 2025
8 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Mar 21, 2025
20 tasks
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