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(plugins): icons enhanced feature can be used for layout menu #12515

Merged
merged 6 commits into from
Jul 12, 2024

Conversation

Donovan-Ye
Copy link
Contributor

@Donovan-Ye Donovan-Ye commented Jul 1, 2024

因为需要自定义max中layout菜单的图标,所以尝试修改源码中加载菜单图标的逻辑。参考和使用了核心配置icons的逻辑,支持了菜单图标使用图标集或者本地图标。

Summary by CodeRabbit

  • 新功能

    • 引入了对默认图标配置的兼容性,可以使用图标集或本地图标。
    • 添加了 autoInstall 属性以支持自动安装图标。
  • 改进

    • 更新了主页和用户页的图标引用。
    • 在应用程序中设置了基于 isIconsFeatureEnable 标志的条件逻辑,动态调整图标的渲染。
  • 依赖更新

    • 添加了 @iconify-json/ic 版本 1.1.17@iconify-json/solar 版本 1.1.9 的开发依赖。
  • 文档

    • 更新了图标配置页面的参考信息。
  • 用户界面

    • 图标部分的文本更新为 "Icon library icons"。
    • 添加了新的图标引用和本地图标的显示部分。

Copy link

vercel bot commented Jul 1, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
umi ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 7, 2024 1:08pm

Copy link

coderabbitai bot commented Jul 1, 2024

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

此次更新主要引入了图标功能的兼容性,为默认图标配置添加了对图标集和本地图标的支持。在多处文件中进行了图标引用的更新,并在配置文件和组件中添加了相关逻辑,以启用或禁用图标功能。还增加了新的开发依赖以支持新的图标引用。

Changes

文件 变更摘要
docs/docs/docs/max/layout-menu.md 引入对默认图标配置的兼容性,支持使用图标集或本地图标,参考图标配置页面获取详情。
examples/max/.umirc.ts 更新主页面和用户页面的图标引用,添加 autoInstall 属性。
examples/max/package.json 添加新的开发依赖:@iconify-json/ic 版本 1.1.17@iconify-json/solar 版本 1.1.9
examples/max/pages/index.tsx 更新图标部分的文本,添加使用不同前缀(如“ic”和“solar”)的图标引用,并增加了一个新部分“Local Icons”。
packages/plugins/src/layout.ts 引入 IcongetIconComponent 的导入,并添加基于图标功能启用标志的条件逻辑,以确定是否使用相关组件。
packages/preset-umi/src/features/icons/icons.ts 引入了新功能 getIconComponent,根据图标名称检索图标组件,增强了 Icon 组件的图标获取逻辑。
packages/plugins/src/layout.ts 基于 isIconsFeatureEnable 标志的条件逻辑,导入和使用 @umijs/max 中相关图标组件,影响应用中图标的渲染。更新 patchRoutes 函数中的条件逻辑。

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:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • 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 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 Configration 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

@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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4b89cd4 and b89761b.

Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing (6)
  • docs/docs/docs/max/layout-menu.md (1 hunks)
  • examples/max/.umirc.ts (2 hunks)
  • examples/max/package.json (1 hunks)
  • examples/max/pages/index.tsx (1 hunks)
  • packages/plugins/src/layout.ts (2 hunks)
  • packages/preset-umi/src/features/icons/icons.ts (1 hunks)
Files not summarized due to errors (1)
  • packages/plugins/src/layout.ts: Error: Server error. Please try again later.
Files not reviewed due to errors (2)
  • examples/max/pages/index.tsx (no review received)
  • examples/max/.umirc.ts (no review received)
Files skipped from review due to trivial changes (2)
  • docs/docs/docs/max/layout-menu.md
  • examples/max/package.json
Additional comments not posted (2)
packages/preset-umi/src/features/icons/icons.ts (1)

325-328: 检查图标组件获取函数的正确性

getIconComponent函数用于获取图标组件,确保此函数能正确处理各种图标名称,并且能在图标不存在时正确返回。

#!/bin/bash
# 描述:验证图标组件获取函数的正确性

# 测试:搜索`getIconComponent`函数的定义和使用情况。期望:找到所有`getIconComponent`函数的定义和使用情况。
rg --type typescript --files-with-matches $'getIconComponent'
packages/plugins/src/layout.ts (1)

Line range hint 432-451: 检查路由图标处理函数的正确性

patchRoutes函数用于处理路由图标,确保此函数能正确处理图标名称和对应的组件,并在图标组件不存在时正确处理。

#!/bin/bash
# 描述:验证路由图标处理函数的正确性

# 测试:搜索`patchRoutes`函数的定义和使用情况。期望:找到所有`patchRoutes`函数的定义和使用情况。
rg --type typescript --files-with-matches $'patchRoutes'

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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4b89cd4 and b89761b.

Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing (6)
  • docs/docs/docs/max/layout-menu.md (1 hunks)
  • examples/max/.umirc.ts (2 hunks)
  • examples/max/package.json (1 hunks)
  • examples/max/pages/index.tsx (1 hunks)
  • packages/plugins/src/layout.ts (2 hunks)
  • packages/preset-umi/src/features/icons/icons.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • examples/max/package.json
Additional comments not posted (16)
examples/max/pages/index.tsx (5)

57-57: 添加图标库部分的标题

添加了图标库部分的标题,明确了接下来展示的图标来源于图标库。


58-58: 使用图标库中的图标

展示了一个图标库中的图标,使用了ic:baseline-14mp


59-59: 使用图标库中的图标

展示了一个图标库中的图标,使用了ic:baseline-3p


60-60: 使用图标库中的图标

展示了一个图标库中的图标,使用了solar:4k-bold


62-62: 添加本地图标部分的标题

添加了本地图标部分的标题,明确了接下来展示的图标来源于本地。

examples/max/.umirc.ts (3)

8-8: 更新路由图标

将首页路由的图标更新为ic:baseline-14mp,确保图标正确展示。


14-14: 更新路由图标

将用户页路由的图标更新为local:rice,确保图标正确展示。


108-108: 添加自动安装图标配置

在图标配置中添加了autoInstall属性,确保图标库自动安装。

docs/docs/docs/max/layout-menu.md (1)

194-195: 更新图标配置文档

兼容默认配置icons,支持使用图标集或本地图标,确保开发者了解新功能。

packages/preset-umi/src/features/icons/icons.ts (2)

325-329: 添加获取图标组件函数

添加了getIconComponent函数,用于根据图标名称获取图标组件,提升图标获取逻辑的可维护性。


332-332: 使用获取图标组件函数

Icon组件中使用getIconComponent函数,确保图标组件正确获取和展示。

packages/plugins/src/layout.ts (5)

432-432: 导入 IcongetIconComponent

导入 IcongetIconComponent 是为了支持加载自定义图标的新功能。


446-446: 使用 getIconComponent 获取图标组件

新增的 Component 常量用于获取相应的图标组件。


447-447: 检查 Component 是否定义

此更改确保仅将有效的组件分配给路由。


448-448: 渲染图标组件

如果 Component 有效,则渲染图标组件。


451-451: 图标回退机制

此更改增加了图标的回退机制,确保即使未找到自定义图标,也会使用标准图标。

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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b89761b and 70e7f20.

Files selected for processing (1)
  • packages/plugins/src/layout.ts (2 hunks)
Additional comments not posted (3)
packages/plugins/src/layout.ts (3)

426-427: 添加图标功能的启用检查

添加了一个检查是否启用了图标功能的标志 isIconsFeatureEnable

这段代码看起来不错,确保在配置中正确设置了 icons 属性。


434-438: 条件导入图标组件

根据 isIconsFeatureEnable 标志,条件性地导入 IcongetIconComponent 组件。

这段代码看起来不错,确保在配置中正确设置了 icons 属性。


452-460: 条件设置图标组件

根据 isIconsFeatureEnable 标志,条件性地设置图标组件。

这段代码看起来不错,确保在配置中正确设置了 icons 属性。

packages/plugins/src/layout.ts Outdated Show resolved Hide resolved
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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 70e7f20 and 0fa4819.

Files selected for processing (1)
  • packages/plugins/src/layout.ts (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/plugins/src/layout.ts

@PeachScript PeachScript changed the title feat(max/layout): 支持菜单图标使用图标集或者本地图标 / Support for menu icons using icon sets or local icons feat(plugins): icons enhanced feature can be used in layout menu Jul 12, 2024
Copy link
Member

@PeachScript PeachScript left a comment

Choose a reason for hiding this comment

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

+1

@PeachScript PeachScript changed the title feat(plugins): icons enhanced feature can be used in layout menu feat(plugins): icons enhanced feature can be used for layout menu Jul 12, 2024
@PeachScript PeachScript merged commit f5318d7 into umijs:master Jul 12, 2024
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants