55 CollectionView ,
66 NestingDelimiter ,
77} from "@bitwarden/admin-console/common" ;
8- import { OrganizationId } from "@bitwarden/common/types/guid" ;
98import { TreeNode } from "@bitwarden/common/vault/models/domain/tree-node" ;
109import { ServiceUtils } from "@bitwarden/common/vault/service-utils" ;
1110
@@ -27,23 +26,15 @@ export function getNestedCollectionTree(
2726 . sort ( ( a , b ) => a . name . localeCompare ( b . name ) )
2827 . map ( cloneCollection ) ;
2928
30- const all : TreeNode < CollectionView | CollectionAdminView > [ ] = [ ] ;
31- const groupedByOrg = new Map < OrganizationId , CollectionView [ ] > ( ) ;
32- clonedCollections . map ( ( c ) => {
33- const key = c . organizationId ;
34- ( groupedByOrg . get ( key ) ?? groupedByOrg . set ( key , [ ] ) . get ( key ) ! ) . push ( c ) ;
29+ const nodes : TreeNode < CollectionView | CollectionAdminView > [ ] = [ ] ;
30+ clonedCollections . forEach ( ( collection ) => {
31+ const parts =
32+ collection . name != null
33+ ? collection . name . replace ( / ^ \/ + | \/ + $ / g, "" ) . split ( NestingDelimiter )
34+ : [ ] ;
35+ ServiceUtils . nestedTraverse ( nodes , 0 , parts , collection , null , NestingDelimiter ) ;
3536 } ) ;
36-
37- for ( const group of groupedByOrg . values ( ) ) {
38- const nodes : TreeNode < CollectionView > [ ] = [ ] ;
39- for ( const c of group ) {
40- const collectionCopy = Object . assign ( new CollectionView ( { ...c , name : c . name } ) , c ) ;
41- const parts = c . name ? c . name . replace ( / ^ \/ + | \/ + $ / g, "" ) . split ( NestingDelimiter ) : [ ] ;
42- ServiceUtils . nestedTraverse ( nodes , 0 , parts , collectionCopy , undefined , NestingDelimiter ) ;
43- }
44- all . push ( ...nodes ) ;
45- }
46- return all ;
37+ return nodes ;
4738}
4839
4940export function cloneCollection ( collection : CollectionView ) : CollectionView ;
0 commit comments