@@ -698,7 +698,7 @@ export class CdkTree<T, K = T> implements AfterContentChecked, CollectionViewer,
698698
699699 /** Given a CdkTreeNode, gets the node that renders that node's parent's data. */
700700 _getNodeParent ( node : CdkTreeNode < T , K > ) {
701- const parent = this . _parents . get ( node . data ) ;
701+ const parent = this . _parents . get ( this . _getExpansionKey ( node . data ) ) ;
702702 return parent && this . _nodes . value . get ( this . _getExpansionKey ( parent ) ) ;
703703 }
704704
@@ -817,39 +817,6 @@ export class CdkTree<T, K = T> implements AfterContentChecked, CollectionViewer,
817817 return this . expansionKey ?.( dataNode ) ?? ( dataNode as unknown as K ) ;
818818 }
819819
820- /**
821- * Converts children for certain tree configurations. Note also that this
822- * caches the known nodes for use in other parts of the tree.
823- */
824- private _convertChildren ( nodes : readonly T [ ] ) : Observable < readonly T [ ] > {
825- // The only situations where we have to convert children types is when
826- // they're mismatched; i.e. if the tree is using a childrenAccessor and the
827- // nodes are flat, or if the tree is using a levelAccessor and the nodes are
828- // nested.
829- if ( this . childrenAccessor && this . nodeType === 'flat' ) {
830- // This flattens children into a single array.
831- return observableOf ( ...nodes ) . pipe (
832- concatMap ( node => concat ( observableOf ( [ node ] ) , this . _getAllChildrenRecursively ( node ) ) ) ,
833- reduce ( ( results , children ) => {
834- results . push ( ...children ) ;
835- return results ;
836- } , [ ] as T [ ] ) ,
837- tap ( allNodes => {
838- this . _dataNodes . next ( allNodes ) ;
839- } ) ,
840- ) ;
841- } else if ( this . levelAccessor && this . nodeType === 'nested' ) {
842- this . _dataNodes . next ( nodes ) ;
843- // In the nested case, we only look for root nodes. The CdkNestedNode
844- // itself will handle rendering each individual node's children.
845- const levelAccessor = this . levelAccessor ;
846- return observableOf ( nodes . filter ( node => levelAccessor ( node ) === 0 ) ) ;
847- } else {
848- this . _dataNodes . next ( nodes ) ;
849- return observableOf ( nodes ) ;
850- }
851- }
852-
853820 private _getNodeGroup ( node : T ) {
854821 const level = this . _levels . get ( this . _getExpansionKey ( node ) ) ;
855822 const parent = this . _parents . get ( this . _getExpansionKey ( node ) ) ;
@@ -876,19 +843,36 @@ export class CdkTree<T, K = T> implements AfterContentChecked, CollectionViewer,
876843 return null ;
877844 }
878845
879- private _flattenChildren ( nodes : readonly T [ ] ) : Observable < readonly T [ ] > {
880- // If we're using TreeControl or levelAccessor, we don't need to manually
881- // flatten things here.
882- if ( ! this . childrenAccessor ) {
883- return observableOf ( nodes ) ;
884- } else {
846+ /**
847+ * Converts children for certain tree configurations. Note also that this
848+ * caches the known nodes for use in other parts of the tree.
849+ */
850+ private _convertChildren ( nodes : readonly T [ ] ) : Observable < readonly T [ ] > {
851+ // The only situations where we have to convert children types is when
852+ // they're mismatched; i.e. if the tree is using a childrenAccessor and the
853+ // nodes are flat, or if the tree is using a levelAccessor and the nodes are
854+ // nested.
855+ if ( this . childrenAccessor && this . nodeType === 'flat' ) {
856+ // This flattens children into a single array.
885857 return observableOf ( ...nodes ) . pipe (
886858 concatMap ( node => concat ( observableOf ( [ node ] ) , this . _getAllChildrenRecursively ( node ) ) ) ,
887- reduce ( ( results , nodes ) => {
888- results . push ( ...nodes ) ;
859+ reduce ( ( results , children ) => {
860+ results . push ( ...children ) ;
889861 return results ;
890862 } , [ ] as T [ ] ) ,
863+ tap ( allNodes => {
864+ this . _dataNodes . next ( allNodes ) ;
865+ } ) ,
891866 ) ;
867+ } else if ( this . levelAccessor && this . nodeType === 'nested' ) {
868+ this . _dataNodes . next ( nodes ) ;
869+ // In the nested case, we only look for root nodes. The CdkNestedNode
870+ // itself will handle rendering each individual node's children.
871+ const levelAccessor = this . levelAccessor ;
872+ return observableOf ( nodes . filter ( node => levelAccessor ( node ) === 0 ) ) ;
873+ } else {
874+ this . _dataNodes . next ( nodes ) ;
875+ return observableOf ( nodes ) ;
892876 }
893877 }
894878}
0 commit comments