1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { ResourcesDataActions, resourcesDataActions } from "~/store/resources-data/resources-data-actions";
6 import { getNodeDescendantsIds, TREE_ROOT_ID } from "~/models/tree";
7 import { CollectionFileType } from "~/models/collection-file";
9 export interface ResourceData {
14 export type ResourcesDataState = {
15 [key: string]: ResourceData
18 export const resourcesDataReducer = (state: ResourcesDataState = {}, action: ResourcesDataActions) =>
19 resourcesDataActions.match(action, {
20 SET_FILES: ({uuid, files}) => {
21 const flattenFiles = getNodeDescendantsIds(TREE_ROOT_ID)(files).map(id => files[id]);
22 const [fileSize, fileCount] = flattenFiles.reduce(([size, cnt], f) =>
23 f && f.value.type === CollectionFileType.FILE
24 ? [size + f.value.size, cnt + 1]
29 [uuid]: { fileCount, fileSize }