X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/6577b5404eef1061fc3f2fb1cfdc1775bd752132..10ce16c28de952f6533ca3cc9df909269e3d2a53:/src/components/tree/tree.tsx

diff --git a/src/components/tree/tree.tsx b/src/components/tree/tree.tsx
index 16f3ab2ce3..e4d8c72ce6 100644
--- a/src/components/tree/tree.tsx
+++ b/src/components/tree/tree.tsx
@@ -11,6 +11,38 @@ 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,
     Pending,
@@ -36,78 +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>;
-    }
+                    </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}`}`} />;
-    }
+        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)
-}
-
-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'
+        handleRowContextMenu = (item: TreeItem<T>) =>
+            (event: React.MouseEvent<HTMLElement>) =>
+                this.props.onContextMenu(event, item)
     }
-});
-
-const StyledTree = withStyles(styles)(Tree);
-export default StyledTree;
+);
