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: route bar support display preview path #1118

Merged

Conversation

gene9831
Copy link
Collaborator

@gene9831 gene9831 commented Feb 13, 2025

English | 简体中文

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • Built its own designer, fully self-validated

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

Background and solution

What is the current behavior?

Issue Number: N/A

What is the new behavior?

  • 路由bar支持显示预览路径
  • 当前编辑页面加粗(只有一个route页面时不加粗),编辑页面的路由后的路径的颜色变浅
  • 支持一键清除预览路径。当预览页面时编辑页面的子孙时可以在路由bar上点击清除按钮

image

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features
    • Enhanced the route bar with dynamic visual cues, including conditional bold styling.
    • Introduced an interactive tooltip to indicate the existence of a preview route.
    • Improved state management to ensure that navigation and preview signals are consistently reflected in the UI.

Copy link
Contributor

coderabbitai bot commented Feb 13, 2025

Walkthrough

The changes modify the CanvasRouteBar.vue file. The template now includes an index in the v-for directive and enhanced class bindings, along with a new conditional tooltip component. In the script section, initialization for previewId and existsPreview has been added, and the watch function is updated to observe both pageId and previewId. Additional helper methods (fontIsBold and handleClearPreview) have been introduced for managing route preview and visual styling.

Changes

File(s) Changes
packages/canvas/route-bar/src/CanvasRouteBar.vue - Template: Added index parameter in v-for, enhanced class bindings to include bold and is-preview, and conditionally rendered tiny-tooltip.
- Script: Initialized previewId and existsPreview, updated the watch function to observe pageId and previewId, mapped routes to include isPreview, and added helper functions fontIsBold and handleClearPreview.

Sequence Diagram(s)

sequenceDiagram
    participant UI as CanvasRouteBar.vue
    participant API as Meta API
    participant GS as Global Service

    UI->>API: Request baseInfo (includes previewId)
    API-->>UI: Return baseInfo
    UI->>UI: Initialize previewId and existsPreview
    UI->>UI: onMounted updates previewId if data present
    UI->>UI: Watch changes on pageId and previewId
    UI->>GS: Call handleClearPreview to reset preview state
Loading

Possibly related PRs

Suggested reviewers

  • chilingling

Poem

I'm a happy rabbit, hopping through code,
A tweak here, a tweak there, in every node.
Routes now shimmer with a bold, bright gleam,
Tiny tooltips guide the way like a dream.
With each new function, my joy's in full mode! 🐇🌟

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/canvas/route-bar/src/CanvasRouteBar.vue

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "@typescript-eslint/eslint-plugin".

(The package "@typescript-eslint/eslint-plugin" was not found when loaded as a Node module from the directory "/packages/canvas".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install @typescript-eslint/eslint-plugin@latest --save-dev

The plugin "@typescript-eslint/eslint-plugin" was referenced from the config file in "packages/canvas/.eslintrc.cjs » @vue/eslint-config-typescript".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.


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.

@github-actions github-actions bot added the refactor-main refactor/develop branch feature label Feb 13, 2025
@gene9831 gene9831 changed the title Feat/router bar display preview feat: route bar support display preview path Feb 14, 2025
@github-actions github-actions bot added the enhancement New feature or request label Feb 14, 2025
@gene9831 gene9831 marked this pull request as ready for review February 14, 2025 08:56
@gene9831 gene9831 added this to the v2.3.0 milestone Feb 14, 2025
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 (4)
packages/canvas/route-bar/src/CanvasRouteBar.vue (4)

18-20: Consider i18n support for the tooltip content.

The tooltip text "重置路由视图为占位符" should be internationalized for better maintainability and multi-language support.

-      <tiny-tooltip v-if="existsPreview" type="normal" content="重置路由视图为占位符">
+      <tiny-tooltip v-if="existsPreview" type="normal" :content="t('resetRouteViewToPlaceholder')">

79-119: Consider extracting string conversion logic.

The string conversion logic is repeated in multiple places. Consider extracting it into a utility function for consistency and maintainability.

+const toStringId = (id) => String(id)
+
 watch(
   [pageId, previewId],
   async ([pageId, previewId]) => {
     if (!pageId) {
       routes.value = []
       return
     }

-    let ancestors = ((await getAncestors(pageId, true)) || []).concat(pageId).map((id) => String(id))
+    let ancestors = ((await getAncestors(pageId, true)) || []).concat(pageId).map(toStringId)

     if (previewId) {
-      const previewAncestors = ((await getAncestors(previewId, true)) || []).concat(previewId).map((id) => String(id))
+      const previewAncestors = ((await getAncestors(previewId, true)) || []).concat(previewId).map(toStringId)

       if (previewAncestors.includes(pageId)) {
         ancestors = previewAncestors
       }
     }

144-146: Add error handling for preview reset.

The handleClearPreview function should handle potential errors when updating the preview ID.

 const handleClearPreview = () => {
-  getMetaApi(META_SERVICE.GlobalService).updatePreviewId('')
+  try {
+    getMetaApi(META_SERVICE.GlobalService).updatePreviewId('')
+  } catch (error) {
+    console.error('Failed to clear preview:', error)
+    // Consider showing a user-friendly error message
+  }
 }

180-199: Consider adding smooth transitions.

The visual changes could benefit from smooth transitions for better user experience.

 .is-preview {
   color: var(--te-common-text-weaken);
+  transition: color 0.2s ease;
 }
 .clear-preview {
   border-radius: 999px;
   visibility: hidden;
   margin-left: 2px;
   width: 16px;
   height: 16px;
   font-size: 12px;
+  transition: visibility 0.2s ease;
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4429189 and 84e2b2c.

📒 Files selected for processing (1)
  • packages/canvas/route-bar/src/CanvasRouteBar.vue (6 hunks)
🔇 Additional comments (2)
packages/canvas/route-bar/src/CanvasRouteBar.vue (2)

26-28: LGTM!

The imports are well-organized and correctly support the new functionality.


38-41: LGTM!

The state management is well-implemented using Vue's reactivity system with proper initialization from baseInfo.

@gene9831
Copy link
Collaborator Author

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Feb 14, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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 (3)
packages/canvas/route-bar/src/CanvasRouteBar.vue (3)

38-41: Consider adding type annotations for improved maintainability.

The state management is well-structured, but type annotations would make it more maintainable.

-const baseInfo = getMetaApi(META_SERVICE.GlobalService).getBaseInfo()
-const pageId = ref(baseInfo.pageId)
-const previewId = ref(baseInfo.previewId)
-const existsPreview = ref(false)
+/** @type {import('vue').Ref<string>} */
+const pageId = ref(baseInfo.pageId)
+/** @type {import('vue').Ref<string>} */
+const previewId = ref(baseInfo.previewId)
+/** @type {import('vue').Ref<boolean>} */
+const existsPreview = ref(false)

51-56: Consider adding type guards for more robust event handling.

The string conversion is good, but type guards would make the code more robust.

-if (data.pageId) {
+if (typeof data.pageId !== 'undefined') {
   pageId.value = String(data.pageId)
 }
-if ('previewId' in data) {
+if (typeof data.previewId !== 'undefined') {
   previewId.value = String(data.previewId)
 }

121-146: Consider adding return type annotations for clarity.

The methods are well-implemented, but return type annotations would improve clarity.

-const shouldHighlight = (id, index) => {
+/** @returns {boolean} */
+const shouldHighlight = (id, index) => {
   // ... implementation
 }

-const handleClearPreview = () => {
+/** @returns {void} */
+const handleClearPreview = () => {
   // ... implementation
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 84e2b2c and 01a5484.

📒 Files selected for processing (1)
  • packages/canvas/route-bar/src/CanvasRouteBar.vue (6 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: push-check
🔇 Additional comments (4)
packages/canvas/route-bar/src/CanvasRouteBar.vue (4)

4-20: LGTM! The template changes enhance user experience.

The template improvements provide clear visual feedback and intuitive controls:

  • Index-based route highlighting
  • Visual distinction for preview paths
  • Accessible tooltip for the reset button

26-28: LGTM! Imports align with new functionality.

The added imports support the new UI elements for preview path management.


79-119: LGTM! Well-structured and documented watch logic.

The watch implementation effectively handles both regular and preview paths with clear comments explaining the logic.


180-199: LGTM! Styles follow project conventions.

The styles effectively use CSS variables and provide appropriate visual feedback for the preview path feature.

@hexqi hexqi merged commit 770eeeb into opentiny:refactor/develop Feb 18, 2025
2 checks passed
@gene9831 gene9831 deleted the feat/router-bar-display-preview branch February 19, 2025 01:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request refactor-main refactor/develop branch feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants