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: header mixed layout #5263

Merged
merged 4 commits into from
Dec 30, 2024
Merged

Conversation

mynetfan
Copy link
Collaborator

@mynetfan mynetfan commented Dec 30, 2024

Description

新增布局:水平菜单+双列菜单混合。类似混合模式,但左侧使用双列菜单

close #5219
request #5253

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 layout type header-mixed-nav with mixed navigation header configuration
    • Introduced new computed properties and methods to support the new layout type
    • Enhanced menu management and navigation flexibility
  • Localization

    • Updated Chinese language preferences with new menu layout terminology
  • UI Improvements

    • Added new SVG icon for header mixed navigation layout
    • Modified layout and menu component logic to support new navigation mode

Copy link

changeset-bot bot commented Dec 30, 2024

⚠️ No Changeset found

Latest commit: 83648d7

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 bot commented Dec 30, 2024

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/@core/base/typings/src/app.d.ts

Oops! Something went wrong! :(

ESLint: 9.17.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/node_modules/@vben/eslint-config/dist/index.mjs' imported from /eslint.config.mjs
at finalizeResolution (node:internal/modules/esm/resolve:257:11)
at moduleResolve (node:internal/modules/esm/resolve:914:10)
at defaultResolve (node:internal/modules/esm/resolve:1038:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:557:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:525:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:246:38)
at ModuleJob._link (node:internal/modules/esm/module_job:126:49)

Walkthrough

This pull request introduces a new layout type called 'header-mixed-nav', which enhances the application's layout flexibility. The changes span multiple packages, adding support for a mixed navigation header layout. The modifications include updating type definitions, creating new computed properties, adjusting menu handling logic, and introducing a new icon for the layout option. The implementation allows for more dynamic and customizable navigation configurations.

Changes

File Change Summary
packages/@core/base/typings/src/app.d.ts Added 'header-mixed-nav' to LayoutType
packages/@core/preferences/src/use-preferences.ts Added isHeaderMixedNav computed property
packages/@core/ui-kit/layout-ui/src/hooks/use-layout.ts Added isHeaderMixedNav computed property
packages/@core/ui-kit/layout-ui/src/vben-layout.vue Updated computed properties and template bindings for header mixed nav
packages/effects/layouts/src/basic/layout.vue Added variables and updated logic for header mixed nav
packages/effects/layouts/src/basic/menu/use-extra-menu.ts Introduced extraRootMenus and updated menu handling
packages/effects/layouts/src/basic/menu/use-mixed-menu.ts Added new reactive references and computed properties
packages/effects/layouts/src/widgets/preferences/blocks/layout/layout.vue Added HeaderMixedNav component and preset
packages/locales/src/langs/zh-CN/preferences.json Updated menu and layout terminology
packages/utils/src/helpers/find-menu-by-path.ts Modified findRootMenuByPath function to support dynamic menu level

Assessment against linked issues

Objective Addressed Explanation
Custom Layout Implementation [#5219]
Mixed Layout and Dual-Row Coexistence [#5219]

Possibly related PRs

Suggested labels

feature

Suggested reviewers

  • vince292007
  • anncwb

Poem

🐰 A layout dance, mixed and bright,
Navigating paths with rabbit's might!
Headers blend, menus entwine,
Flexibility now truly divine!
Code hops forward, design takes flight! 🚀

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


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/header mixed layout feat: header mixed layout Dec 30, 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: 0

🧹 Nitpick comments (8)
packages/utils/src/helpers/find-menu-by-path.ts (1)

24-24: Ensure clarity in parameter usage.

Adding the level = 0 parameter is a good enhancement. Consider documenting in a JSDoc comment how it influences the indexing of parents, particularly if level might exceed the array bounds.

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

3-3: Potential overhead with nextTick.
Check if nextTick() is necessary at line 56 or if ref updates would suffice immediately.


20-20: Initialize extraRootMenus.
Using a ref for extraRootMenus looks good. Consider validating or resetting it on layout change if needed.


70-76: Side menu mouse leave logic.
Focus on streamlined code by removing commented-out lines (70-73). This helps improve clarity.

-    // const { findMenu, rootMenu, rootMenuPath } = findRootMenuByPath(
-    //   menus.value,
-    //   route.path,
-    // );
calcExtraMenus(route.path);
packages/effects/layouts/src/basic/menu/use-mixed-menu.ts (1)

25-27: Conditionally split with isHeaderMixedNav.
This logic is sound, but be sure any future layout expansions remain consistent here.

packages/effects/layouts/src/widgets/preferences/icons/header-mixed-nav.vue (2)

1-8: Consider providing accessibility attributes for the SVG.

Currently, the markup relies on purely visual attributes, which screen readers may ignore. Consider adding role="img" and/or aria-label (or marking it as decorative with aria-hidden="true") to improve accessibility.


97-129: Avoid excessive id attributes if not actively referenced.

Unless the id attributes (e.g., svg_10, svg_11) are used for advanced styling or scripting, consider removing them to reduce noise in the markup.

packages/effects/layouts/src/basic/layout.vue (1)

117-118: Extended mixed-menu support.

Introducing mixedSidebarActive and mixHeaderMenus helps unify the logic for multiple mixed layout types, allowing the header-based mixed mode to share code.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 07c4ad0 and 83648d7.

📒 Files selected for processing (13)
  • packages/@core/base/typings/src/app.d.ts (1 hunks)
  • packages/@core/preferences/src/use-preferences.ts (3 hunks)
  • packages/@core/ui-kit/layout-ui/src/hooks/use-layout.ts (1 hunks)
  • packages/@core/ui-kit/layout-ui/src/vben-layout.vue (7 hunks)
  • packages/effects/layouts/src/basic/layout.vue (6 hunks)
  • packages/effects/layouts/src/basic/menu/use-extra-menu.ts (5 hunks)
  • packages/effects/layouts/src/basic/menu/use-mixed-menu.ts (4 hunks)
  • packages/effects/layouts/src/widgets/preferences/blocks/layout/layout.vue (3 hunks)
  • packages/effects/layouts/src/widgets/preferences/blocks/layout/sidebar.vue (1 hunks)
  • packages/effects/layouts/src/widgets/preferences/icons/header-mixed-nav.vue (1 hunks)
  • packages/effects/layouts/src/widgets/preferences/icons/index.ts (1 hunks)
  • packages/locales/src/langs/zh-CN/preferences.json (1 hunks)
  • packages/utils/src/helpers/find-menu-by-path.ts (1 hunks)
🔇 Additional comments (32)
packages/effects/layouts/src/widgets/preferences/icons/index.ts (1)

5-5: Smooth integration of new layout icon export.

The addition of HeaderMixedNav export aligns seamlessly with your new layout type. Great to see consistency across the codebase.

packages/utils/src/helpers/find-menu-by-path.ts (1)

26-26: Validate the presence of parent paths.

findMenu?.parents?.[level] could potentially be undefined if parents is absent or shorter than level. You might want to handle edge cases or return early if parents[level] is not found.

packages/@core/ui-kit/layout-ui/src/hooks/use-layout.ts (1)

34-40: Excellent addition of isHeaderMixedNav.

The new computed property cleanly extends the useLayout hook, enabling detection of 'header-mixed-nav'. This change aligns with the new layout option and maintains consistent naming conventions.

Also applies to: 44-44

packages/@core/base/typings/src/app.d.ts (1)

3-3: Layout type extension is consistent.

The addition of 'header-mixed-nav' in LayoutType complements the new layout functionality without breaking existing types.

packages/effects/layouts/src/widgets/preferences/blocks/layout/sidebar.vue (1)

47-47: Ensure consistent naming.
Including 'header-mixed-nav' here aligns with the new layout type. Verify if 'mixed-nav' remains relevant or is partially replaced by 'header-mixed-nav'.

packages/effects/layouts/src/widgets/preferences/blocks/layout/layout.vue (3)

12-12: Import is correct.
The new HeaderMixedNav import follows the consistent naming convention for icons. Looks good.


37-37: Clean expansion of layout.
Adding 'header-mixed-nav': HeaderMixedNav extends the existing record effectively.


61-65: Addition of headerTwoColumn layout.
Adding a new preset for 'header-mixed-nav' is coherent with the design. Ensure the UI translations for headerTwoColumn and headerTwoColumnTip exist.

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

52-58: Asynchronous default menu selection.
Waiting for the DOM update is fine, but ensure that any dependent code also awaits the same cycle if needed.


91-115: Centralized extra menu calculation.
calcExtraMenus significantly improves code organization and maintainability. Confirm if all calls to calcExtraMenus handle potential absence of rootMenu.


117-120: Reactive watch on route & layout.
Watching both route.path and preferences.app.layout ensures the menu updates properly. Good job.

packages/effects/layouts/src/basic/menu/use-mixed-menu.ts (6)

18-19: Extra references for root menu state.
Storing the mixedRootMenuPath and mixExtraMenus is straightforward and keeps logic organized.


22-22: Destructured isHeaderMixedNav.
Neatly integrates the new layout type within existing preferences.


61-63: Header menus with new layout.
mixHeaderMenus effectively merges or replaces headerMenus depending on isHeaderMixedNav. Looks good.


72-74: Sidebar active path.
Using mixedRootMenuPath for the active path properly aligns with the “header-mixed-nav” use case.


133-135: Refined side menus calculation.
Good approach to set the correct root path and store extra menus. Validates well for hierarchical menus.


163-165: Exposing computed references.
Exposing mixedSidebarActive, mixHeaderMenus, and mixExtraMenus fosters reusability across layouts.

packages/effects/layouts/src/widgets/preferences/icons/header-mixed-nav.vue (1)

22-26: Good use of theme-based color tokens.

Using hsl(var(--primary)) ensures the icon remains consistent with the application’s theme, making it more maintainable and easier to adapt for dark/light themes.

packages/@core/preferences/src/use-preferences.ts (2)

85-87: Introduction of isHeaderMixedNav is consistent with new layout.

This provides a clear computed property for detecting the 'header-mixed-nav' layout. Implementation is straightforward and matches the project's structure.


100-105: Verify the side-mode logic for 'header-mixed-nav'.

Including isHeaderMixedNav.value in isSideMode might cause confusion about whether the “header mixed” layout is truly side-based. Confirm that this is intended, especially if future logic expects 'header-mixed-nav' to behave differently from side-based modes.

packages/effects/layouts/src/basic/layout.vue (5)

42-42: Properly retrieving isHeaderMixedNav from preferences.

Good job referencing the new isHeaderMixedNav property. This seamlessly integrates into the existing layout checks.


87-89: Unified approach to collapsible logos.

By extending the condition with isHeaderMixedNav.value, you ensure that the logo collapses consistently across the new layout mode.


93-96: Consistent header visibility checks.

Including isHeaderMixedNav.value ensures that the header navigation is shown in the new layout mode alongside the existing ones.


165-165: Accurate type annotation for setup context slots.

Using SetupContext['slots'] improves clarity and type safety when referencing slot properties.


278-279: Dynamic active path for mixed menu.

Conditionally using mixedSidebarActive or extraActiveMenu promotes consistency when toggling between header-based and side-based mixed modes.

packages/@core/ui-kit/layout-ui/src/vben-layout.vue (6)

90-90: New isHeaderMixedNav import.

The additional computed property keeps the logic consistent across layout variations. No issues observed.


116-118: Conditional collapse width for header-mixed layouts.

Adding isHeaderMixedNav.value ensures the sidebar respects the new layout setting when collapsed, preserving consistent UI behavior.


151-154: Avoid hidden sidebar conflicts.

Explicitly excluding isHeaderMixedNav.value from hidden states ensures the sidebar remains properly visible in the new layout variant.


159-159: Handle normal vs. mixed nav usage.

Correctly applying isHeaderMixedNav.value || isSidebarMixedNav.value means the code gracefully differentiates between layouts, especially for non-mobile states.


185-186: Comprehensive addition to side-mode detection.

Including 'header-mixed-nav' in the isSideMode check ensures consistent features — such as sidebars — remain active in the new layout.


223-223: Maintaining correct layout expansions.

Using (isSidebarMixedNav.value || isHeaderMixedNav.value) to conditionally expand side menus avoids unexpected overlaps or hidden areas, especially during hover.

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

20-22: Well-structured translations that clearly describe the new layout options!

The translations are clear, consistent, and follow good practices:

  • Descriptive Chinese terms that accurately reflect the layout behavior
  • Consistent terminology with existing layout options
  • Clear tooltip explaining the dual-column and horizontal menu coexistence

@mynetfan mynetfan merged commit ff8d5ca into vbenjs:main Dec 30, 2024
14 of 15 checks passed
@mynetfan mynetfan deleted the feat/header-mixed-layout branch December 30, 2024 06:01
little-alei pushed a commit to little-alei/vue-vben-admin that referenced this pull request Jan 6, 2025
* feat: new layout header-mixed

* fix: header-mixed layout update

* feat: layout preference update

* fix: extra menus follow layout setting
@github-actions github-actions bot locked and limited conversation to collaborators Jan 30, 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