Skip to content

feat(rust tui): add delete uri funciton with confirmation and refresh behaviour#696

Open
xiaobin83 wants to merge 4 commits intovolcengine:mainfrom
xiaobin83:feature/manage-record-tui
Open

feat(rust tui): add delete uri funciton with confirmation and refresh behaviour#696
xiaobin83 wants to merge 4 commits intovolcengine:mainfrom
xiaobin83:feature/manage-record-tui

Conversation

@xiaobin83
Copy link

@xiaobin83 xiaobin83 commented Mar 17, 2026

Description

This commit adds two TUI features:

  1. Delete functionality (d key):

    • Press 'd' to delete the selected file or directory
    • A confirmation prompt appears: "Delete [file/directory]? (y/n): [URI]"
    • Press 'y' to confirm deletion or 'n' to cancel
    • After deletion, the tree refreshes and cursor moves to the next or previous sibling
  2. Refresh behavior (r key):

    • Press 'r' to refresh the entire tree
    • Loads the root node "viking://"
    • Restores the cursor to the originally selected node
    • Maintains user context after refresh

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Test update

Changes Made

  • added delete_uri and reload_entire_tree in app.rs
  • added set_status_message for showing a status message on the bottom bar.
  • added update_status_message in mod.rs for making status message go away after 3 (hardcoded) seconds.
  • added expand_node_by_uri in tree
  • monitor key input 'd' for deletion (then 'y'/'n' for confirmation), and 'r' for refresh

Testing

  • 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
  • I have tested this on the following platforms:
    • Linux
    • macOS
    • Windows

Checklist

  • My code follows the project's coding style
  • I have performed a self-review of my 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
  • Any dependent changes have been merged and published

Screenshots

Screenshot 2026-03-17 at 17 33 53 Screenshot 2026-03-17 at 17 33 58

…h behavior

This commit adds two key TUI features:

1. Delete functionality (d key):
   - Press 'd' to delete the selected file or directory
   - A confirmation prompt appears: "Delete [file/directory]? (y/n): [URI]"
   - Press 'y' to confirm deletion or 'n' to cancel
   - After deletion, the tree refreshes and cursor moves to the next or previous sibling

2. Refresh behavior (r key):
   - Press 'r' to refresh the entire tree
   - Loads the root node "viking://"
   - Restores the cursor to the originally selected node
   - Maintains user context after refresh
@CLAassistant
Copy link

CLAassistant commented Mar 17, 2026

CLA assistant check
All committers have signed the CLA.

Copy link
Collaborator

@qin-ctx qin-ctx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall a well-structured PR that adds useful TUI features. One blocking bug found: the delete confirmation prompt can be prematurely cleared by the auto-clear timer from a previous status message. 4 additional non-blocking suggestions included.

Also note: no tests were added for the new functionality (delete confirmation state machine, status message auto-clear, tree refresh with state restoration). Consider adding unit tests for at least the timer logic and confirmation flow.


// Set delete confirmation state
app.delete_confirmation = Some((selected_uri.clone(), is_dir));
app.status_message = format!("Delete {}? (y/n): {}",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Bug] (blocking) The confirmation message is set by directly assigning status_message without resetting status_message_time. If a previous timed message (e.g., "Tree refreshed" from pressing r) set the timer via set_status_message, update_status_message() in the main loop will clear this confirmation prompt when the old 3-second timer expires — even though delete_confirmation is still Some.

This creates a UX inconsistency: the confirmation prompt disappears but the app still silently waits for y/n, with no visible indication to the user.

Suggested fix:

app.delete_confirmation = Some((selected_uri.clone(), is_dir));
app.status_message = format!("Delete {}? (y/n): {}",
    if is_dir { "directory" } else { "file" },
    selected_uri
);
app.status_message_time = None; // Prevent auto-clear during confirmation

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • refactored the deletion_confirmation to a generic confirmation system.
  • when confirmation pops up, no new status message can be set.
  • added error message for error happens (for example, when deleting protected uri)

}
}

pub async fn reload_entire_tree(&mut self) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Design] (non-blocking) reload_entire_tree() and delete_uri() share ~40 lines of nearly identical logic:

  • Collecting expanded nodes from self.tree.visible
  • Reloading root and restoring expanded state via expand_node_by_uri loop
  • Walking parent paths to ensure target URI visibility
  • Finding cursor position with parent-fallback closure

Consider extracting a shared helper (e.g., refresh_tree_and_restore(&mut self, target_uri: &str)) to reduce duplication and make future maintenance easier.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extracted common code into small methods

app.tree.toggle_expand(&client).await;
app.load_content_for_selected().await;
}
KeyCode::Char('d') => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Suggestion] (non-blocking) There's no guard against deleting the root node (/) or scope-level URIs (viking://resources, viking://agent, etc.). If the server's rm endpoint doesn't reject these, it could lead to unintended data loss.

Consider adding a check before entering confirmation:

if selected_uri == "/" || Self::ROOT_SCOPES.iter().any(|s| selected_uri == format!("viking://{}", s)) {
    app.set_status_message("Cannot delete root or scope directories".to_string());
    return;
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a tree.allow_deletion method to ensure the those nodes cannot be delete.

.style(Style::default().bg(Color::DarkGray).fg(Color::White));
frame.render_widget(bar, area);
}
} No newline at end of file
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Suggestion] (non-blocking) Missing trailing newline at end of file. Most editors, linters, and POSIX tools expect files to end with a newline character.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Changes:
- Replace delete_confirmation with generic confirmation system using callbacks
- Add error message handling with dedicated display
- Add status message locking during confirmations
- Add delete_selected_uri method for cleaner deletion flow
- Add deletion protection for root and scope directories
- Update UI to show error messages and confirmation prompts
- Rename update_status_message to update_messages
- Add allow_deletion method to TreeState
- Update key handling to prioritize error messages
@xiaobin83 xiaobin83 requested a review from qin-ctx March 18, 2026 03:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

3 participants