Skip to content

feat: 添加大纲树节点删除功能 #1216

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

Merged
merged 1 commit into from
Mar 14, 2025

Conversation

1degrees
Copy link
Contributor

@1degrees 1degrees commented Mar 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?

2025-03-13.17.14.26.mov

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features
    • Simplified the visibility icon rendering for a more consistent display.
    • Introduced a new delete icon that allows users to remove nodes directly from the tree, supporting undo actions.
  • Style
    • Enhanced visual styling to ensure icons are displayed appropriately during interaction.

Copy link
Contributor

coderabbitai bot commented Mar 13, 2025

Walkthrough

The changes update the tree component in the UI by streamlining the eye icon rendering and adding a new delete icon. The two separate SVG elements for the eye condition are merged into one dynamic element based on the eyeOpen(row.id) function. A new <svg-icon> is added for deletion, which triggers a newly defined delNode method on mouseup events to delete nodes from the canvas, clear selections, and record the action in history. Additionally, the history management is imported and CSS rules are updated to show the delete icon on hover.

Changes

File Change Summary
packages/.../Main.vue Merged two conditional <svg-icon> elements into one dynamic icon for eye visibility; introduced a new delete icon triggering delNode on mouseup; added delNode method with calls to delete the node, clear selection, and update history; imported useHistory and updated CSS for delete icon visibility.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant C as Main.vue
    participant Canvas as Canvas Module
    participant H as History Module

    U->>C: Mouseup on delete icon
    C->>Canvas: Delete node and clear selection
    C->>H: Record deletion in history
Loading

Possibly related PRs

  • feat: outline tree support dragging #1050: The changes in the main PR are related to the introduction of the DraggableTree component, which is also referenced in the retrieved PR that enhances dragging functionality within tree structures.
  • fix:missing outline tree eyes icon #900: The changes in the main PR introduce a new delNode method and modify the rendering logic for eye icons, while the retrieved PR focuses on simplifying event handling and state management for the visibility of the eye icon, indicating a direct relationship in their modifications to the eye icon's functionality.

Suggested labels

ospp-2024

Suggested reviewers

  • chilingling
  • hexqi

Poem

I'm a little rabbit with joyful hops,
Skipping through code like enchanted crops,
Conquering icons and delete clicks so neat,
With each refactor, my heart skips a beat.
Celebrate the code, let the changes bloom,
In a forest of logic, I cheer in full zoom!
🐰💻 Happy coding!

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.

 ERR_PNPM_OPTIONAL_DEPS_REQUIRE_PROD_DEPS  Optional dependencies cannot be installed without production dependencies

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.

🪧 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.
  • @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 enhancement New feature or request label Mar 13, 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 (1)
packages/plugins/tree/src/Main.vue (1)

136-144: Consider adding confirmation for node deletion

The implementation of the delete node functionality works well. However, since deletion is a destructive operation, consider adding a confirmation dialog to prevent accidental deletions of important nodes.

const delNode = (data) => {
+  const { message } = useMessage()
  const { clearSelect } = useCanvas().canvasApi.value
-  useCanvas().operateNode({
-    type: 'delete',
-    id: data.id
-  })
-  clearSelect()
-  useHistory().addHistory()
+  message.confirm({
+    message: '确定要删除此节点吗?',
+    onConfirm: () => {
+      useCanvas().operateNode({
+        type: 'delete',
+        id: data.id
+      })
+      clearSelect()
+      useHistory().addHistory()
+    }
+  })
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 38fe39c and 2ebd571.

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

30-31: UI enhancement: Added node deletion capability alongside visibility toggle

Good implementation of the delete node functionality. The code now provides both visibility control (eye icon) and node deletion (delete icon) capabilities. The consolidated eye icon implementation is also a nice cleanup.


44-44: Added history tracking for node deletion

Good addition of the useHistory import to enable undo/redo functionality for node deletion operations.


211-211: Properly exposed delNode function to the template

The new function is correctly exposed in the setup return object.


246-256: UI behavior aligned between eye and delete icons

Good CSS implementation that ensures the delete icon follows the same visibility behavior as the eye icon - only appearing when hovering over a tree row. This creates a consistent user experience.

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 (2)
packages/plugins/tree/src/Main.vue (2)

31-31: Added delete functionality as requested in PR

The implementation adds a delete icon that calls the new delNode method. This correctly implements the feature described in the PR objectives.

Consider adding a confirmation dialog before deleting nodes, especially for nodes that might contain children or are critical to the page structure.


136-144: Well-structured node deletion implementation

The delNode implementation correctly:

  1. Uses the canvas API for node deletion
  2. Clears selection after deletion to prevent UI issues
  3. Records the action in history for undo functionality

Consider adding:

  1. Error handling in case the deletion operation fails
  2. Validation to prevent deletion of essential nodes (if applicable)
 const delNode = (data) => {
   const { clearSelect } = useCanvas().canvasApi.value
+  try {
     useCanvas().operateNode({
       type: 'delete',
       id: data.id
     })
     clearSelect()
     useHistory().addHistory()
+  } catch (error) {
+    console.error('Failed to delete node:', error)
+    // Consider adding a user notification here
+  }
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2ebd571 and f038413.

📒 Files selected for processing (1)
  • packages/plugins/tree/src/Main.vue (5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: push-check
🔇 Additional comments (5)
packages/plugins/tree/src/Main.vue (5)

30-30: Code improvement - streamlined SVG icon implementation

The consolidation of two separate SVG icon elements into a single element with a dynamic name attribute is a good refactoring that reduces template complexity while maintaining the same functionality.


44-44: Good practice: Added history tracking for deletion actions

Adding the useHistory import ensures that deletion operations can be undone, which is essential for a good user experience in any editing interface.


211-211: Correctly exposing the new method

The delNode method is properly exposed in the returned object, making it accessible to the template. This follows Vue 3 Composition API best practices.


246-248: Consistent styling for both icons

The CSS selector now includes both the eye and delete icons, ensuring consistent visibility rules for both controls.


250-254: Consistent hover behavior for all controls

The hover style now properly applies to both icons, creating a consistent user experience where all available actions become visible on hover.

@1degrees 1degrees force-pushed the feat/delNodeInTree branch from f038413 to 27845c6 Compare March 13, 2025 09:46
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 (1)
packages/plugins/tree/src/Main.vue (1)

136-144: Consider adding a confirmation dialog for deletion

The implementation of delNode is functional but could benefit from a confirmation step before deletion to prevent accidental deletions. Also, consider adding error handling to provide feedback if the deletion fails.

const delNode = (data) => {
  const { clearSelect } = useCanvas().canvasApi.value
-  useCanvas().operateNode({
-    type: 'delete',
-    id: data.id
-  })
-  clearSelect()
-  useHistory().addHistory()
+  const { message } = useMessage()
+  message({
+    type: 'confirm',
+    title: '确认删除',
+    message: `确定要删除节点 "${data.componentName}" 吗?`,
+    callback: () => {
+      try {
+        useCanvas().operateNode({
+          type: 'delete',
+          id: data.id
+        })
+        clearSelect()
+        useHistory().addHistory()
+      } catch (error) {
+        message({
+          type: 'error',
+          message: `删除失败: ${error.message || '未知错误'}`
+        })
+      }
+    }
+  })
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f038413 and 27845c6.

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

30-31: Nice refactoring of the eye icons and addition of deletion functionality

You've effectively consolidated the eye icon implementation into a single conditional element and added a new delete icon. This is a good UI enhancement that keeps the interface consistent.


44-44: LGTM - Appropriate addition of useHistory import

The import of useHistory is correctly added to support the undo functionality for node deletion.


211-211: LGTM - Properly exposed the new method

Good job exposing the delNode method in the returned object to make it available to the template.


246-248: LGTM - Consistent styling for both icons

The CSS updates correctly maintain the same visibility behavior for both the eye and delete icons, showing them only on hover. This keeps the UI clean and consistent.

Also applies to: 250-254

@chilingling chilingling merged commit 46dbbe8 into opentiny:develop Mar 14, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants