Skip to content

Deletion: a space or a folder can put its notes in the trash #1672

Done

Description

@vmillet-dev

Context — Deleting a space (space switcher › the space's options › Delete the space) always moves its notes into another space, chosen in « Move notes to », out of any folder; its folders are deleted. Deleting a folder (its options › Delete) always hands its notes and sub-folders to its parent, or loose at the top of the space. There is no way to delete a space or a folder together with its notes: the user must first select and trash them, then delete the container. Reported on 1.2.1.

Change — Deleting a space or a folder asks what becomes of its notes: kept (today's behaviour, the default) or put in the trash with it. Nothing is erased for good: only emptying the trash, or its 30 days, does that. The consequence line says, counted by the core, what each choice will do before the second click.

To do

Space

  • Core: spaces::delete_space takes what becomes of the notes (Keep / Trash), in one transaction; validated in spaces::model.
  • The « Move notes to » menu stays in both choices: with Keep the notes go there; with Trash they are moved there and trashed (deleted_at = now), so a restore brings them back, unfiled, into that space.
  • Notes already in the space's trash follow the same path as today (moved to the chosen space, still trashed).
  • The last space stays undeletable (trashed notes need a space to be restored into).

Folder

  • Core: folders::delete_folder takes the same choice; with Trash, the folder and every sub-folder under it are deleted and all the notes they hold are trashed, in the same transaction, and come back, on restore, loose in the folder's space (its folder_id set to null by ON DELETE SET NULL). No menu: the space still exists.
  • A count of what the folder holds, sub-folders included, from the core (today the panel only says folders.deleteKeepsNotes, without a number).

Both

  • Panel: a two-option choice (« Keep them » / « Put them in the trash ») above the delete button; the consequence line for each (new keys, both locales).
  • Report through the status notifier how many notes were moved or trashed.

Tests — Core (engine/tests/spaces.rs, engine/tests/folders.rs): delete with Trash → the container is gone, its notes are in the trash, restore puts them in the chosen space (space) or loose in the same space (folder), their attachments are still there; the index answers no note of the container. kittest in the notes/panel.rs tests: the choice switches the consequence text. e2e 05_spaces: a step deletes a space with « Put them in the trash » and finds its notes in the trash panel; e2e 17_folders: the same for a folder.


Technical analysis

Space, today. engine/src/spaces.rs:50 delete_space(engine, id, target_space_id) validates that the target is not the space itself, then spaces/store.rs:194 moves every note of the space (trashed ones included: the filter is space_id alone) to the target and deletes the space row; folders.space_id is ON DELETE CASCADE, notes.folder_id ON DELETE SET NULL, hence « out of any folder ». notes.space_id is also ON DELETE CASCADE (initial migration, line 12): deleting the row first would hard-delete the notes without removing their attachment files, which only notes::trash::purge collects before its DELETE (notes/trash.rs:54-70). The panel (ui/src/notes/panel.rs, deletion line 261) always shows the menu and a two-step destructive button; consequences (line 317) builds the line from count_space_contents (live notes, folders).

Folder, today. engine/src/folders.rs:184 delete_folder → folders/store.rs:416: in one transaction, each child folder is re-placed under the parent, the folder's notes lose their board positions (board::forget_positions) and are filed into the parent, the folder row is deleted, and the parent's zones grow to fit (grow_with_ancestors). The panel (panel.rs, around line 405) shows a two-step « Delete » and the fixed line folders.deleteKeepsNotes.

Fix. One service function each, with the notes' fate as an argument (no second path to maintain). Space: UPDATE notes SET space_id = refuge [, deleted_at = now WHERE deleted_at IS NULL], then delete the row. Folder: with Trash, take the subtree from Lineage::subtree(id) (already used by grow_with_ancestors), UPDATE notes SET deleted_at = now WHERE folder_id IN (subtree) AND deleted_at IS NULL, forget their board positions, then delete the folders of the subtree (no child is re-placed under the parent); the parent's zones are recomputed as today. Trashing keeps the trash's rules intact (restore needs a live space_id; purge removes the files) and makes the deletion reversible for 30 days. Changed::everything() stays. The UI's Action::DeleteSpace { id, refuge } and Action::DeleteFolder(id) gain the choice; SpaceEdit / FolderEdit keep it.

Decided. The notes go to the trash, never erased: a deletion is final only when the user empties the trash explicitly. No path of this ticket calls purge. For a space the user still chooses, in « Move notes to », where they will be restored.

Decided. A folder deleted with its notes takes its whole subtree: its sub-folders are deleted and all their notes go to the trash, as the folder shows them when opened. With « Keep them », the sub-folders and notes are handed to the parent as today.

Risk. Medium: destructive paths. Each transaction must trash and move or delete together; tests check that the attachments' files survive and that nothing is left referencing the deleted container.

Activity

  1. added
    enhancement
    on Nov 27, 2026
  2. changed the title [-]Spaces: deleting a space can take its notes with it[/-] [+]Spaces: deleting a space can put its notes in the trash[/+] on Nov 27, 2026
  3. changed the title [-]Spaces: deleting a space can put its notes in the trash[/-] [+]Deletion: a space or a folder can put its notes in the trash[/+] on Nov 27, 2026
  4. added a commit that references this issue on Nov 27, 2026
  5. vmillet-dev commented on Nov 27, 2026

    @vmillet-dev
    OwnerAuthor

    Fixed by #1685, merged into dev/1.2.2.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions