X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/185f57cf4371e7811077bee56976028dd640688d..db1c206c8403ed2b874625f1d1afc7af85dde25c:/src/views-components/projects-tree-picker/projects-tree-picker.tsx diff --git a/src/views-components/projects-tree-picker/projects-tree-picker.tsx b/src/views-components/projects-tree-picker/projects-tree-picker.tsx index ae98cf00..bddde892 100644 --- a/src/views-components/projects-tree-picker/projects-tree-picker.tsx +++ b/src/views-components/projects-tree-picker/projects-tree-picker.tsx @@ -2,38 +2,98 @@ // // SPDX-License-Identifier: AGPL-3.0 -import * as React from 'react'; -import { values, memoize, pipe, pick } from 'lodash/fp'; -import { HomeTreePicker } from '~/views-components/projects-tree-picker/home-tree-picker'; -import { SharedTreePicker } from '~/views-components/projects-tree-picker/shared-tree-picker'; -import { FavoritesTreePicker } from '~/views-components/projects-tree-picker/favorites-tree-picker'; -import { getProjectsTreePickerIds, SHARED_PROJECT_ID, FAVORITES_PROJECT_ID } from '~/store/tree-picker/tree-picker-actions'; -import { TreeItem } from '~/components/tree/tree'; -import { ProjectsTreePickerItem } from './generic-projects-tree-picker'; +import React from 'react'; +import { Dispatch } from 'redux'; +import { connect } from 'react-redux'; +import { RootState } from 'store/store'; +import { values, pipe } from 'lodash/fp'; +import { HomeTreePicker } from 'views-components/projects-tree-picker/home-tree-picker'; +import { SharedTreePicker } from 'views-components/projects-tree-picker/shared-tree-picker'; +import { FavoritesTreePicker } from 'views-components/projects-tree-picker/favorites-tree-picker'; +import { getProjectsTreePickerIds, treePickerSearchActions, SHARED_PROJECT_ID, FAVORITES_PROJECT_ID } from 'store/tree-picker/tree-picker-actions'; +import { TreeItem } from 'components/tree/tree'; +import { ProjectsTreePickerItem } from 'store/tree-picker/tree-picker-middleware'; +import { PublicFavoritesTreePicker } from './public-favorites-tree-picker'; +import { SearchInput } from 'components/search-input/search-input'; export interface ProjectsTreePickerProps { pickerId: string; includeCollections?: boolean; includeFiles?: boolean; showSelection?: boolean; + options?: { showOnlyOwned: boolean, showOnlyWritable: boolean }; toggleItemActive?: (event: React.MouseEvent, item: TreeItem, pickerId: string) => void; toggleItemSelection?: (event: React.MouseEvent, item: TreeItem, pickerId: string) => void; } -export const ProjectsTreePicker = ({ pickerId, ...props }: ProjectsTreePickerProps) => { - const { home, shared, favorites } = getProjectsTreePickerIds(pickerId); +interface ProjectsTreePickerSearchProps { + projectSearch: string; + collectionFilter: string; +} + +interface ProjectsTreePickerActionProps { + onProjectSearch: (value: string) => void; + onCollectionFilter: (value: string) => void; +} + +type ProjectsTreePickerCombinedProps = ProjectsTreePickerProps & ProjectsTreePickerSearchProps & ProjectsTreePickerActionProps; + +const mapStateToProps = (state: RootState, props: ProjectsTreePickerProps): ProjectsTreePickerSearchProps => ({ + projectSearch: "", + collectionFilter: "", + ...props +}); + +const mapDispatchToProps = (dispatch: Dispatch, props: ProjectsTreePickerProps): ProjectsTreePickerActionProps => { + const { home, shared, favorites, publicFavorites } = getProjectsTreePickerIds(props.pickerId); + const params = { + includeCollections: props.includeCollections, + includeFiles: props.includeFiles, + options: props.options + }; + dispatch(treePickerSearchActions.SET_TREE_PICKER_LOAD_PARAMS({ pickerId: home, params })); + dispatch(treePickerSearchActions.SET_TREE_PICKER_LOAD_PARAMS({ pickerId: shared, params })); + dispatch(treePickerSearchActions.SET_TREE_PICKER_LOAD_PARAMS({ pickerId: favorites, params })); + dispatch(treePickerSearchActions.SET_TREE_PICKER_LOAD_PARAMS({ pickerId: publicFavorites, params })); + + return { + onProjectSearch: (projectSearchValue: string) => dispatch(treePickerSearchActions.SET_TREE_PICKER_PROJECT_SEARCH({ pickerId: props.pickerId, projectSearchValue })), + onCollectionFilter: (collectionFilterValue: string) => { + dispatch(treePickerSearchActions.SET_TREE_PICKER_COLLECTION_FILTER({ pickerId: home, collectionFilterValue })); + dispatch(treePickerSearchActions.SET_TREE_PICKER_COLLECTION_FILTER({ pickerId: shared, collectionFilterValue })); + dispatch(treePickerSearchActions.SET_TREE_PICKER_COLLECTION_FILTER({ pickerId: favorites, collectionFilterValue })); + dispatch(treePickerSearchActions.SET_TREE_PICKER_COLLECTION_FILTER({ pickerId: publicFavorites, collectionFilterValue })); + } + } +}; + +export const ProjectsTreePicker = connect(mapStateToProps, mapDispatchToProps)(({ pickerId, onProjectSearch, onCollectionFilter, ...props }: ProjectsTreePickerCombinedProps) => { + const { home, shared, favorites, publicFavorites } = getProjectsTreePickerIds(pickerId); const relatedTreePickers = getRelatedTreePickers(pickerId); const p = { ...props, relatedTreePickers, - disableActivation + disableActivation, }; return
- - - + + + + +
+ +
+
+ +
+
+ +
+
+ +
; -}; +}); -const getRelatedTreePickers = memoize(pipe(getProjectsTreePickerIds, values)); +const getRelatedTreePickers = pipe(getProjectsTreePickerIds, values); const disableActivation = [SHARED_PROJECT_ID, FAVORITES_PROJECT_ID];