Skip to content
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

[PM-8050] Deleting one folder deletes all other folders #10165

Merged
merged 3 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { FolderApiServiceAbstraction } from "@bitwarden/common/vault/abstractions/folder/folder-api.service.abstraction";
import { FolderService } from "@bitwarden/common/vault/abstractions/folder/folder.service.abstraction";
import { DialogService } from "@bitwarden/components";
import { DialogService, ToastService } from "@bitwarden/components";

@Component({
selector: "app-folder-add-edit",
Expand All @@ -24,6 +24,7 @@
logService: LogService,
dialogService: DialogService,
formBuilder: FormBuilder,
protected toastService: ToastService,
protected dialogRef: DialogRef<FolderAddEditDialogResult>,
@Inject(DIALOG_DATA) params: FolderAddEditDialogParams,
) {
Expand Down Expand Up @@ -51,10 +52,12 @@
}

try {
this.deletePromise = this.folderApiService.delete(this.folder.id);
await this.deletePromise;
this.platformUtilsService.showToast("success", null, this.i18nService.t("deletedFolder"));
this.onDeletedFolder.emit(this.folder);
shane-melton marked this conversation as resolved.
Show resolved Hide resolved
await this.folderApiService.delete(this.folder.id);
this.toastService.showToast({

Check warning on line 56 in apps/web/src/app/vault/individual-vault/folder-add-edit.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/vault/individual-vault/folder-add-edit.component.ts#L55-L56

Added lines #L55 - L56 were not covered by tests
variant: "success",
title: null,
message: this.i18nService.t("deletedFolder"),
});
} catch (e) {
this.logService.error(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,9 +464,7 @@
const result = await lastValueFrom(dialog.closed);

if (result === FolderAddEditDialogResult.Deleted) {
// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.router.navigate([], {
await this.router.navigate([], {

Check warning on line 467 in apps/web/src/app/vault/individual-vault/vault.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/vault/individual-vault/vault.component.ts#L467

Added line #L467 was not covered by tests
queryParams: { folderId: null },
queryParamsHandling: "merge",
replaceUrl: true,
Expand Down
16 changes: 7 additions & 9 deletions libs/common/src/vault/services/folder/folder.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,14 @@ export class FolderService implements InternalFolderServiceAbstraction {
return;
}

if (typeof id === "string") {
if (folders[id] == null) {
return;
Copy link
Member

Choose a reason for hiding this comment

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

๐Ÿ‘ Wow, nice catch on this one!

const folderIdsToDelete = Array.isArray(id) ? id : [id];

folderIdsToDelete.forEach((id) => {
if (folders[id] != null) {
delete folders[id];
}
delete folders[id];
} else {
(id as string[]).forEach((i) => {
delete folders[i];
});
}
});

return folders;
});

Expand Down
Loading