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: menu routing support opens in a new window #4715

Merged
merged 1 commit into from
Oct 22, 2024
Merged

feat: menu routing support opens in a new window #4715

merged 1 commit into from
Oct 22, 2024

Conversation

anncwb
Copy link
Collaborator

@anncwb anncwb commented Oct 22, 2024

Description

close #4699
fixed #4707

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

Release Notes

  • New Features

    • Introduced the ability to open routes in a new window via the openInNewWindow property.
    • Added a new demo for opening a window in the application.
  • Documentation

    • Enhanced routing documentation with clearer explanations and examples for static and dynamic routes.
    • Updated the guide to include new properties and methods related to route configuration.
  • Bug Fixes

    • Adjusted navigation logic to ensure proper handling of routes with the new window feature.
  • UI Enhancements

    • Added a new Vue component to display messages for pages opened in a new window.

@anncwb anncwb added the feature label Oct 22, 2024
@anncwb anncwb requested review from vince292007 and a team as code owners October 22, 2024 14:14
Copy link

changeset-bot bot commented Oct 22, 2024

⚠️ No Changeset found

Latest commit: 400b916

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 Oct 22, 2024

Walkthrough

The pull request introduces significant enhancements to routing and menu configuration documentation, clarifying the distinctions between static and dynamic routes. It adds a new property, openInNewWindow, to the RouteMeta interface across multiple files, facilitating the opening of routes in new windows. Additionally, new functions and components are introduced to support this feature, alongside updates to existing routing structures and examples. The changes aim to improve clarity and usability in routing configurations and related components.

Changes

File Change Summary
docs/src/en/guide/essentials/route.md
docs/src/guide/essentials/route.md
Enhanced documentation on routing, added examples for static and dynamic routes, clarified routing types, and introduced the openInNewWindow property in RouteMeta.
packages/@core/base/shared/src/utils/window.ts Added openRouteInNewWindow function to open specified routes in a new window; updated export statement.
packages/@core/base/typings/src/vue-router.d.ts Added openInNewWindow property to RouteMeta interface.
packages/@core/ui-kit/shadcn-ui/src/components/breadcrumb/breadcrumb-background.vue Updated handleClick function to include index parameter and modified click event logic.
packages/effects/layouts/src/basic/menu/use-navigation.ts Enhanced type safety and modified navigation logic to utilize openInNewWindow property.
packages/stores/src/modules/tabbar.ts Renamed openWindow to openRouteInNewWindow and simplified openTabInNewWindow method.
playground/src/locales/langs/en-US/demos.json
playground/src/locales/langs/zh-CN/demos.json
Added openInNewWindow key-value pair in features section for English and Chinese locales.
playground/src/router/routes/modules/demos.ts Added NewWindowDemo route and updated title for FullScreenDemo.
playground/src/views/demos/features/new-window/index.vue Introduced new Vue component utilizing <Fallback> to display new window message.
pnpm-workspace.yaml Updated dependency versions for several packages without adding or removing any packages.

Possibly related PRs

Suggested reviewers

  • vince292007

Poem

🐰 In the world of routes so bright,
A new window opens, what a sight!
With menus dancing, clear and true,
Hop along, there's much to do!
Click and explore, let joy abound,
In every corner, new paths found! 🌟


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.

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

🧹 Outside diff range and nitpick comments (11)
packages/@core/base/shared/src/utils/window.ts (1)

26-35: LGTM with minor suggestions for improvement

The openRouteInNewWindow function is well-implemented and aligns with the PR objectives. It correctly constructs the URL and uses the existing openWindow function. However, consider the following improvements:

  1. Add JSDoc for the path parameter to improve developer understanding.
  2. Consider adding error handling for invalid paths.

Here's a suggested improvement with JSDoc and basic error handling:

/**
 * Opens a route in a new window.
 * @param path - The route path to open. Can be absolute or relative.
 * @throws {Error} If the path is empty or not a string.
 */
function openRouteInNewWindow(path: string) {
  if (typeof path !== 'string' || path.trim() === '') {
    throw new Error('Invalid path provided');
  }
  const { hash, origin } = location;
  const fullPath = path.startsWith('/') ? path : `/${path}`;
  const url = `${origin}${hash ? '/#' : ''}${fullPath}`;
  openWindow(url, { target: '_blank' });
}
playground/src/locales/langs/zh-CN/demos.json (1)

52-52: LGTM: New translation added for 'Open in New Window' feature

The addition of "openInNewWindow": "新窗口打开" correctly implements the Chinese translation for the new feature to open menu items in a new window. This aligns with the PR objectives and the changes in routing configuration.

Consider adding a comment above this line to explain the purpose of this feature, which might help other developers understand its significance:

 "menuWithQuery": "带参菜单",
+// 允许在新窗口中打开菜单项
 "openInNewWindow": "新窗口打开"
playground/src/locales/langs/en-US/demos.json (1)

51-52: LGTM! Consider adding translations for other supported languages.

The addition of "openInNewWindow": "Open in New Window" is appropriate and aligns with the new feature. The English text is clear and concise.

To maintain consistency across the application, consider adding corresponding translations for this new feature in other supported language files (if any) within the locales/langs/ directory.

packages/@core/base/typings/src/vue-router.d.ts (1)

101-104: LGTM! Consider enhancing the JSDoc comment.

The addition of the openInNewWindow property is well-implemented and aligns with the PR objective. The property is correctly typed as an optional boolean.

Consider expanding the JSDoc comment to provide more context:

/**
 * Indicates whether the route should open in a new window/tab when accessed.
 * @default false
 */
openInNewWindow?: boolean;

This enhancement provides more clarity on the property's behavior and default value.

docs/src/guide/essentials/route.md (3)

Line range hint 1-24: LGTM! Clear explanation of routing types and menu generation.

The updated introduction and routing types section provide a clearer explanation of how the framework handles routing and menu generation. The distinction between static and dynamic routes is well-defined.

Consider adding a brief example or diagram to illustrate the difference between static and dynamic routes for visual learners.


Line range hint 26-385: Excellent additions for route definition and page creation.

The new sections on route definition and adding pages provide clear, practical guidance with well-structured examples. This will greatly assist users in implementing both simple and complex routing structures.

Consider adding a brief note about best practices for organizing route files in larger projects, such as grouping routes by feature or module.


Line range hint 385-552: Comprehensive update to RouteMeta interface and configuration options.

The addition of the openInNewWindow property to the RouteMeta interface is well-documented and aligns with the PR objectives. The expanded explanations for each configuration option provide valuable context for users.

Consider adding a brief example demonstrating how to use the openInNewWindow property in a route configuration to further clarify its usage.

packages/stores/src/modules/tabbar.ts (1)

293-293: Simplify openTabInNewWindow method

The method has been refactored to use the new openRouteInNewWindow function, which simplifies the logic and improves consistency. This change aligns well with the new feature for opening routes in new windows.

Consider using optional chaining for a more concise expression:

-openRouteInNewWindow(tab.fullPath || tab.path);
+openRouteInNewWindow(tab.fullPath ?? tab.path);

This change would use tab.path only if tab.fullPath is null or undefined, which might be more precise depending on your use case.

docs/src/en/guide/essentials/route.md (2)

Line range hint 1-38: LGTM! Clear explanations and updated examples.

The introduction and route types sections have been significantly improved. The distinction between static and dynamic routes is now clearer, and the code examples for static routes configuration have been updated.

Consider adding a brief explanation of when to use static vs. dynamic routes to help developers choose the appropriate approach for their use case.


Line range hint 40-205: Great addition of detailed routing examples!

The examples for secondary and multilevel routing are comprehensive and provide valuable guidance for implementing complex routing structures.

For the multilevel routing example, consider breaking it down into smaller sections with explanations for each level. This could help readers better understand the structure and purpose of each nested route.

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

9-9: Rename 'routeMetaMap' to 'routeMap' for clarity

Since the map now stores entire route objects rather than just their meta properties, consider renaming routeMetaMap to routeMap to better reflect its purpose.

Apply this diff to rename the variable:

-const routeMetaMap = new Map<string, RouteRecordNormalized>();
+const routeMap = new Map<string, RouteRecordNormalized>();

-routes.forEach((route) => {
-  routeMetaMap.set(route.path, route);
-});
+routes.forEach((route) => {
+  routeMap.set(route.path, route);
+});

-const route = routeMetaMap.get(path);
+const route = routeMap.get(path);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between f60796f and 400b916.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (12)
  • docs/src/en/guide/essentials/route.md (1 hunks)
  • docs/src/guide/essentials/route.md (2 hunks)
  • packages/@core/base/shared/src/utils/window.ts (1 hunks)
  • packages/@core/base/typings/src/vue-router.d.ts (1 hunks)
  • packages/@core/ui-kit/shadcn-ui/src/components/breadcrumb/breadcrumb-background.vue (2 hunks)
  • packages/effects/layouts/src/basic/menu/use-navigation.ts (1 hunks)
  • packages/stores/src/modules/tabbar.ts (2 hunks)
  • playground/src/locales/langs/en-US/demos.json (1 hunks)
  • playground/src/locales/langs/zh-CN/demos.json (1 hunks)
  • playground/src/router/routes/modules/demos.ts (2 hunks)
  • playground/src/views/demos/features/new-window/index.vue (1 hunks)
  • pnpm-workspace.yaml (3 hunks)
🧰 Additional context used
🔇 Additional comments (18)
playground/src/views/demos/features/new-window/index.vue (2)

1-3: LGTM: Script section is well-structured.

The script section is concise, uses TypeScript, and correctly imports the Fallback component. It follows the Vue 3 composition API style with <script setup>.


5-11: LGTM: Template structure and Fallback component usage are correct.

The Fallback component is properly implemented with appropriate props for description, status, and title. This effectively communicates that the page has been opened in a new window.

packages/@core/base/shared/src/utils/window.ts (1)

37-37: Export statement looks good

The export statement correctly includes both the new openRouteInNewWindow function and the existing openWindow function, making them available for use in other parts of the application.

playground/src/locales/langs/zh-CN/demos.json (1)

51-51: LGTM: Trailing comma added

Adding a trailing comma after the last item in an object or array is a good practice. It makes future additions easier and reduces diff noise in version control.

packages/@core/ui-kit/shadcn-ui/src/components/breadcrumb/breadcrumb-background.vue (3)

9-9: Improved props handling and click logic

The changes in the script section enhance the component's functionality and readability:

  1. Props handling (line 9): The switch to direct destructuring from defineProps<Props>() simplifies the code and aligns with modern Vue 3 practices.

  2. handleClick function (lines 13-17): The addition of the index parameter and the check for the last breadcrumb item prevent unnecessary 'select' events for the current page, improving the component's behavior.

These changes improve both the code quality and the breadcrumb's functionality.

Also applies to: 13-17


28-31: Updated click event handler in template

The modification to the click event handler in the template (lines 28-31) correctly implements the changes made to the handleClick function:

  1. It now passes both the index and item.path to handleClick, aligning with the updated function signature.
  2. This change enables the new logic in handleClick to identify the last breadcrumb item.
  3. The use of @click.stop is maintained, preventing unintended event propagation.

This update ensures consistency between the template and the script, maintaining the improved breadcrumb functionality.


Line range hint 1-31: Overall improvement to breadcrumb component

The changes made to this component collectively enhance its functionality and align with modern Vue 3 practices:

  1. The props handling has been simplified using direct destructuring.
  2. The handleClick function now considers the breadcrumb item's position, preventing unnecessary actions on the last item.
  3. The template has been updated to correctly utilize the new handleClick function signature.

These improvements contribute to a more robust and user-friendly breadcrumb navigation, aligning well with the PR's objective of enhancing routing capabilities. The code is now more maintainable and provides a better user experience by disabling clicks on the current page's breadcrumb.

pnpm-workspace.yaml (1)

46-46: LGTM: Minor version updates for development dependencies.

The changes include minor version updates for the following packages:

  • @types/node: ^22.7.7 to ^22.7.8
  • @typescript-eslint/eslint-plugin and @typescript-eslint/parser: ^8.10.0 to ^8.11.0
  • eslint-config-turbo: ^2.2.1 to ^2.2.3
  • turbo: ^2.2.1 to ^2.2.3

These updates are likely to include bug fixes and small improvements. The synchronized updates for related packages (@typescript-eslint/* and turbo-related) are good practice.

Please ensure these updates align with the project's dependency update policy and that they don't introduce any unexpected changes in the development environment.

Also applies to: 51-52, 87-87, 156-156

docs/src/guide/essentials/route.md (2)

Line range hint 553-568: Useful addition of route refresh functionality.

The new section on route refreshing provides a clear and concise example of how to programmatically refresh routes using the useRefresh hook. This is a valuable addition to the documentation.


Line range hint 1-568: Comprehensive and well-structured update to routing documentation.

This update significantly enhances the routing and menu configuration documentation. Key improvements include:

  1. Clearer explanations of routing types and automatic menu generation.
  2. Detailed examples for second-level and multi-level routes.
  3. Step-by-step guide for adding new pages.
  4. Addition of the openInNewWindow property to the RouteMeta interface.
  5. Expanded documentation for each configuration option.
  6. New section on route refreshing.

These changes provide users with a more comprehensive understanding of the routing system and practical guidance for implementation.

packages/stores/src/modules/tabbar.ts (2)

7-7: Update import statement to use openRouteInNewWindow

The import statement has been updated to use openRouteInNewWindow instead of openWindow. This change aligns with the refactoring of the window opening functionality.


Line range hint 1-593: Summary of changes and their impact

The changes in this file are minimal and focused on implementing the new feature for opening routes in new windows. The modifications are well-contained and don't introduce any breaking changes to the existing tab management functionality. These updates align perfectly with the PR objective of adding menu routing support for opening in a new window.

Key points:

  1. The import statement has been updated to use the new openRouteInNewWindow function.
  2. The openTabInNewWindow method has been simplified to use this new function.

These changes enhance the tab management system by providing a more streamlined way to open tabs in new windows, improving the overall user experience.

docs/src/en/guide/essentials/route.md (3)

Line range hint 207-258: LGTM! Clear instructions for adding new pages.

The step-by-step guide for adding a new page, including both route configuration and component creation, is well-structured and easy to follow.


Line range hint 392-406: LGTM! Useful example for route refreshing.

The addition of a code example for refreshing the current route is a helpful feature for developers. It's concise and easy to understand.


Line range hint 260-390: Excellent documentation of route configuration options!

The comprehensive list of route configuration options, including detailed explanations, provides valuable guidance for developers. The addition of the openInNewWindow property to the RouteMeta interface aligns well with the PR objective of supporting menu routing that opens in a new window.

To ensure consistency across the codebase, let's verify the implementation of the openInNewWindow property:

✅ Verification successful

Verification Successful

The openInNewWindow property is properly defined and utilized across the codebase as intended.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation and usage of the openInNewWindow property

# Test 1: Check for the property definition in relevant files
echo "Checking for openInNewWindow property definition:"
rg "openInNewWindow\??:\s*boolean" --type ts

# Test 2: Search for usage of the openInNewWindow property in the codebase
echo "Checking for openInNewWindow property usage:"
rg "openInNewWindow" --type vue --type ts

Length of output: 401


Script:

#!/bin/bash
# Description: Verify the usage of the openInNewWindow property in .vue and .ts files

# Test 1: Check for the property definition in relevant files
echo "Checking for openInNewWindow property definition:"
rg "openInNewWindow\??:\s*boolean" --type ts

# Test 2: Search for usage of the openInNewWindow property in the codebase
echo "Checking for openInNewWindow property usage:"
rg "openInNewWindow" -g "*.vue" -g "*.ts"

Length of output: 983

playground/src/router/routes/modules/demos.ts (2)

177-177: LGTM: FullScreenDemo title update

The title update for the FullScreenDemo route improves clarity and consistency.


203-213: LGTM: NewWindowDemo route addition

The new route for NewWindowDemo is well-structured and aligns perfectly with the PR objective of adding support for opening menu routes in a new window. The openInNewWindow: true property in the meta object is crucial for implementing this feature.

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

20-21: Confirm the functionality of 'openRouteInNewWindow'

Ensure that the openRouteInNewWindow function correctly handles route paths and includes necessary query parameters or state. Missing these could lead to incomplete or incorrect navigation when opening in a new window.

Run the following script to check the implementation of openRouteInNewWindow:

#!/bin/bash
# Description: Find the implementation of 'openRouteInNewWindow' and display its code.

# Expected: The function definition of 'openRouteInNewWindow'.

rg 'function openRouteInNewWindow' --type ts -A 10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
1 participant