From 99e0ead5fdbdca7ff7114709c004ffe7d9e3e1d4 Mon Sep 17 00:00:00 2001 From: Shane Melton Date: Wed, 15 Feb 2023 12:55:25 -0800 Subject: [PATCH] [EC-1037] [EC-742] Cleanup vault folder filter logic (#4700) * [EC-1037] Cleanup vault folder filter logic - "All vaults" and "My vault" should always show all folders - Organization vault should only show non-empty folders and the "No folder" folder - Ensures the "Folders" filter section is always visible * Update apps/web/src/vault/individual-vault/vault-filter/services/vault-filter.service.ts Co-authored-by: Thomas Rittson <31796059+eliykat@users.noreply.github.com> * Update libs/angular/src/vault/vault-filter/services/vault-filter.service.ts Co-authored-by: Thomas Rittson <31796059+eliykat@users.noreply.github.com> --------- Co-authored-by: Thomas Rittson <31796059+eliykat@users.noreply.github.com> --- .../vault-filter/services/vault-filter.service.ts | 9 +++++---- .../vault-filter/services/vault-filter.service.ts | 14 ++++++++------ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/apps/web/src/vault/individual-vault/vault-filter/services/vault-filter.service.ts b/apps/web/src/vault/individual-vault/vault-filter/services/vault-filter.service.ts index eab891b04b..27e3ab918d 100644 --- a/apps/web/src/vault/individual-vault/vault-filter/services/vault-filter.service.ts +++ b/apps/web/src/vault/individual-vault/vault-filter/services/vault-filter.service.ts @@ -215,15 +215,16 @@ export class VaultFilterService implements VaultFilterServiceAbstraction { storedFolders: FolderView[], org?: Organization ): Promise { - if (org?.id == null) { + // If no org or "My Vault" is selected, show all folders + if (org?.id == null || org?.id == "MyVault") { return storedFolders; } + + // Otherwise, show only folders that have ciphers from the selected org and the "no folder" folder const ciphers = await this.cipherService.getAllDecrypted(); const orgCiphers = ciphers.filter((c) => c.organizationId == org?.id); return storedFolders.filter( - (f) => - orgCiphers.filter((oc) => oc.folderId == f.id).length > 0 || - ciphers.filter((c) => c.folderId == f.id).length < 1 + (f) => orgCiphers.some((oc) => oc.folderId == f.id) || f.id == null ); } diff --git a/libs/angular/src/vault/vault-filter/services/vault-filter.service.ts b/libs/angular/src/vault/vault-filter/services/vault-filter.service.ts index a56758a8bd..ced1b1b7e9 100644 --- a/libs/angular/src/vault/vault-filter/services/vault-filter.service.ts +++ b/libs/angular/src/vault/vault-filter/services/vault-filter.service.ts @@ -55,17 +55,19 @@ export class VaultFilterService implements DeprecatedVaultFilterServiceAbstracti buildNestedFolders(organizationId?: string): Observable> { const transformation = async (storedFolders: FolderView[]) => { let folders: FolderView[]; - if (organizationId != null) { + + // If no org or "My Vault" is selected, show all folders + if (organizationId == null || organizationId == "MyVault") { + folders = storedFolders; + } else { + // Otherwise, show only folders that have ciphers from the selected org and the "no folder" folder const ciphers = await this.cipherService.getAllDecrypted(); const orgCiphers = ciphers.filter((c) => c.organizationId == organizationId); folders = storedFolders.filter( - (f) => - orgCiphers.filter((oc) => oc.folderId == f.id).length > 0 || - ciphers.filter((c) => c.folderId == f.id).length < 1 + (f) => orgCiphers.some((oc) => oc.folderId == f.id) || f.id == null ); - } else { - folders = storedFolders; } + const nestedFolders = await this.getAllFoldersNested(folders); return new DynamicTreeNode({ fullList: folders,