X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/86d0ec68c0a400ab6d4de1897a68a4593f450b60..25216cc7acedc987c26a159f0b640210c0ef101e:/src/components/tree/tree.tsx?ds=sidebyside diff --git a/src/components/tree/tree.tsx b/src/components/tree/tree.tsx index 9680e3c0..3b1145fe 100644 --- a/src/components/tree/tree.tsx +++ b/src/components/tree/tree.tsx @@ -5,13 +5,15 @@ import * as React from 'react'; import { List, ListItem, ListItemIcon, Checkbox, Radio, Collapse } from "@material-ui/core"; import { StyleRulesCallback, withStyles, WithStyles } from '@material-ui/core/styles'; -import { ProjectIcon } from '~/components/icon/icon'; +import { CollectionIcon, DefaultIcon, DirectoryIcon, FileIcon, ProjectIcon, FilterGroupIcon } from 'components/icon/icon'; import { ReactElement } from "react"; import CircularProgress from '@material-ui/core/CircularProgress'; import classnames from "classnames"; -import { ArvadosTheme } from '~/common/custom-theme'; +import { ArvadosTheme } from 'common/custom-theme'; import { SidePanelRightArrowIcon } from '../icon/icon'; +import { ResourceKind } from 'models/resource'; +import { GroupClass } from 'models/group'; type CssRules = 'list' | 'listItem' @@ -105,6 +107,7 @@ export interface TreeProps { currentItemUuid?: string; items?: Array>; level?: number; + itemsMap?: Map>; onContextMenu: (event: React.MouseEvent, item: TreeItem) => void; render: (item: TreeItem, level?: number) => ReactElement<{}>; showSelection?: boolean | ((item: TreeItem) => boolean); @@ -150,16 +153,52 @@ interface FlatTreeProps { toggleItemActive: Function; getToggableIconClassNames: Function; getProperArrowAnimation: Function; + itemsMap?: Map>; classes: any; + showSelection: any; + useRadioButtons?: boolean; + handleCheckboxChange: Function; } - const FLAT_TREE_ACTIONS = { toggleOpen: 'TOGGLE_OPEN', contextMenu: 'CONTEXT_MENU', toggleActive: 'TOGGLE_ACTIVE', }; +const ItemIcon = React.memo(({ type, kind, active, groupClass, classes }: any) => { + let Icon = ProjectIcon; + + if (groupClass === GroupClass.FILTER) { + Icon = FilterGroupIcon; + } + + if (type) { + switch (type) { + case 'directory': + Icon = DirectoryIcon; + break; + case 'file': + Icon = FileIcon; + break; + default: + Icon = DefaultIcon; + } + } + + if (kind) { + switch (kind) { + case ResourceKind.COLLECTION: + Icon = CollectionIcon; + break; + default: + break; + } + } + + return ; +}); + const FlatTree = (props: FlatTreeProps) =>
{ @@ -170,12 +209,14 @@ const FlatTree = (props: FlatTreeProps) => const [action, id] = getActionAndId(event); if (action && id) { + const item = props.itemsMap ? props.itemsMap[id] : { id }; + switch (action) { case FLAT_TREE_ACTIONS.toggleOpen: - props.handleToggleItemOpen({ id } as any, event); + props.handleToggleItemOpen(item as any, event); break; case FLAT_TREE_ACTIONS.toggleActive: - props.toggleItemActive(event, { id } as any); + props.toggleItemActive(event, item as any); break; default: break; @@ -193,9 +234,20 @@ const FlatTree = (props: FlatTreeProps) => {props.getProperArrowAnimation(item.status, item.items!)} + {props.showSelection(item) && !props.useRadioButtons && + } + {props.showSelection(item) && props.useRadioButtons && + }
- + {item.data.name} @@ -209,7 +261,7 @@ export const Tree = withStyles(styles)( class Component extends React.Component & WithStyles, {}> { render(): ReactElement { const level = this.props.level ? this.props.level : 0; - const { classes, render, items, toggleItemActive, toggleItemOpen, disableRipple, currentItemUuid, useRadioButtons } = this.props; + const { classes, render, items, toggleItemActive, toggleItemOpen, disableRipple, currentItemUuid, useRadioButtons, itemsMap } = this.props; const { list, listItem, loader, toggableIconContainer, renderContainer } = classes; const showSelection = typeof this.props.showSelection === 'function' ? this.props.showSelection @@ -255,28 +307,32 @@ export const Tree = withStyles(styles)( { it.open && it.items && it.items.length > 0 && it.flatTree ? - : + + : - - - + toggleItemSelection={this.props.toggleItemSelection} /> + }
)} ;