X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/876e5e2f31a218255845977489ea70aacc0211cd..9a59fad2b6a97af963728a5111395f9caa71802f:/src/store/collection-panel/collection-panel-files/collection-panel-files-state.ts diff --git a/src/store/collection-panel/collection-panel-files/collection-panel-files-state.ts b/src/store/collection-panel/collection-panel-files/collection-panel-files-state.ts index f7955eb6..0044a66d 100644 --- a/src/store/collection-panel/collection-panel-files/collection-panel-files-state.ts +++ b/src/store/collection-panel/collection-panel-files/collection-panel-files-state.ts @@ -2,8 +2,8 @@ // // SPDX-License-Identifier: AGPL-3.0 -import { CollectionFile, CollectionDirectory, CollectionFileType } from '~/models/collection-file'; -import { Tree, TreeNode } from '~/models/tree'; +import { Tree, TreeNode, mapTreeValues, getNodeValue, getNodeDescendants } from 'models/tree'; +import { CollectionFile, CollectionDirectory, CollectionFileType } from 'models/collection-file'; export type CollectionPanelFilesState = Tree; @@ -24,3 +24,21 @@ export const mapCollectionFileToCollectionPanelFile = (node: TreeNode { + return mapTreeValues((value: CollectionPanelDirectory | CollectionPanelFile) => { + const oldValue = getNodeValue(value.id)(oldState); + return oldValue + ? oldValue.type === CollectionFileType.DIRECTORY + ? { ...value, collapsed: oldValue.collapsed, selected: oldValue.selected } + : { ...value, selected: oldValue.selected } + : value; + })(newState); +}; + +export const filterCollectionFilesBySelection = (tree: CollectionPanelFilesState, selected: boolean) => { + const allFiles = getNodeDescendants('')(tree).map(node => node.value); + const selectedDirectories = allFiles.filter(file => file.selected === selected && file.type === CollectionFileType.DIRECTORY); + const selectedFiles = allFiles.filter(file => file.selected === selected && !selectedDirectories.some(dir => dir.id === file.path)); + return [...selectedDirectories, ...selectedFiles]; +};