1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from "react";
6 import { Dispatch } from "redux";
7 import { connect } from "react-redux";
8 import { TreePicker, TreePickerProps } from "../tree-picker/tree-picker";
9 import { TreeItem } from "~/components/tree/tree";
10 import { ProjectResource } from "~/models/project";
11 import { ListItemTextIcon } from "~/components/list-item-text-icon/list-item-text-icon";
12 import { ProjectIcon, FavoriteIcon, ProjectsIcon, ShareMeIcon, TrashIcon, PublicFavoriteIcon } from '~/components/icon/icon';
13 import { WorkflowIcon } from '~/components/icon/icon';
14 import { activateSidePanelTreeItem, toggleSidePanelTreeItemCollapse, SIDE_PANEL_TREE, SidePanelTreeCategory } from '~/store/side-panel-tree/side-panel-tree-actions';
15 import { openSidePanelContextMenu } from '~/store/context-menu/context-menu-actions';
16 import { noop } from 'lodash';
17 export interface SidePanelTreeProps {
18 onItemActivation: (id: string) => void;
19 sidePanelProgress?: boolean;
22 type SidePanelTreeActionProps = Pick<TreePickerProps<ProjectResource | string>, 'onContextMenu' | 'toggleItemActive' | 'toggleItemOpen' | 'toggleItemSelection'>;
24 const mapDispatchToProps = (dispatch: Dispatch, props: SidePanelTreeProps): SidePanelTreeActionProps => ({
25 onContextMenu: (event, { id }) => {
26 dispatch<any>(openSidePanelContextMenu(event, id));
28 toggleItemActive: (_, { id }) => {
29 dispatch<any>(activateSidePanelTreeItem(id));
30 props.onItemActivation(id);
32 toggleItemOpen: (_, { id }) => {
33 dispatch<any>(toggleSidePanelTreeItemCollapse(id));
35 toggleItemSelection: noop,
38 export const SidePanelTree = connect(undefined, mapDispatchToProps)(
39 (props: SidePanelTreeActionProps) =>
40 <TreePicker {...props} render={renderSidePanelItem} pickerId={SIDE_PANEL_TREE} />);
42 const renderSidePanelItem = (item: TreeItem<ProjectResource>) =>
44 icon={getProjectPickerIcon(item)}
45 name={typeof item.data === 'string' ? item.data : item.data.name}
46 isActive={item.active}
51 const getProjectPickerIcon = (item: TreeItem<ProjectResource | string>) =>
52 typeof item.data === 'string'
53 ? getSidePanelIcon(item.data)
56 const getSidePanelIcon = (category: string) => {
58 case SidePanelTreeCategory.FAVORITES:
60 case SidePanelTreeCategory.PROJECTS:
62 case SidePanelTreeCategory.SHARED_WITH_ME:
64 case SidePanelTreeCategory.TRASH:
66 case SidePanelTreeCategory.WORKFLOWS:
68 case SidePanelTreeCategory.PUBLIC_FAVORITES:
69 return PublicFavoriteIcon;