1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import 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 { ProcessIcon, ProjectIcon, FilterGroupIcon, FavoriteIcon, ProjectsIcon, ShareMeIcon, TrashIcon, PublicFavoriteIcon, GroupsIcon, TerminalIcon, ResourceIcon } from 'components/icon/icon';
13 import { activateSidePanelTreeItem, toggleSidePanelTreeItemCollapse, SIDE_PANEL_TREE, SidePanelTreeCategory } from 'store/side-panel-tree/side-panel-tree-actions';
14 import { openSidePanelContextMenu } from 'store/context-menu/context-menu-actions';
15 import { noop } from 'lodash';
16 import { ResourceKind } from "models/resource";
17 import { IllegalNamingWarning } from "components/warning/warning";
18 import { GroupClass } from "models/group";
20 export interface SidePanelTreeProps {
21 onItemActivation: (id: string) => void;
22 sidePanelProgress?: boolean;
24 setCurrentSideWidth: (width: number) => void
27 type SidePanelTreeActionProps = Pick<TreePickerProps<ProjectResource | string>, 'onContextMenu' | 'toggleItemActive' | 'toggleItemOpen' | 'toggleItemSelection'>;
29 const mapDispatchToProps = (dispatch: Dispatch, props: SidePanelTreeProps): SidePanelTreeActionProps => ({
30 onContextMenu: (event, { id }) => {
31 dispatch<any>(openSidePanelContextMenu(event, id));
33 toggleItemActive: (_, { id }) => {
34 dispatch<any>(activateSidePanelTreeItem(id));
35 props.onItemActivation(id);
37 toggleItemOpen: (_, { id }) => {
38 dispatch<any>(toggleSidePanelTreeItemCollapse(id));
40 toggleItemSelection: noop,
43 export const SidePanelTree = connect(undefined, mapDispatchToProps)(
44 (props: SidePanelTreeActionProps) =>
45 <div data-cy="side-panel-tree">
46 <TreePicker {...props} render={renderSidePanelItem} pickerId={SIDE_PANEL_TREE} />
49 const renderSidePanelItem = (item: TreeItem<ProjectResource>) => {
50 const name = typeof item.data === 'string' ? item.data : item.data.name;
51 const warn = typeof item.data !== 'string' && item.data.kind === ResourceKind.PROJECT
52 ? <IllegalNamingWarning name={name} />
54 return <ListItemTextIcon
55 icon={getProjectPickerIcon(item)}
58 isActive={item.active}
63 const getProjectPickerIcon = (item: TreeItem<ProjectResource | string>) =>
64 typeof item.data === 'string'
65 ? getSidePanelIcon(item.data)
66 : (item.data && item.data.groupClass === GroupClass.FILTER)
70 export const getSidePanelIcon = (category: string) => {
72 case SidePanelTreeCategory.FAVORITES:
74 case SidePanelTreeCategory.PROJECTS:
76 case SidePanelTreeCategory.SHARED_WITH_ME:
78 case SidePanelTreeCategory.TRASH:
80 case SidePanelTreeCategory.PUBLIC_FAVORITES:
81 return PublicFavoriteIcon;
82 case SidePanelTreeCategory.ALL_PROCESSES:
84 case SidePanelTreeCategory.INSTANCE_TYPES:
86 case SidePanelTreeCategory.GROUPS:
88 case SidePanelTreeCategory.SHELL_ACCESS: