X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/232eac919b067a3783348eab549c9fc555b80abd..72b6c853b95b1ef3da2a0beca3a31e4838a17896:/src/models/collection-file.ts diff --git a/src/models/collection-file.ts b/src/models/collection-file.ts index a1400806c4..37e18cfc0d 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; @@ -12,24 +12,31 @@ export enum CollectionFileType { } export interface CollectionDirectory { - parentId: string; + path: string; + url: string; id: string; name: string; type: CollectionFileType.DIRECTORY; } export interface CollectionFile { - parentId: string; + path: string; + url: string; id: string; name: string; size: number; type: CollectionFileType.FILE; } +export interface CollectionUploadFile { + name: string; +} + export const createCollectionDirectory = (data: Partial): CollectionDirectory => ({ id: '', name: '', - parentId: '', + path: '', + url: '', type: CollectionFileType.DIRECTORY, ...data }); @@ -37,8 +44,27 @@ export const createCollectionDirectory = (data: Partial): C export const createCollectionFile = (data: Partial): CollectionFile => ({ id: '', name: '', - parentId: '', + path: '', + url: '', size: 0, type: CollectionFileType.FILE, ...data -}); \ No newline at end of file +}); + +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