1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 08:13:42 +00:00

[PM-17690] Improve collection search to consider nested collections (#14420)

* Add getFlatCollectionTree function and corresponding tests

- Implemented getFlatCollectionTree to flatten a tree structure of collections.
- Added unit tests for getFlatCollectionTree to verify functionality.

* Refactor VaultComponent to utilize getFlatCollectionTree to search within all sub-levels

- Updated vault.component.ts to import and use getFlatCollectionTree for flattening collection nodes during search.
- Ensured consistent handling of collections across both vault and admin-console components.
This commit is contained in:
Rui Tomé
2025-04-30 11:40:55 +01:00
committed by GitHub
parent d43e4757df
commit a92afe1efb
4 changed files with 116 additions and 18 deletions

View File

@@ -121,7 +121,7 @@ import {
BulkCollectionsDialogResult,
} from "./bulk-collections-dialog";
import { CollectionAccessRestrictedComponent } from "./collection-access-restricted.component";
import { getNestedCollectionTree } from "./utils";
import { getNestedCollectionTree, getFlatCollectionTree } from "./utils";
import { VaultFilterModule } from "./vault-filter/vault-filter.module";
import { VaultHeaderComponent } from "./vault-header/vault-header.component";
@@ -432,23 +432,33 @@ export class VaultComponent implements OnInit, OnDestroy {
}
this.showAddAccessToggle = false;
let collectionsToReturn = [];
let searchableCollectionNodes: TreeNode<CollectionAdminView>[] = [];
if (filter.collectionId === undefined || filter.collectionId === All) {
collectionsToReturn = collections.map((c) => c.node);
searchableCollectionNodes = collections;
} else {
const selectedCollection = ServiceUtils.getTreeNodeObjectFromList(
collections,
filter.collectionId,
);
collectionsToReturn = selectedCollection?.children.map((c) => c.node) ?? [];
searchableCollectionNodes = selectedCollection?.children ?? [];
}
let collectionsToReturn: CollectionAdminView[] = [];
if (await this.searchService.isSearchable(this.userId, searchText)) {
// Flatten the tree for searching through all levels
const flatCollectionTree: CollectionAdminView[] =
getFlatCollectionTree(searchableCollectionNodes);
collectionsToReturn = this.searchPipe.transform(
collectionsToReturn,
flatCollectionTree,
searchText,
(collection: CollectionAdminView) => collection.name,
(collection: CollectionAdminView) => collection.id,
(collection) => collection.name,
(collection) => collection.id,
);
} else {
collectionsToReturn = searchableCollectionNodes.map(
(treeNode: TreeNode<CollectionAdminView>): CollectionAdminView => treeNode.node,
);
}