X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/8edacc9b2dac6520ace9a2d420979bbeb5558a6f..fe0f3f07a4dea0506844d47529752484cf0347a7:/src/components/tree/virtual-tree.tsx?ds=sidebyside diff --git a/src/components/tree/virtual-tree.tsx b/src/components/tree/virtual-tree.tsx index 467969fa..ca7cd40c 100644 --- a/src/components/tree/virtual-tree.tsx +++ b/src/components/tree/virtual-tree.tsx @@ -2,14 +2,14 @@ // // SPDX-License-Identifier: AGPL-3.0 -import * as React from 'react'; -import * as classnames from "classnames"; +import React from 'react'; +import classnames from "classnames"; import { StyleRulesCallback, withStyles, WithStyles } from '@material-ui/core/styles'; import { ReactElement } from "react"; import { FixedSizeList, ListChildComponentProps } from "react-window"; import AutoSizer from "react-virtualized-auto-sizer"; -import { ArvadosTheme } from '~/common/custom-theme'; +import { ArvadosTheme } from 'common/custom-theme'; import { TreeItem, TreeProps, TreeItemStatus } from './tree'; import { ListItem, Radio, Checkbox, CircularProgress, ListItemIcon } from '@material-ui/core'; import { SidePanelRightArrowIcon } from '../icon/icon'; @@ -24,12 +24,18 @@ type CssRules = 'list' | 'iconOpen' | 'toggableIcon' | 'checkbox' + | 'virtualFileTree' | 'virtualizedList'; const styles: StyleRulesCallback = (theme: ArvadosTheme) => ({ list: { padding: '3px 0px', }, + virtualFileTree: { + "&:last-child": { + paddingBottom: 20 + } + }, virtualizedList: { height: '200px', }, @@ -71,35 +77,36 @@ const styles: StyleRulesCallback = (theme: ArvadosTheme) => ({ } }); -// export const RowA = (items: TreeItem[], render:any) => (index: number) => { -// return
-// {render(items[index])} -//
; -// }; +export interface VirtualTreeItem extends TreeItem { + itemCount?: number; + level?: number; +} // For some reason, on TSX files it isn't accepted just one generic param, so // I'm using as a workaround. -export const Row = (itemList: TreeItem[], render: any) => withStyles(styles)( - (props: React.PropsWithChildren & TreeProps & WithStyles) => { - const { index, style } = props; +// eslint-disable-next-line +export const Row = (itemList: VirtualTreeItem[], render: any, treeProps: TreeProps) => withStyles(styles)( + (props: React.PropsWithChildren & WithStyles) => { + const { index, style, classes } = props; const it = itemList[index]; const level = it.level || 0; - const { classes, toggleItemActive, disableRipple, currentItemUuid, useRadioButtons } = props; - const { listItem, loader, toggableIconContainer, renderContainer } = classes; - const { levelIndentation = 20, itemRightPadding = 20 } = props; + const { toggleItemActive, disableRipple, currentItemUuid, useRadioButtons } = treeProps; + const { listItem, loader, toggableIconContainer, renderContainer, virtualFileTree } = classes; + const { levelIndentation = 20, itemRightPadding = 20 } = treeProps; - const showSelection = typeof props.showSelection === 'function' - ? props.showSelection - : () => props.showSelection ? true : false; + const showSelection = typeof treeProps.showSelection === 'function' + ? treeProps.showSelection + : () => treeProps.showSelection ? true : false; - const handleRowContextMenu = (item: TreeItem) => - (event: React.MouseEvent) => - props.onContextMenu(event, item); + const handleRowContextMenu = (item: VirtualTreeItem) => + (event: React.MouseEvent) => { + treeProps.onContextMenu(event, item); + }; - const handleToggleItemOpen = (item: TreeItem) => + const handleToggleItemOpen = (item: VirtualTreeItem) => (event: React.MouseEvent) => { event.stopPropagation(); - props.toggleItemOpen(event, item); + treeProps.toggleItemOpen(event, item); }; const getToggableIconClassNames = (isOpen?: boolean, isActive?: boolean) => { @@ -120,8 +127,8 @@ export const Row = (itemList: TreeItem[], render: any) => withStyles(s return isSidePanelIconNotNeeded(status, itemCount) ? : ; }; - const handleCheckboxChange = (item: TreeItem) => { - const { toggleItemSelection } = props; + const handleCheckboxChange = (item: VirtualTreeItem) => { + const { toggleItemSelection } = treeProps; return toggleItemSelection ? (event: React.MouseEvent) => { event.stopPropagation(); @@ -130,7 +137,7 @@ export const Row = (itemList: TreeItem[], render: any) => withStyles(s : undefined; }; - return
+ return
(itemList: TreeItem[], render: any) => withStyles(s
; }); -export const VirtualList = (height: number, width: number, items: TreeItem[], render: any) => +const itemSize = 30; + +// eslint-disable-next-line +export const VirtualList = (height: number, width: number, items: VirtualTreeItem[], render: any, treeProps: TreeProps) => - {Row(items, render)} + {Row(items, render, treeProps)} ; export const VirtualTree = withStyles(styles)( class Component extends React.Component & WithStyles, {}> { render(): ReactElement { const { items, render } = this.props; - - return
+ return {({ height, width }) => { - return VirtualList(height, width, items || [], render); + return VirtualList(height, width, items || [], render, this.props); }} -
; + ; } } );