-
Notifications
You must be signed in to change notification settings - Fork 355
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: the function of adding and deleting nodes in the outline tree, support undo. #1136
base: develop
Are you sure you want to change the base?
Conversation
WalkthroughThe changes add a delete node functionality to the tree component. A consolidated SVG icon now dynamically toggles between visibility states, and a new delete icon invokes the Changes
Sequence Diagram(s)sequenceDiagram
participant U as User
participant T as Tree Component
participant C as useCanvas API
participant H as useHistory API
U->>T: Clicks delete icon
T->>T: Execute delNode(data)
T->>C: Call deletion with node ID
T->>T: Call clearSelect()
T->>H: Record deletion in history
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (2)
packages/plugins/tree/src/Main.vue (2)
30-31
: Add confirmation dialog before node deletion.To prevent accidental deletions, consider adding a confirmation dialog before executing the delete operation.
- <svg-icon name="delete" @mouseup="delNode(row.rawData)"></svg-icon> + <svg-icon name="delete" @mouseup="confirmDelete(row.rawData)"></svg-icon>Add the confirmation method:
const confirmDelete = (data) => { // Use your UI framework's confirmation dialog if (confirm('Are you sure you want to delete this node?')) { delNode(data) } }
259-270
: Add visual distinction for destructive action.Consider adding a distinct hover color for the delete icon to indicate its destructive nature.
svg.icon-eye, svg.icon-delete, svg.icon-eye-invisible { visibility: hidden; } .tree-row:hover { svg.icon-eye, - svg.icon-delete, svg.icon-eye-invisible { visibility: unset; } + svg.icon-delete { + visibility: unset; + &:hover { + color: var(--te-color-error); + } + } }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/plugins/tree/src/Main.vue
(5 hunks)
🔇 Additional comments (1)
packages/plugins/tree/src/Main.vue (1)
30-31
: LGTM! Well-structured implementation of node deletion with undo support.The changes effectively implement the node deletion feature with proper integration of history management for undo support. The code maintains consistency with the existing patterns and provides a good user experience.
Also applies to: 141-149, 259-270
const delNode = (data) => { | ||
const { clearSelect } = useCanvas().canvasApi.value | ||
useCanvas().operateNode({ | ||
type: 'delete', | ||
id: data.id | ||
}) | ||
clearSelect() | ||
useHistory().addHistory() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add error handling to delNode method.
The deletion operation should handle potential failures gracefully.
const delNode = (data) => {
+ try {
const { clearSelect } = useCanvas().canvasApi.value
useCanvas().operateNode({
type: 'delete',
id: data.id
})
clearSelect()
useHistory().addHistory()
+ } catch (error) {
+ console.error('Failed to delete node:', error)
+ // Use your UI framework's error notification
+ useMessage().error('Failed to delete node')
+ }
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
const delNode = (data) => { | |
const { clearSelect } = useCanvas().canvasApi.value | |
useCanvas().operateNode({ | |
type: 'delete', | |
id: data.id | |
}) | |
clearSelect() | |
useHistory().addHistory() | |
} | |
const delNode = (data) => { | |
try { | |
const { clearSelect } = useCanvas().canvasApi.value | |
useCanvas().operateNode({ | |
type: 'delete', | |
id: data.id | |
}) | |
clearSelect() | |
useHistory().addHistory() | |
} catch (error) { | |
console.error('Failed to delete node:', error) | |
// Use your UI framework's error notification | |
useMessage().error('Failed to delete node') | |
} | |
} |
the function of adding and deleting nodes in the outline tree, support undo.
(大纲树增加删除功能,支持撤销)
English | 简体中文
PR
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
Background and solution
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Other information
Summary by CodeRabbit
New Features
Style