1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { Tree, createTree, setNode, TreeNodeStatus } from './tree';
7 export type CollectionFilesTree = Tree<CollectionDirectory | CollectionFile>;
9 export enum CollectionFileType {
10 DIRECTORY = 'directory',
14 export interface CollectionDirectory {
19 type: CollectionFileType.DIRECTORY;
22 export interface CollectionFile {
28 type: CollectionFileType.FILE;
31 export interface CollectionUploadFile {
35 export const createCollectionDirectory = (data: Partial<CollectionDirectory>): CollectionDirectory => ({
40 type: CollectionFileType.DIRECTORY,
44 export const createCollectionFile = (data: Partial<CollectionFile>): CollectionFile => ({
50 type: CollectionFileType.FILE,
54 export const createCollectionFilesTree = (data: Array<CollectionDirectory | CollectionFile>) => {
55 const directories = data.filter(item => item.type === CollectionFileType.DIRECTORY);
56 directories.sort((a, b) => a.path.localeCompare(b.path));
57 const files = data.filter(item => item.type === CollectionFileType.FILE);
58 return [...directories, ...files]
59 .reduce((tree, item) => setNode({
67 status: TreeNodeStatus.INITIAL
69 })(tree), createTree<CollectionDirectory | CollectionFile>());