merge master
[arvados.git] / src / views-components / projects-tree-picker / projects-tree-picker.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import * as React from 'react';
6 import { values, memoize, pipe, pick } from 'lodash/fp';
7 import { HomeTreePicker } from '~/views-components/projects-tree-picker/home-tree-picker';
8 import { SharedTreePicker } from '~/views-components/projects-tree-picker/shared-tree-picker';
9 import { FavoritesTreePicker } from '~/views-components/projects-tree-picker/favorites-tree-picker';
10 import { getProjectsTreePickerIds, SHARED_PROJECT_ID, FAVORITES_PROJECT_ID } from '~/store/tree-picker/tree-picker-actions';
11 import { TreeItem } from '~/components/tree/tree';
12 import { ProjectsTreePickerItem } from './generic-projects-tree-picker';
13
14 export interface ProjectsTreePickerProps {
15     pickerId: string;
16     includeCollections?: boolean;
17     includeFiles?: boolean;
18     showSelection?: boolean;
19     toggleItemActive?: (event: React.MouseEvent<HTMLElement>, item: TreeItem<ProjectsTreePickerItem>, pickerId: string) => void;
20     toggleItemSelection?: (event: React.MouseEvent<HTMLElement>, item: TreeItem<ProjectsTreePickerItem>, pickerId: string) => void;
21 }
22
23 export const ProjectsTreePicker = ({ pickerId, ...props }: ProjectsTreePickerProps) => {
24     const { home, shared, favorites } = getProjectsTreePickerIds(pickerId);
25     const relatedTreePickers = getRelatedTreePickers(pickerId);
26     const p = {
27         ...props,
28         relatedTreePickers,
29         disableActivation
30     };
31     return <div>
32         <HomeTreePicker pickerId={home} {...p} />
33         <SharedTreePicker pickerId={shared} {...p} />
34         <FavoritesTreePicker pickerId={favorites} {...p} />
35     </div>;
36 };
37
38 const getRelatedTreePickers = memoize(pipe(getProjectsTreePickerIds, values));
39 const disableActivation = [SHARED_PROJECT_ID, FAVORITES_PROJECT_ID];