X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/40952ad86a823635968c9abc5d6feacef316cffd..ba27bdf218da8894df4ffa6174c67c1fb3e70c81:/src/models/collection-file.ts diff --git a/src/models/collection-file.ts b/src/models/collection-file.ts index a4b656c5..37e18cfc 100644 --- a/src/models/collection-file.ts +++ b/src/models/collection-file.ts @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: AGPL-3.0 -import { Tree } from './tree'; +import { Tree, createTree, setNode, TreeNodeStatus } from './tree'; export type CollectionFilesTree = Tree; @@ -13,6 +13,7 @@ export enum CollectionFileType { export interface CollectionDirectory { path: string; + url: string; id: string; name: string; type: CollectionFileType.DIRECTORY; @@ -20,6 +21,7 @@ export interface CollectionDirectory { export interface CollectionFile { path: string; + url: string; id: string; name: string; size: number; @@ -34,6 +36,7 @@ export const createCollectionDirectory = (data: Partial): C id: '', name: '', path: '', + url: '', type: CollectionFileType.DIRECTORY, ...data }); @@ -42,7 +45,26 @@ export const createCollectionFile = (data: Partial): CollectionF id: '', name: '', path: '', + url: '', size: 0, type: CollectionFileType.FILE, ...data }); + +export const createCollectionFilesTree = (data: Array) => { + 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); + return [...directories, ...files] + .reduce((tree, item) => setNode({ + children: [], + id: item.id, + parent: item.path, + value: item, + active: false, + selected: false, + expanded: false, + status: TreeNodeStatus.INITIAL + + })(tree), createTree()); +}; \ No newline at end of file