X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/725ea8d5e40c33ccba89ba2936b135ea0ddddd5a..bb7f866a34548157fd5ba69475da4c8065f0227b:/src/views-components/projects-tree-picker/generic-projects-tree-picker.tsx diff --git a/src/views-components/projects-tree-picker/generic-projects-tree-picker.tsx b/src/views-components/projects-tree-picker/generic-projects-tree-picker.tsx index c877a15466..77f831fafd 100644 --- a/src/views-components/projects-tree-picker/generic-projects-tree-picker.tsx +++ b/src/views-components/projects-tree-picker/generic-projects-tree-picker.tsx @@ -28,18 +28,15 @@ export interface ProjectsTreePickerDataProps { includeCollections?: boolean; includeFiles?: boolean; rootItemIcon: IconType; - rootItemSelection?: boolean; - projectsSelection?: boolean; - collectionsSelection?: boolean; - filesSelection?: boolean; + showSelection?: boolean; loadRootItem: (item: TreeItem, pickerId: string, includeCollections?: boolean, inlcudeFiles?: boolean) => void; } export type ProjectsTreePickerProps = ProjectsTreePickerDataProps & Partial; -const mapStateToProps = (_: any, { rootItemIcon, ...props }: ProjectsTreePickerProps) => ({ +const mapStateToProps = (_: any, { rootItemIcon, showSelection }: ProjectsTreePickerProps) => ({ render: renderTreeItem(rootItemIcon), - showSelection: isSelectionVisible(props), + showSelection: isSelectionVisible(showSelection), }); const mapDispatchToProps = (dispatch: Dispatch, { loadRootItem, includeCollections, includeFiles, ...props }: ProjectsTreePickerProps): PickedTreePickerProps => ({ @@ -66,8 +63,11 @@ const mapDispatchToProps = (dispatch: Dispatch, { loadRootItem, includeCollectio dispatch(treePickerActions.TOGGLE_TREE_PICKER_NODE_COLLAPSE({ id, pickerId })); } }, - toggleItemSelection: (_, { id }, pickerId) => { - dispatch(treePickerActions.TOGGLE_TREE_PICKER_NODE_SELECTION({ id, pickerId })); + toggleItemSelection: (event, item, pickerId) => { + dispatch(treePickerActions.TOGGLE_TREE_PICKER_NODE_SELECTION({ id: item.id, pickerId })); + if(props.toggleItemSelection){ + props.toggleItemSelection(event, item, pickerId); + } }, }); @@ -92,26 +92,16 @@ const getProjectPickerIcon = ({ data }: TreeItem, rootIc return rootIcon; } }; -interface IsSelectionVisibleParams { - rootItemSelection?: boolean; - projectsSelection?: boolean; - collectionsSelection?: boolean; - filesSelection?: boolean; -} -const isSelectionVisible = (params: IsSelectionVisibleParams) => - ({ data, status }: TreeItem) => { - if ('kind' in data) { - switch (data.kind) { - case ResourceKind.COLLECTION: - return !!params.collectionsSelection; - default: - return !!params.projectsSelection; + +const isSelectionVisible = (shouldBeVisible?: boolean) => + ({ status, items }: TreeItem): boolean => { + if (shouldBeVisible) { + if (items && items.length > 0) { + return items.every(isSelectionVisible(shouldBeVisible)); } - } else if ('type' in data) { - return !!params.filesSelection; - } else { - return !!params.rootItemSelection; + return status === TreeItemStatus.LOADED; } + return false; }; const renderTreeItem = (rootItemIcon: IconType) => (item: TreeItem) =>