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

* removed the use of deletepromise from folder edit dialog on web

* resolved fix me

* return folders if folder is not found with folder id
This commit is contained in:
SmithThe4th 2024-07-18 18:28:25 -04:00 committed by GitHub
parent 56f5dba444
commit c27657eb82
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 17 deletions

View File

@ -8,7 +8,7 @@ import { LogService } from "@bitwarden/common/platform/abstractions/log.service"
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",
@ -24,6 +24,7 @@ export class FolderAddEditComponent extends BaseFolderAddEditComponent {
logService: LogService,
dialogService: DialogService,
formBuilder: FormBuilder,
protected toastService: ToastService,
protected dialogRef: DialogRef<FolderAddEditDialogResult>,
@Inject(DIALOG_DATA) params: FolderAddEditDialogParams,
) {
@ -51,10 +52,12 @@ export class FolderAddEditComponent extends BaseFolderAddEditComponent {
}
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);
await this.folderApiService.delete(this.folder.id);
this.toastService.showToast({
variant: "success",
title: null,
message: this.i18nService.t("deletedFolder"),
});
} catch (e) {
this.logService.error(e);
}

View File

@ -464,9 +464,7 @@ export class VaultComponent implements OnInit, OnDestroy {
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([], {
queryParams: { folderId: null },
queryParamsHandling: "merge",
replaceUrl: true,

View File

@ -137,16 +137,14 @@ export class FolderService implements InternalFolderServiceAbstraction {
return;
}
if (typeof id === "string") {
if (folders[id] == null) {
return;
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;
});