X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/63210cc7d29062bcffa7af461e27f56d3b8bac7c..68ac0f45eef3ed971615fb0a0849c950b74d7e06:/src/components/tree/tree.tsx

diff --git a/src/components/tree/tree.tsx b/src/components/tree/tree.tsx
index 8de9bda5..e4d8c72c 100644
--- a/src/components/tree/tree.tsx
+++ b/src/components/tree/tree.tsx
@@ -5,10 +5,43 @@
 import * as React from 'react';
 import List from "@material-ui/core/List/List";
 import ListItem from "@material-ui/core/ListItem/ListItem";
-import { StyleRulesCallback, Theme, withStyles, WithStyles } from '@material-ui/core/styles';
+import { StyleRulesCallback, withStyles, WithStyles } from '@material-ui/core/styles';
 import { ReactElement } from "react";
 import Collapse from "@material-ui/core/Collapse/Collapse";
 import CircularProgress from '@material-ui/core/CircularProgress';
+import { ArvadosTheme } from '../../common/custom-theme';
+
+type CssRules = 'list' | 'activeArrow' | 'inactiveArrow' | 'arrowRotate' | 'arrowTransition' | 'loader' | 'arrowVisibility';
+
+const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
+    list: {
+        paddingBottom: '3px',
+        paddingTop: '3px',
+    },
+    activeArrow: {
+        color: theme.palette.primary.main,
+        position: 'absolute',
+    },
+    inactiveArrow: {
+        color: theme.palette.grey["700"],
+        position: 'absolute',
+    },
+    arrowTransition: {
+        transition: 'all 0.1s ease',
+    },
+    arrowRotate: {
+        transition: 'all 0.1s ease',
+        transform: 'rotate(-90deg)',
+    },
+    arrowVisibility: {
+        opacity: 0,
+    },
+    loader: {
+        position: 'absolute',
+        transform: 'translate(0px)',
+        top: '3px'
+    }
+});
 
 export enum TreeItemStatus {
     Initial,
@@ -35,76 +68,48 @@ interface TreeProps<T> {
     onContextMenu: (event: React.MouseEvent<HTMLElement>, item: TreeItem<T>) => void;
 }
 
-class Tree<T> extends React.Component<TreeProps<T> & WithStyles<CssRules>, {}> {
-    render(): ReactElement<any> {
-        const level = this.props.level ? this.props.level : 0;
-        const { classes, render, toggleItemOpen, items, toggleItemActive, onContextMenu } = this.props;
-        const { list, inactiveArrow, activeArrow, loader } = classes;
-        return <List component="div" className={list}>
-            {items && items.map((it: TreeItem<T>, idx: number) =>
-                <div key={`item/${level}/${idx}`}>
-                    <ListItem button className={list} style={{ paddingLeft: (level + 1) * 20 }} onClick={() => toggleItemActive(it.id, it.status)} onContextMenu={this.handleRowContextMenu(it)}>
-                        {it.status === TreeItemStatus.Pending ? <CircularProgress size={10} className={loader} /> : null}
-                        {it.toggled && it.items && it.items.length === 0 ? null : this.renderArrow(it.status, it.active ? activeArrow : inactiveArrow, it.open, it.id)}
-                        {render(it, level)}
-                    </ListItem>
-                    {it.items && it.items.length > 0 &&
+export const Tree = withStyles(styles)(
+    class Component<T> extends React.Component<TreeProps<T> & WithStyles<CssRules>, {}> {
+        render(): ReactElement<any> {
+            const level = this.props.level ? this.props.level : 0;
+            const { classes, render, toggleItemOpen, items, toggleItemActive, onContextMenu } = this.props;
+            const { list, inactiveArrow, activeArrow, loader } = classes;
+            return <List component="div" className={list}>
+                {items && items.map((it: TreeItem<T>, idx: number) =>
+                    <div key={`item/${level}/${idx}`}>
+                        <ListItem button className={list} style={{ paddingLeft: (level + 1) * 20 }}
+                                  onClick={() => toggleItemActive(it.id, it.status)}
+                                  onContextMenu={this.handleRowContextMenu(it)}>
+                            {it.status === TreeItemStatus.Pending ?
+                                <CircularProgress size={10} className={loader}/> : null}
+                            {it.toggled && it.items && it.items.length === 0 ? null : this.renderArrow(it.status, it.active ? activeArrow : inactiveArrow, it.open, it.id)}
+                            {render(it, level)}
+                        </ListItem>
+                        {it.items && it.items.length > 0 &&
                         <Collapse in={it.open} timeout="auto" unmountOnExit>
-                            <StyledTree
+                            <Tree
                                 items={it.items}
                                 render={render}
                                 toggleItemOpen={toggleItemOpen}
                                 toggleItemActive={toggleItemActive}
                                 level={level + 1}
-                                onContextMenu={onContextMenu} />
+                                onContextMenu={onContextMenu}/>
                         </Collapse>}
-                </div>)}
-        </List>;
-    }
-    renderArrow(status: TreeItemStatus, arrowClass: string, open: boolean, id: string) {
-        const { arrowTransition, arrowVisibility, arrowRotate } = this.props.classes;
-        return <i onClick={() => this.props.toggleItemOpen(id, status)}
-            className={`
-                    ${arrowClass} 
-                    ${status === TreeItemStatus.Pending ? arrowVisibility : ''} 
-                    ${open ? `fas fa-caret-down ${arrowTransition}` : `fas fa-caret-down ${arrowRotate}`}`} />;
-    }
-
-    handleRowContextMenu = (item: TreeItem<T>) =>
-        (event: React.MouseEvent<HTMLElement>) =>
-            this.props.onContextMenu(event, item)
-}
+                    </div>)}
+            </List>;
+        }
 
-type CssRules = 'list' | 'activeArrow' | 'inactiveArrow' | 'arrowRotate' | 'arrowTransition' | 'loader' | 'arrowVisibility';
+        renderArrow(status: TreeItemStatus, arrowClass: string, open: boolean, id: string) {
+            const { arrowTransition, arrowVisibility, arrowRotate } = this.props.classes;
+            return <i onClick={() => this.props.toggleItemOpen(id, status)}
+                      className={`
+                        ${arrowClass}
+                        ${status === TreeItemStatus.Pending ? arrowVisibility : ''}
+                        ${open ? `fas fa-caret-down ${arrowTransition}` : `fas fa-caret-down ${arrowRotate}`}`}/>;
+        }
 
-const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
-    list: {
-        paddingBottom: '3px',
-        paddingTop: '3px',
-    },
-    activeArrow: {
-        color: '#4285F6',
-        position: 'absolute',
-    },
-    inactiveArrow: {
-        position: 'absolute',
-    },
-    arrowTransition: {
-        transition: 'all 0.1s ease',
-    },
-    arrowRotate: {
-        transition: 'all 0.1s ease',
-        transform: 'rotate(-90deg)',
-    },
-    arrowVisibility: {
-        opacity: 0,
-    },
-    loader: {
-        position: 'absolute',
-        transform: 'translate(0px)',
-        top: '3px'
+        handleRowContextMenu = (item: TreeItem<T>) =>
+            (event: React.MouseEvent<HTMLElement>) =>
+                this.props.onContextMenu(event, item)
     }
-});
-
-const StyledTree = withStyles(styles)(Tree);
-export default StyledTree;
+);
