X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/54c77552a4ff0403eb627408ed38a9d8b60606b3..39bdc716190a21ee7c70d9450fc121a0513ff8ba:/src/store/tree-picker/tree-picker-actions.ts diff --git a/src/store/tree-picker/tree-picker-actions.ts b/src/store/tree-picker/tree-picker-actions.ts index b8003aa1c2..505e0622e7 100644 --- a/src/store/tree-picker/tree-picker-actions.ts +++ b/src/store/tree-picker/tree-picker-actions.ts @@ -4,7 +4,7 @@ import { unionize, ofType, UnionOf } from "common/unionize"; import { TreeNode, initTreeNode, getNodeDescendants, TreeNodeStatus, getNode, TreePickerId, Tree } from 'models/tree'; -import { CollectionFileType, createCollectionFilesTree } from "models/collection-file"; +import { CollectionFileType, createCollectionFilesTree, getCollectionResourceCollectionUuid } from "models/collection-file"; import { Dispatch } from 'redux'; import { RootState } from 'store/store'; import { getUserUuid } from "common/getuser"; @@ -482,3 +482,32 @@ const buildParams = (ownerUuid: string) => { .getOrder() }; }; + +/** + * Given a tree picker item, return collection uuid and path + * if the item represents a valid target/destination location + */ +export type FileOperationLocation = { + uuid: string; + path: string; +} +export const getFileOperationLocation = (item: ProjectsTreePickerItem): FileOperationLocation | undefined => { + if ('kind' in item && item.kind === ResourceKind.COLLECTION) { + return { + uuid: item.uuid, + path: '/' + }; + } else if ('type' in item && item.type === CollectionFileType.DIRECTORY) { + const uuid = getCollectionResourceCollectionUuid(item.id); + if (uuid) { + return { + uuid, + path: [item.path, item.name].join('/') + }; + } else { + return undefined; + } + } else { + return undefined; + } +};