Create function for creating correct file's parent id
authorMichal Klobukowski <michal.klobukowski@contractors.roche.com>
Tue, 13 Nov 2018 11:56:00 +0000 (12:56 +0100)
committerMichal Klobukowski <michal.klobukowski@contractors.roche.com>
Tue, 13 Nov 2018 11:56:00 +0000 (12:56 +0100)
Feature #14436

Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski <michal.klobukowski@contractors.roche.com>

src/models/collection-file.ts

index 37e18cfc0d247905900d3fec4ac6160a8d3afe01..97afcac6ca70d4f5d7fc0f8f005e980b3597d7eb 100644 (file)
@@ -3,6 +3,7 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import { Tree, createTree, setNode, TreeNodeStatus } from './tree';
+import { head, split, pipe, join } from 'lodash/fp';
 
 export type CollectionFilesTree = Tree<CollectionDirectory | CollectionFile>;
 
@@ -59,7 +60,7 @@ export const createCollectionFilesTree = (data: Array<CollectionDirectory | Coll
         .reduce((tree, item) => setNode({
             children: [],
             id: item.id,
-            parent: item.path,
+            parent: getParentId(item),
             value: item,
             active: false,
             selected: false,
@@ -67,4 +68,14 @@ export const createCollectionFilesTree = (data: Array<CollectionDirectory | Coll
             status: TreeNodeStatus.INITIAL
 
         })(tree), createTree<CollectionDirectory | CollectionFile>());
-};
\ No newline at end of file
+};
+
+const getParentId = (item: CollectionDirectory | CollectionFile) =>
+    item.path
+        ? join('', [getCollectionId(item.id), item.path])
+        : item.path;
+
+const getCollectionId = pipe(
+    split('/'),
+    head,
+);
\ No newline at end of file