Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Update folder delete logic and redirect for subdirs (#1695)

Leendert de Borst3c36917a5a5a
diff --git a/apps/browser-extension/src/entrypoints/popup/pages/items/ItemsList.tsx b/apps/browser-extension/src/entrypoints/popup/pages/items/ItemsList.tsx
index e9cf8c576..1e45c5b48 100644
--- a/apps/browser-extension/src/entrypoints/popup/pages/items/ItemsList.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/pages/items/ItemsList.tsx
@@ -247,6 +247,11 @@ const ItemsList: React.FC = () => {
return;
}
+ // Get the current folder to determine parent before deletion
+ const allFolders = dbContext.sqliteClient.folders.getAll();
+ const currentFolder = allFolders.find(f => f.Id === currentFolderId);
+ const parentFolderId = currentFolder?.ParentFolderId ?? null;
+
await executeVaultMutationAsync(async () => {
await dbContext.sqliteClient!.folders.delete(currentFolderId);
});
@@ -257,8 +262,12 @@ const ItemsList: React.FC = () => {
const deletedCount = dbContext.sqliteClient!.items.getRecentlyDeletedCount();
setRecentlyDeletedCount(deletedCount);
- // Navigate back to root
- navigate('/items');
+ // Navigate to parent folder if it exists, otherwise root
+ if (parentFolderId) {
+ navigate(`/items/folder/${parentFolderId}`);
+ } else {
+ navigate('/items');
+ }
}, [dbContext, currentFolderId, executeVaultMutationAsync, navigate]);
/**
@@ -269,6 +278,11 @@ const ItemsList: React.FC = () => {
return;
}
+ // Get the current folder to determine parent before deletion
+ const allFolders = dbContext.sqliteClient.folders.getAll();
+ const currentFolder = allFolders.find(f => f.Id === currentFolderId);
+ const parentFolderId = currentFolder?.ParentFolderId ?? null;
+
await executeVaultMutationAsync(async () => {
await dbContext.sqliteClient!.folders.deleteWithContents(currentFolderId);
});
@@ -279,8 +293,12 @@ const ItemsList: React.FC = () => {
const deletedCount = dbContext.sqliteClient!.items.getRecentlyDeletedCount();
setRecentlyDeletedCount(deletedCount);
- // Navigate back to root
- navigate('/items');
+ // Navigate to parent folder if it exists, otherwise root
+ if (parentFolderId) {
+ navigate(`/items/folder/${parentFolderId}`);
+ } else {
+ navigate('/items');
+ }
}, [dbContext, currentFolderId, executeVaultMutationAsync, navigate]);
/**
diff --git a/apps/browser-extension/src/utils/db/queries/FolderQueries.ts b/apps/browser-extension/src/utils/db/queries/FolderQueries.ts
index 632760f07..3b9c7268a 100644
--- a/apps/browser-extension/src/utils/db/queries/FolderQueries.ts
+++ b/apps/browser-extension/src/utils/db/queries/FolderQueries.ts
@@ -46,7 +46,7 @@ export class FolderQueries {
WHERE Id = ?`;
/**
- * Clear folder reference from items.
+ * Clear folder reference from items (set to NULL).
*/
public static readonly CLEAR_ITEMS_FOLDER = `
UPDATE Items
@@ -54,6 +54,15 @@ export class FolderQueries {
UpdatedAt = ?
WHERE FolderId = ?`;
+ /**
+ * Move items to a different folder.
+ */
+ public static readonly MOVE_ITEMS_TO_FOLDER = `
+ UPDATE Items
+ SET FolderId = ?,
+ UpdatedAt = ?
+ WHERE FolderId = ?`;
+
/**
* Trash items in folder.
*/
diff --git a/apps/browser-extension/src/utils/db/repositories/FolderRepository.ts b/apps/browser-extension/src/utils/db/repositories/FolderRepository.ts
index 8e47981dc..e19b252d6 100644
--- a/apps/browser-extension/src/utils/db/repositories/FolderRepository.ts
+++ b/apps/browser-extension/src/utils/db/repositories/FolderRepository.ts
@@ -110,7 +110,7 @@ export class FolderRepository extends BaseRepository {
/**
* Delete a folder (soft delete).
* Recursively handles child folders and items:
- * - All items in this folder and child folders are moved to root (FolderId = NULL)
+ * - All items in this folder and child folders are moved to the parent folder (or root if no parent)
* - All child folders are moved to the parent of the deleted folder
* @param folderId - The ID of the folder to delete
* @returns The number of rows updated
@@ -126,17 +126,35 @@ export class FolderRepository extends BaseRepository {
// Get all child folder IDs recursively
const allChildFolderIds = this.getAllChildFolderIds(folderId);
- // Move all items in this folder and all child folders to root
- this.client.executeUpdate(FolderQueries.CLEAR_ITEMS_FOLDER, [
- currentDateTime,
- folderId
- ]);
+ // Move all items in this folder and all child folders to the parent folder (or root if no parent)
+ if (targetParentId) {
+ // Has parent: move items to parent folder
+ this.client.executeUpdate(FolderQueries.MOVE_ITEMS_TO_FOLDER, [
+ targetParentId,
+ currentDateTime,
+ folderId
+ ]);
- for (const childFolderId of allChildFolderIds) {
+ for (const childFolderId of allChildFolderIds) {
+ this.client.executeUpdate(FolderQueries.MOVE_ITEMS_TO_FOLDER, [
+ targetParentId,
+ currentDateTime,
+ childFolderId
+ ]);
+ }
+ } else {
+ // No parent: move items to root (NULL)
this.client.executeUpdate(FolderQueries.CLEAR_ITEMS_FOLDER, [
currentDateTime,
- childFolderId
+ folderId
]);
+
+ for (const childFolderId of allChildFolderIds) {
+ this.client.executeUpdate(FolderQueries.CLEAR_ITEMS_FOLDER, [
+ currentDateTime,
+ childFolderId
+ ]);
+ }
}
// Move direct child folders to the parent of the deleted folder