X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/c11055f2d6ce8385088bc221eab1175e31777ec0..5cefad212822a48c83af1d38cbe14368c0cb1a20:/src/models/collection-file.ts diff --git a/src/models/collection-file.ts b/src/models/collection-file.ts index d74ada60..91008d1f 100644 --- a/src/models/collection-file.ts +++ b/src/models/collection-file.ts @@ -2,7 +2,8 @@ // // SPDX-License-Identifier: AGPL-3.0 -import { Tree, createTree, setNode } from './tree'; +import { Tree, createTree, setNode, TreeNodeStatus } from './tree'; +import { head, split, pipe, join } from 'lodash/fp'; export type CollectionFilesTree = Tree; @@ -51,7 +52,7 @@ export const createCollectionFile = (data: Partial): CollectionF ...data }); -export const createCollectionFilesTree = (data: Array) => { +export const createCollectionFilesTree = (data: Array, joinParents: Boolean = true) => { const directories = data.filter(item => item.type === CollectionFileType.DIRECTORY); directories.sort((a, b) => a.path.localeCompare(b.path)); const files = data.filter(item => item.type === CollectionFileType.FILE); @@ -59,7 +60,21 @@ export const createCollectionFilesTree = (data: Array setNode({ children: [], id: item.id, - parent: item.path, - value: item + parent: joinParents ? 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