1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { uniqBy } from 'lodash';
6 import { KeepManifestStream, KeepManifestStreamFile, KeepManifest } from "../../../models/keep-manifest";
8 export type CollectionPanelFilesState = Array<CollectionPanelItem>;
10 export type CollectionPanelItem = CollectionPanelDirectory | CollectionPanelFile;
12 export interface CollectionPanelDirectory {
21 export interface CollectionPanelFile {
30 export const mapManifestToItems = (manifest: KeepManifest): CollectionPanelItem[] => ([
31 ...mapManifestToDirectories(manifest),
32 ...mapManifestToFiles(manifest)
35 export const mapManifestToDirectories = (manifest: KeepManifest): CollectionPanelDirectory[] =>
38 .map(mapStreamDirectory)
40 .reduce((all, splitted) => ([...all, ...splitted]), []),
41 directory => directory.id);
43 export const mapManifestToFiles = (manifest: KeepManifest): CollectionPanelFile[] =>
45 .map(stream => stream.files.map(mapStreamFile(stream)))
46 .reduce((all, current) => ([...all, ...current]), []);
48 const splitDirectory = (directory: CollectionPanelDirectory): CollectionPanelDirectory[] => {
52 .map(mapPathComponentToDirectory);
55 const mapPathComponentToDirectory = (component: string, index: number, components: string[]): CollectionPanelDirectory =>
57 parentId: index === 0 ? '' : joinPathComponents(components, index),
58 id: joinPathComponents(components, index + 1),
62 const joinPathComponents = (components: string[], index: number) =>
63 `/${components.slice(0, index).join('/')}`;
65 const mapStreamDirectory = (stream: KeepManifestStream): CollectionPanelDirectory =>
72 const mapStreamFile = (stream: KeepManifestStream) =>
73 (file: KeepManifestStreamFile): CollectionPanelFile =>
75 parentId: stream.name,
76 id: `${stream.name}/${file.name}`,
81 const createDirectory = (data: { parentId: string, id: string, name: string }): CollectionPanelDirectory => ({
88 const createFile = (data: { parentId: string, id: string, name: string, size: number }): CollectionPanelFile => ({