[ARVADOS-WORKBENCH2] updated: 1.1.4-437-g42de130

Git user git at public.curoverse.com
Fri Jul 27 05:30:48 EDT 2018


Summary of changes:
 src/components/tree/tree.test.tsx | 48 ++++++++++++++++++++++++++++++++++
 src/components/tree/tree.tsx      | 54 ++++++++++++++++++++++++++++++++++-----
 2 files changed, 96 insertions(+), 6 deletions(-)

       via  42de1303354a30d004095003d6143deaa3f62992 (commit)
      from  750ece46ef69eec338523c63c834cd87901c1342 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 42de1303354a30d004095003d6143deaa3f62992
Author: Michal Klobukowski <michal.klobukowski at contractors.roche.com>
Date:   Fri Jul 27 11:30:25 2018 +0200

    Extends tree component with checkboxes
    
    Feature #13855
    
    Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski <michal.klobukowski at contractors.roche.com>

diff --git a/src/components/tree/tree.test.tsx b/src/components/tree/tree.test.tsx
index 58484c3..3018a49 100644
--- a/src/components/tree/tree.test.tsx
+++ b/src/components/tree/tree.test.tsx
@@ -10,6 +10,7 @@ import ListItem from "@material-ui/core/ListItem/ListItem";
 import { Tree, TreeItem } from './tree';
 import { ProjectResource } from '../../models/project';
 import { mockProjectResource } from '../../models/test-utils';
+import { Checkbox } from '../../../node_modules/@material-ui/core';
 
 Enzyme.configure({ adapter: new Adapter() });
 
@@ -48,4 +49,51 @@ describe("Tree component", () => {
             items={[project]} />);
         expect(wrapper.find('i')).toHaveLength(1);
     });
+
+    it("should render checkbox", () => {
+        const project: TreeItem<ProjectResource> = {
+            data: mockProjectResource(),
+            id: "3",
+            open: true,
+            active: true,
+            status: 1,
+        };
+        const wrapper = mount(<Tree
+            showSelection={true}
+            render={() => <div />}
+            toggleItemOpen={jest.fn()}
+            toggleItemActive={jest.fn()}
+            onContextMenu={jest.fn()}
+            items={[project]} />);
+        expect(wrapper.find(Checkbox)).toHaveLength(1);
+    });
+
+    it("call onSelectionChanged with associated item", () => {
+        const project: TreeItem<ProjectResource> = {
+            data: mockProjectResource(),
+            id: "3",
+            open: true,
+            active: true,
+            status: 1,
+        };
+        const spy = jest.fn();
+        const onSelectionChanged = (event: any, item: TreeItem<any>) => spy(item);
+        const wrapper = mount(<Tree
+            showSelection={true}
+            render={() => <div />}
+            toggleItemOpen={jest.fn()}
+            toggleItemActive={jest.fn()}
+            onContextMenu={jest.fn()}
+            onSelectionChange={onSelectionChanged}
+            items={[project]} />);
+        wrapper.find(Checkbox).prop('onChange')();
+        expect(spy).toHaveBeenLastCalledWith({
+            data: mockProjectResource(),
+            id: "3",
+            open: true,
+            active: true,
+            status: 1,
+        });
+    });
+
 });
diff --git a/src/components/tree/tree.tsx b/src/components/tree/tree.tsx
index 2052600..f16348c 100644
--- a/src/components/tree/tree.tsx
+++ b/src/components/tree/tree.tsx
@@ -3,7 +3,7 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import * as React from 'react';
-import { List, ListItem, ListItemIcon, Collapse } from "@material-ui/core";
+import { List, ListItem, ListItemIcon, Collapse, Checkbox } from "@material-ui/core";
 import { StyleRulesCallback, withStyles, WithStyles } from '@material-ui/core/styles';
 import { ReactElement } from "react";
 import CircularProgress from '@material-ui/core/CircularProgress';
@@ -12,12 +12,24 @@ import * as classnames from "classnames";
 import { ArvadosTheme } from '../../common/custom-theme';
 import { SidePanelRightArrowIcon } from '../icon/icon';
 
-type CssRules = 'list' | 'active' | 'loader' | 'toggableIconContainer' | 'iconClose' | 'iconOpen' | 'toggableIcon';
+type CssRules = 'list'
+    | 'listItem'
+    | 'active'
+    | 'loader'
+    | 'toggableIconContainer'
+    | 'iconClose'
+    | 'renderContainer'
+    | 'iconOpen'
+    | 'toggableIcon'
+    | 'checkbox';
 
 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
     list: {
         padding: '3px 0px'
     },
+    listItem: {
+        padding: '3px 0px',
+    },
     loader: {
         position: 'absolute',
         transform: 'translate(0px)',
@@ -26,11 +38,14 @@ const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
     toggableIconContainer: {
         color: theme.palette.grey["700"],
         height: '14px',
-        position: 'absolute'
+        width: '14px',
     },
     toggableIcon: {
         fontSize: '14px'
     },
+    renderContainer: {
+        flex: 1
+    },
     active: {
         color: theme.palette.primary.main,
     },
@@ -40,6 +55,12 @@ const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
     iconOpen: {
         transition: 'all 0.1s ease',
         transform: 'rotate(90deg)',
+    },
+    checkbox: {
+        width: theme.spacing.unit * 3,
+        height: theme.spacing.unit * 3,
+        margin: `0 ${theme.spacing.unit}px`,
+        color: theme.palette.grey["500"]
     }
 });
 
@@ -54,6 +75,7 @@ export interface TreeItem<T> {
     id: string;
     open: boolean;
     active: boolean;
+    selected?: boolean;
     status: TreeItemStatus;
     items?: Array<TreeItem<T>>;
 }
@@ -65,6 +87,8 @@ interface TreeProps<T> {
     toggleItemActive: (id: string, status: TreeItemStatus) => void;
     level?: number;
     onContextMenu: (event: React.MouseEvent<HTMLElement>, item: TreeItem<T>) => void;
+    showSelection?: boolean;
+    onSelectionChange?: (event: React.ChangeEvent<HTMLInputElement>, item: TreeItem<T>) => void;
 }
 
 export const Tree = withStyles(styles)(
@@ -72,11 +96,11 @@ export const Tree = withStyles(styles)(
         render(): ReactElement<any> {
             const level = this.props.level ? this.props.level : 0;
             const { classes, render, toggleItemOpen, items, toggleItemActive, onContextMenu } = this.props;
-            const { list, loader, toggableIconContainer } = classes;
+            const { list, listItem, loader, toggableIconContainer, renderContainer } = 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 }}
+                        <ListItem button className={listItem} style={{ paddingLeft: (level + 1) * 20 }}
                             onClick={() => toggleItemActive(it.id, it.status)}
                             onContextMenu={this.handleRowContextMenu(it)}>
                             {it.status === TreeItemStatus.PENDING ?
@@ -87,11 +111,20 @@ export const Tree = withStyles(styles)(
                                     {it.status !== TreeItemStatus.INITIAL && it.items && it.items.length === 0 ? <span /> : <SidePanelRightArrowIcon />}
                                 </ListItemIcon>
                             </i>
-                            {render(it, level)}
+                            {this.props.showSelection &&
+                                <Checkbox
+                                    checked={it.selected}
+                                    className={classes.checkbox}
+                                    color="primary"
+                                    onChange={this.handleCheckboxChange(it)} />}
+                            <div className={renderContainer}>
+                                {render(it, level)}
+                            </div>
                         </ListItem>
                         {it.items && it.items.length > 0 &&
                             <Collapse in={it.open} timeout="auto" unmountOnExit>
                                 <Tree
+                                    showSelection={this.props.showSelection}
                                     items={it.items}
                                     render={render}
                                     toggleItemOpen={toggleItemOpen}
@@ -115,5 +148,14 @@ export const Tree = withStyles(styles)(
         handleRowContextMenu = (item: TreeItem<T>) =>
             (event: React.MouseEvent<HTMLElement>) =>
                 this.props.onContextMenu(event, item)
+
+        handleCheckboxChange = (item: TreeItem<T>) => {
+            const { onSelectionChange } = this.props;
+            return onSelectionChange
+                ? (event: React.ChangeEvent<HTMLInputElement>, checked: boolean) => {
+                    onSelectionChange(event, item);
+                }
+                : undefined;
+        }
     }
 );

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list