1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-25 12:15:18 +01:00

[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>
This commit is contained in:
Shane Melton 2023-02-15 12:55:25 -08:00 committed by GitHub
parent 36633bcb04
commit 99e0ead5fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 10 deletions

View File

@ -215,15 +215,16 @@ export class VaultFilterService implements VaultFilterServiceAbstraction {
storedFolders: FolderView[],
org?: Organization
): Promise<FolderView[]> {
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
);
}

View File

@ -55,17 +55,19 @@ export class VaultFilterService implements DeprecatedVaultFilterServiceAbstracti
buildNestedFolders(organizationId?: string): Observable<DynamicTreeNode<FolderView>> {
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<FolderView>({
fullList: folders,