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: auto activate subMenu on select root menu #5147

Merged
merged 3 commits into from
Dec 15, 2024

Conversation

mynetfan
Copy link
Collaborator

@mynetfan mynetfan commented Dec 15, 2024

Description

双列菜单布局下,点击顶级菜单可以自动激活上一次激活的子菜单。如果所有子菜单都没有被激活过,自动激活第一个子菜单。
以上功能可在偏好设置中开关。

close #4430

另外,补充一个侧边栏偏好设置:鼠标悬停展开

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Checklist

ℹ️ Check all checkboxes - this will indicate that you have done everything in accordance with the rules in CONTRIBUTING.

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs:dev command.
  • Run the tests with pnpm test.
  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Summary by CodeRabbit

  • New Features

    • Added a new configuration option for the sidebar to automatically activate child menu items.
    • Introduced an option for the sidebar to expand on hover.
    • Enhanced sidebar component with new props and state management for better configurability.
  • Localization

    • Updated English and Chinese language files with new entries for the sidebar options, providing descriptions for new features.
  • Bug Fixes

    • Minor syntactical adjustment made to existing keys in the localization files.

Copy link
Contributor

coderabbitai bot commented Dec 15, 2024

Warning

Rate limit exceeded

@mynetfan has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 13 minutes and 12 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between b732b3e and 7dcaa91.

⛔ Files ignored due to path filters (1)
  • packages/@core/preferences/__tests__/__snapshots__/config.test.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (3)
  • docs/src/en/guide/essentials/settings.md (1 hunks)
  • docs/src/guide/essentials/settings.md (1 hunks)
  • packages/effects/layouts/src/widgets/preferences/blocks/layout/sidebar.vue (2 hunks)

Walkthrough

This pull request introduces a new feature for sidebar menu navigation by adding an autoActivateChild configuration option. The changes span multiple files across the project, implementing a mechanism to automatically activate child menus when a top-level menu is clicked. The modification allows users to configure whether clicking a directory should automatically navigate to its first or previously activated submenu, enhancing the sidebar's interaction model.

Changes

File Change Summary
@core/preferences/src/config.ts Added autoActivateChild: false to default sidebar preferences
@core/preferences/src/types.ts Added autoActivateChild: boolean to SidebarPreferences interface
effects/layouts/src/basic/menu/use-extra-menu.ts Introduced defaultSubMap to track last activated submenu
effects/layouts/src/widgets/preferences/blocks/layout/sidebar.vue Added new props and models for sidebar auto-activate child feature
effects/layouts/src/widgets/preferences/preferences-drawer.vue Added new v-model bindings for sidebar configuration
locales/src/langs/en-US/preferences.json Added translations for autoActivateChild and expandOnHover
locales/src/langs/zh-CN/preferences.json Added Chinese translations for new sidebar configuration options

Assessment against linked issues

Objective Addressed Explanation
Auto-navigate to first/last submenu when directory clicked [#4430]

Possibly related PRs

Suggested reviewers

  • vince292007
  • anncwb

Poem

🐰 A sidebar's dance, a menu's delight,
Clicking paths now leap with might!
Submenus spring, no extra click,
Navigation smooth, oh so slick!
Rabbit's magic, code so bright! 🌟


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

@mynetfan mynetfan changed the title feat: auto activate subMenu on click root menu feat: auto activate subMenu on select root menu Dec 15, 2024
Copy link
Contributor

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

🧹 Nitpick comments (8)
packages/effects/layouts/src/widgets/preferences/blocks/layout/sidebar.vue (1)

30-36: Consider adding aria-label for better accessibility

The expand-on-hover switch implementation looks good, but could benefit from enhanced accessibility.

 <SwitchItem
   v-model="SidebarExpandOnHover"
   :disabled="!sidebarEnable || disabled || !sidebarCollapsed"
   :tip="$t('preferences.sidebar.expandOnHoverTip')"
+  :aria-label="$t('preferences.sidebar.expandOnHover')"
 >
   {{ $t('preferences.sidebar.expandOnHover') }}
 </SwitchItem>
packages/effects/layouts/src/basic/menu/use-extra-menu.ts (3)

18-19: Consider adding JSDoc for the defaultSubMap

The Chinese comment should be translated to English and expanded into proper JSDoc for better maintainability.

-/** 记录当前顶级菜单下哪个子菜单最后激活 */
+/**
+ * Maps root menu paths to their last activated submenu paths
+ * Used to restore submenu selection state when returning to a root menu
+ * @type {Map<string, string>}
+ */

38-43: Consider memory management for defaultSubMap

The implementation should consider clearing old entries from defaultSubMap to prevent memory leaks over time, especially in long-running sessions.

 } else if (preferences.sidebar.autoActivateChild) {
+  // Prevent unlimited growth of the map
+  if (defaultSubMap.size > 100) {
+    const oldestKey = defaultSubMap.keys().next().value;
+    defaultSubMap.delete(oldestKey);
+  }
   await navigation(
     defaultSubMap.has(menu.path)
       ? (defaultSubMap.get(menu.path) as string)
       : menu.path,
   );
 }

38-43: Consider race conditions in navigation

The async navigation and map updates could potentially lead to race conditions. Consider implementing a guard mechanism.

Suggestions:

  1. Add a navigation lock to prevent concurrent navigation attempts
  2. Consider using a more robust state management solution for menu state
  3. Implement proper error handling for navigation failures

Also applies to: 101-101

packages/locales/src/langs/zh-CN/preferences.json (1)

51-52: Consider improving tooltip readability

The tooltip text uses backticks inconsistently and could benefit from better formatting.

Consider this improvement:

-    "expandOnHoverTip": "鼠标在折叠区域悬浮时,`启用`则展开当前子菜单,`禁用`则展开整个侧边栏"
+    "expandOnHoverTip": "鼠标在折叠区域悬浮时:\n- 启用:展开当前子菜单\n- 禁用:展开整个侧边栏"
packages/locales/src/langs/en-US/preferences.json (2)

49-50: Improve grammar in tooltip text

The tooltip text could be more natural in English.

Consider this improvement:

-    "autoActivateChildTip": "`Enabled` to automatically activate the submenu while click menu.",
+    "autoActivateChildTip": "When enabled, automatically activates the submenu when clicking a menu item."

51-52: Enhance tooltip formatting consistency

The tooltip uses a mix of newlines and formatting styles. Let's make it consistent with other tooltips.

Consider this improvement:

-    "expandOnHoverTip": "When the mouse hovers over menu, \n `Enabled` to expand children menus \n `Disabled` to expand whole sidebar."
+    "expandOnHoverTip": "When the mouse hovers over a collapsed menu:\n- Enabled: Expands only the current submenu\n- Disabled: Expands the entire sidebar"
packages/@core/preferences/src/types.ts (1)

128-129: Enhance JSDoc documentation

While the comment is in Chinese, it would be beneficial to add more comprehensive documentation including the default behavior.

Consider this improvement:

-  /** 点击目录时自动激活子菜单   */
+  /**
+   * Automatically activates child menu items when clicking a directory
+   * @description When enabled, clicking a menu item will activate either:
+   * - The last activated submenu, or
+   * - The first submenu if none was previously activated
+   * @default false
+   */
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 22c1f86 and 07bbf67.

📒 Files selected for processing (7)
  • packages/@core/preferences/src/config.ts (1 hunks)
  • packages/@core/preferences/src/types.ts (1 hunks)
  • packages/effects/layouts/src/basic/menu/use-extra-menu.ts (3 hunks)
  • packages/effects/layouts/src/widgets/preferences/blocks/layout/sidebar.vue (2 hunks)
  • packages/effects/layouts/src/widgets/preferences/preferences-drawer.vue (2 hunks)
  • packages/locales/src/langs/en-US/preferences.json (1 hunks)
  • packages/locales/src/langs/zh-CN/preferences.json (1 hunks)
🔇 Additional comments (6)
packages/effects/layouts/src/widgets/preferences/blocks/layout/sidebar.vue (1)

9-9: LGTM: Props and models are well-defined

The new props and models are correctly typed and follow Vue's composition API best practices:

  • currentLayout is properly typed as optional LayoutType
  • Models use the new defineModel syntax for two-way binding

Also applies to: 16-18, 20-20

packages/@core/preferences/src/config.ts (1)

68-68: LGTM: Safe default configuration

The autoActivateChild preference is correctly added with a safe default value of false. This ensures backward compatibility and prevents unexpected behavior for existing users.

packages/effects/layouts/src/basic/menu/use-extra-menu.ts (1)

101-101: 🛠️ Refactor suggestion

Verify path existence before storing in Map

The implementation should verify that the current path exists in the menu structure before storing it.

-if (rootMenuPath) defaultSubMap.set(rootMenuPath, currentPath);
+if (rootMenuPath && findMenu) {
+  defaultSubMap.set(rootMenuPath, currentPath);
+}
packages/locales/src/langs/zh-CN/preferences.json (1)

49-50: LGTM: Clear and concise translation for auto-activate feature

The translation accurately reflects the feature's purpose and maintains consistency with the UI terminology.

packages/@core/preferences/src/types.ts (1)

128-129: Verify the property placement

The new property is appropriately placed in the SidebarPreferences interface and correctly typed as boolean.

Let's verify this is the only interface that needs updating:

✅ Verification successful

Property placement is correct and properly integrated

The autoActivateChild property is correctly placed in the SidebarPreferences interface and is well integrated across the codebase:

  • Default value is set in packages/@core/preferences/src/config.ts
  • Localization strings exist in both en-US and zh-CN locale files
  • Property is actively used in the sidebar menu logic (packages/effects/layouts/src/basic/menu/use-extra-menu.ts)
  • UI implementation exists in the sidebar preferences component
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any other preference interfaces that might need the autoActivateChild property
ast-grep --pattern 'interface $INTERFACE {
  $$$
  activate$_: $_
  $$$
}'

Length of output: 76


Script:

#!/bin/bash
# Let's search for any interfaces or types that might be related to sidebar preferences
rg -l "interface.*Sidebar|type.*Sidebar" --type typescript

# Also search for any usage of autoActivateChild
rg "autoActivateChild" --type typescript

Length of output: 171


Script:

#!/bin/bash
# Let's search for any interfaces or types that might be related to sidebar preferences
rg -l "interface.*Sidebar|type.*Sidebar"

# Also search for any usage of autoActivateChild
rg "autoActivateChild"

Length of output: 1145

packages/effects/layouts/src/widgets/preferences/preferences-drawer.vue (1)

306-312: LGTM! Template changes follow Vue.js best practices

The new v-model bindings are properly implemented with:

  • Consistent kebab-case prop naming in template
  • Appropriate conditional disabling based on layout
  • Alphabetical prop ordering

Copy link

changeset-bot bot commented Dec 15, 2024

⚠️ No Changeset found

Latest commit: 7dcaa91

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

@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 07bbf67 and b732b3e.

📒 Files selected for processing (2)
  • packages/effects/layouts/src/widgets/preferences/blocks/layout/sidebar.vue (2 hunks)
  • packages/effects/layouts/src/widgets/preferences/preferences-drawer.vue (2 hunks)
🔇 Additional comments (4)
packages/effects/layouts/src/widgets/preferences/blocks/layout/sidebar.vue (2)

2-2: LGTM: Props definition looks good

The addition of the optional currentLayout prop of type LayoutType is well-structured and follows Vue's type system conventions.

Also applies to: 9-9


30-36: LGTM: Expand on hover implementation

The implementation of the expand-on-hover feature is well-structured with appropriate disabled state handling based on sidebar state.

packages/effects/layouts/src/widgets/preferences/preferences-drawer.vue (2)

90-93: Maintain consistent naming convention

The same naming inconsistency exists in this file.


306-312: LGTM: Sidebar component integration

The integration of the new preferences with the Sidebar component is well-structured:

  • Proper v-model bindings
  • Correct prop passing for layout-dependent features

@mynetfan mynetfan requested a review from a team as a code owner December 15, 2024 18:49
@mynetfan mynetfan merged commit 2efb5b7 into vbenjs:main Dec 15, 2024
13 checks passed
@mynetfan mynetfan deleted the feat/sidebar-menu branch December 15, 2024 18:57
@github-actions github-actions bot locked and limited conversation to collaborators Jan 15, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FEATURE: 点击目录自动跳转第一项子菜单
1 participant