Merge branch '14258-collection-filtering'
[arvados-workbench2.git] / src / models / tree.ts
index 1bc15bc0824a500c1121812c252c82eaa2fc7ca0..bec2f758a478335e6ef437afe6592dde144ce729 100644 (file)
@@ -98,6 +98,9 @@ export const getNodeDescendants = (id: string, limit = Infinity) => <T>(tree: Tr
 export const countNodes = <T>(tree: Tree<T>) =>
     getNodeDescendantsIds('')(tree).length;
 
+export const countChildren = (id: string) => <T>(tree: Tree<T>) =>
+    getNodeChildren('')(tree).length;
+
 export const getNodeDescendantsIds = (id: string, limit = Infinity) => <T>(tree: Tree<T>): string[] => {
     const node = getNode(id)(tree);
     const children = node ? node.children :
@@ -178,6 +181,10 @@ export const deselectNodes = (id: string | string[]) => <T>(tree: Tree<T>) => {
     return ids.reduce((tree, id) => deselectNode(id)(tree), tree);
 };
 
+export const getSelectedNodes = <T>(tree: Tree<T>) =>
+    getNodeDescendants('')(tree)
+        .filter(node => node.selected);
+
 export const initTreeNode = <T>(data: Pick<TreeNode<T>, 'id' | 'value'> & { parent?: string }): TreeNode<T> => ({
     children: [],
     active: false,