import type { Node , NodeList } from '../Tree' ; export const getDescendantByParent = ( nodes , currentContainer ) : NodeList => { const foundList = [ ] ; const search = ( currentParent ) => { nodes . forEach ( ( n ) => { if ( ! foundList . includes ( n . id ) && n . parentId === currentParent && n . id !== currentParent ) { foundList . push ( n . id ) ; search ( n . id ) ; } } ) ; } ; search ( currentContainer . id ) ; return nodes . filter ( ( n ) => foundList . includes ( n . id ) ) ; } ; export const getAllDescendantsForCurrentContainers = ( nodeList , containerItems ) : Array < NodeList > => { return containerItems . map ( ( parent ) => { return getDescendantByParent ( nodeList , parent ) ; } ) ; } ; export const getChildrenByParent = ( nodes , parentId = null ) : NodeList => { return nodes . filter ( ( n ) => n . parentId === parentId ) ; } ;