X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/8775768ca3a344775c81b7278a50d56d9be3f9b6..825ea4fce4ba3568f6105c17e83f4769a9323759:/src/models/collection-file.ts diff --git a/src/models/collection-file.ts b/src/models/collection-file.ts index 37e18cfc..3951d272 100644 --- a/src/models/collection-file.ts +++ b/src/models/collection-file.ts @@ -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; @@ -59,12 +60,21 @@ export const createCollectionFilesTree = (data: Array setNode({ children: [], id: item.id, - parent: item.path, + parent: getParentId(item), value: item, active: false, selected: false, expanded: false, status: TreeNodeStatus.INITIAL - })(tree), createTree()); -}; \ 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