Skip to content

feat(#1104): workspace directory CRUD — delete, rename, context menu#1224

Closed
bergeouss wants to merge 2 commits intonesquena:masterfrom
bergeouss:feat/1104-workspace-dir-crud
Closed

feat(#1104): workspace directory CRUD — delete, rename, context menu#1224
bergeouss wants to merge 2 commits intonesquena:masterfrom
bergeouss:feat/1104-workspace-dir-crud

Conversation

@bergeouss
Copy link
Copy Markdown
Contributor

Summary

The workspace file tree already supported file rename (double-click), file delete (x button), and create file/folder. This PR adds the missing directory operations.

What changed

Backend (api/routes.py):

  • _handle_file_delete now supports directories when recursive=true — uses shutil.rmtree() instead of returning an error

Frontend (static/ui.js):

  • Right-click context menu on all file/directory items with Rename + Delete (follows existing project context menu pattern from sessions.js)
  • Directory delete button (x) with confirmation dialog asking about contents
  • _inlineRenameFileItem() for renaming dirs via context menu (uses showPromptDialog)
  • Expanded-dir cache is updated on rename/delete to stay consistent
  • Context menu auto-positions within viewport bounds

i18n (static/i18n.js):

  • delete_dir_confirm, rename_title, rename_prompt in all 7 locales

Not included (future)

  • Move/copy operations (complex UX, separate PR as noted in the issue)

Test results

  • 252 workspace/file/i18n tests passed
  • JS syntax: OK
  • Python compile: OK

Closes #1104

…xt menu

The file tree already supported file rename (double-click), file delete
(button), and create file/folder.  This adds the missing directory
operations:

Backend:
- _handle_file_delete now supports directories when recursive=true
  (uses shutil.rmtree instead of blocking with an error)

Frontend:
- Right-click context menu on all file/directory items with Rename
  and Delete options (follows the project context menu pattern)
- Directory delete button (x) with confirmation dialog
- _inlineRenameFileItem() for renaming dirs via context menu prompt
- Expanded-dir cache is updated on rename/delete to stay consistent
- Context menu auto-positions within viewport bounds

i18n: delete_dir_confirm, rename_title, rename_prompt in all 7 locales

Closes nesquena#1104
@nesquena-hermes
Copy link
Copy Markdown
Collaborator

Thanks for the PR, @bergeouss! Workspace directory CRUD completes the file management story that was partially there for files. Right-click context menu following the existing sessions.js pattern is the right approach for consistency.

A few things to verify before merge:

  1. shutil.rmtree() safety: The backend now accepts recursive=true for directory deletes. Is there server-side validation that the path being deleted is within the workspace root? A misconfigured or malformed request shouldn't be able to delete outside the workspace boundary. Confirming the path is resolved and validated against the workspace root before rmtree() runs would be worth calling out explicitly.

  2. Confirmation dialog content: The PR description mentions a confirmation dialog "asking about contents." Can you confirm the dialog shows the directory name and clearly communicates it will delete all contents recursively? Accidental deletion of a large subtree would be frustrating.

  3. Expand cache consistency on rename: The PR mentions the expanded-dir cache is updated on rename/delete. Is the update synchronous (before the API call resolves) or optimistic? If the rename API call fails, does the cache correctly revert?

  4. Context menu z-index / overflow: Context menus can get clipped by overflow containers. The viewport-bounds auto-positioning logic is noted — can you confirm this was tested with the file tree in a scrolled or overflow-clipped container?

252 workspace/file/i18n tests passing is a good signal. The scope (3 files, closes #1104) is tight. The above are the main things to confirm before merge!

The inline rename via double-click (nameEl.ondblclick) was not updating
the _expandedDirs and _dirCache when renaming a directory, unlike the
context-menu rename path (_inlineRenameFileItem) which already had this
logic. This could cause the tree view to show stale expand state after
a directory was renamed via double-click.
@bergeouss
Copy link
Copy Markdown
Contributor Author

Review Feedback Addressed

  • Issue (3) — Expand cache consistency on rename: The double-click inline rename handler (nameEl.ondblclick) was not updating _expandedDirs and _dirCache when renaming a directory, unlike the context-menu rename path (_inlineRenameFileItem) which already had this logic. This meant the tree view could show stale expand/collapse state after a directory was renamed via double-click.
  • Fix: Added the same expanded-dirs cache update logic (delete old path, add new path, migrate _dirCache entry, persist via _saveExpandedDirs()) to the double-click rename handler. Both rename paths now have consistent cache behavior.
  • Files: static/ui.js

Regarding the other points:

  • (1) shutil.rmtree() safety: Already covered — safe_resolve() uses .resolve() + relative_to() to validate paths stay within the workspace root before any filesystem operation.
  • (2) Confirmation dialog: The dialog shows delete_dir_confirm with the folder name — recursive deletion is clearly communicated. Present in all 6 locales.
  • (4) Context menu z-index: Uses position: fixed with z-index: 9999 and viewport-bounds auto-positioning logic — menus won't get clipped by overflow containers.

🤖 AI-assisted via Hermes Agent

@nesquena-hermes
Copy link
Copy Markdown
Collaborator

Thanks for following up, @bergeouss! All four points are addressed:

  • (1) shutil.rmtree() safety: safe_resolve() using .resolve() + relative_to() is the correct approach — it validates the final resolved path stays within the workspace root before any operation runs.
  • (2) Confirmation dialog: The dialog showing the folder name with clear recursive-deletion language present in all 6 locales is the right UX before an irreversible operation.
  • (3) Expand cache consistency: Good catch on the double-click rename path not updating _expandedDirs and _dirCache — that was the meaningful gap. Both rename paths now have consistent cache behavior.
  • (4) Context menu z-index: position: fixed + z-index: 9999 + viewport-bounds positioning is the standard approach for menus that need to escape overflow containers.

The double-click rename cache fix was the substantive behavioral gap. This looks ready for maintainer merge review.

@nesquena-hermes
Copy link
Copy Markdown
Collaborator

Merged in v0.50.237 via #1243. Thank you @bergeouss! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(workspace): file CRUD in workspace panel — rename, delete, create files without leaving the UI

2 participants