small refactor
authorPawel Kowalczyk <pawel.kowalczyk@contractors.roche.com>
Thu, 12 Jul 2018 11:49:40 +0000 (13:49 +0200)
committerPawel Kowalczyk <pawel.kowalczyk@contractors.roche.com>
Thu, 12 Jul 2018 11:49:40 +0000 (13:49 +0200)
Feature #13796

Arvados-DCO-1.1-Signed-off-by: Pawel Kowalczyk <pawel.kowalczyk@contractors.roche.com>

src/views/project-panel/project-panel.tsx
src/views/workbench/workbench.tsx

index 0b1be099d0a7aba336d8d142d6b8b05e0e1695cc..0c9be912b02bc6b54982b2d8f25e911666dd4ba8 100644 (file)
@@ -34,31 +34,32 @@ type ProjectPanelProps = {
     & WithStyles<CssRules>
     & RouteComponentProps<{ id: string }>;
 
-class ProjectPanel extends React.Component<ProjectPanelProps> {    
+class ProjectPanel extends React.Component<ProjectPanelProps> {
     render() {
+        const { classes, currentItemId, onItemClick, onItemDoubleClick, onContextMenu, onDialogOpen } = this.props;
         return <div>
-            <div className={this.props.classes.toolbar}>
-                <Button color="primary" variant="raised" className={this.props.classes.button}>
+            <div className={classes.toolbar}>
+                <Button color="primary" variant="raised" className={classes.button}>
                     Create a collection
                 </Button>
-                <Button color="primary" variant="raised" className={this.props.classes.button}>
+                <Button color="primary" variant="raised" className={classes.button}>
                     Run a process
                 </Button>
-                <Button color="primary" onClick={() => this.props.onDialogOpen(this.props.currentItemId)} variant="raised" className={this.props.classes.button}>
+                <Button color="primary" onClick={() => onDialogOpen(currentItemId)} variant="raised" className={classes.button}>
                     New project
                 </Button>
             </div>
             <DataExplorer
                 id={PROJECT_PANEL_ID}
-                onRowClick={this.props.onItemClick}
-                onRowDoubleClick={this.props.onItemDoubleClick}
-                onContextMenu={this.props.onContextMenu} />
+                onRowClick={onItemClick}
+                onRowDoubleClick={onItemDoubleClick}
+                onContextMenu={onContextMenu} />
         </div>;
     }
 
-    componentWillReceiveProps({ match, currentItemId }: ProjectPanelProps) {
+    componentWillReceiveProps({ match, currentItemId, onItemRouteChange }: ProjectPanelProps) {
         if (match.params.id !== currentItemId) {
-            this.props.onItemRouteChange(match.params.id);
+            onItemRouteChange(match.params.id);
         }
     }
 }
index 6ad4d247456c9d995b3a44562e5defd765756e14..e8f5aed78dfff23324cbd43f22fafd22dba22128 100644 (file)
@@ -35,47 +35,6 @@ import { authService } from '../../services/services';
 import detailsPanelActions, { loadDetails } from "../../store/details-panel/details-panel-action";
 import { ResourceKind } from '../../models/kinds';
 
-const drawerWidth = 240;
-const appBarHeight = 100;
-
-type CssRules = 'root' | 'appBar' | 'drawerPaper' | 'content' | 'contentWrapper' | 'toolbar';
-
-const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
-    root: {
-        flexGrow: 1,
-        zIndex: 1,
-        overflow: 'hidden',
-        position: 'relative',
-        display: 'flex',
-        width: '100vw',
-        height: '100vh'
-    },
-    appBar: {
-        zIndex: theme.zIndex.drawer + 1,
-        position: "absolute",
-        width: "100%"
-    },
-    drawerPaper: {
-        position: 'relative',
-        width: drawerWidth,
-        display: 'flex',
-        flexDirection: 'column',
-    },
-    contentWrapper: {
-        backgroundColor: theme.palette.background.default,
-        display: "flex",
-        flexGrow: 1,
-        minWidth: 0,
-        paddingTop: appBarHeight
-    },
-    content: {
-        padding: `${theme.spacing.unit}px ${theme.spacing.unit * 3}px`,
-        overflowY: "auto",
-        flexGrow: 1
-    },
-    toolbar: theme.mixins.toolbar
-});
-
 interface WorkbenchDataProps {
     projects: Array<TreeItem<Project>>;
     currentProjectId: string;
@@ -147,60 +106,6 @@ class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
         }
     };
 
-    mainAppBarActions: MainAppBarActionProps = {
-        onBreadcrumbClick: ({ itemId }: NavBreadcrumb) => {
-            this.props.dispatch<any>(setProjectItem(itemId, ItemMode.BOTH));
-            this.props.dispatch<any>(loadDetails(itemId, ResourceKind.Project));
-        },
-        onSearch: searchText => {
-            this.setState({ searchText });
-            this.props.dispatch(push(`/search?q=${searchText}`));
-        },
-        onMenuItemClick: (menuItem: NavMenuItem) => menuItem.action(),
-        onDetailsPanelToggle: () => {
-            this.props.dispatch(detailsPanelActions.TOGGLE_DETAILS_PANEL());
-        },
-        onContextMenu: (event: React.MouseEvent<HTMLElement>, breadcrumb: NavBreadcrumb) => {
-            this.openContextMenu(event, breadcrumb.itemId);
-        }
-    };
-
-    toggleSidePanelOpen = (itemId: string) => {
-        this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_OPEN(itemId));
-    }
-
-    toggleSidePanelActive = (itemId: string) => {
-        this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_ACTIVE(itemId));
-        this.props.dispatch(projectActions.RESET_PROJECT_TREE_ACTIVITY(itemId));
-    }
-
-    handleCreationDialogOpen = (itemUuid: string) => {
-        this.closeContextMenu();
-        this.props.dispatch(projectActions.OPEN_PROJECT_CREATOR({ ownerUuid: itemUuid }));
-    }
-
-
-    openContextMenu = (event: React.MouseEvent<HTMLElement>, itemUuid: string) => {
-        event.preventDefault();
-        this.setState({
-            contextMenu: {
-                anchorEl: mockAnchorFromMouseEvent(event),
-                itemUuid
-            }
-        });
-    }
-
-    closeContextMenu = () => {
-        this.setState({ contextMenu: {} });
-    }
-
-    openCreateDialog = (item: ContextMenuAction) => {
-        const { itemUuid } = this.state.contextMenu;
-        if (item.openCreateDialog && itemUuid) {
-            this.handleCreationDialogOpen(itemUuid);
-        }
-    }
-
     render() {
         const path = getTreePath(this.props.projects, this.props.currentProjectId);
         const breadcrumbs = path.map(item => ({
@@ -272,6 +177,60 @@ class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
             this.props.dispatch<any>(loadDetails(item.uuid, ResourceKind.Project));
         }}
         {...props} />
+
+        mainAppBarActions: MainAppBarActionProps = {
+            onBreadcrumbClick: ({ itemId }: NavBreadcrumb) => {
+                this.props.dispatch<any>(setProjectItem(itemId, ItemMode.BOTH));
+                this.props.dispatch<any>(loadDetails(itemId, ResourceKind.Project));
+            },
+            onSearch: searchText => {
+                this.setState({ searchText });
+                this.props.dispatch(push(`/search?q=${searchText}`));
+            },
+            onMenuItemClick: (menuItem: NavMenuItem) => menuItem.action(),
+            onDetailsPanelToggle: () => {
+                this.props.dispatch(detailsPanelActions.TOGGLE_DETAILS_PANEL());
+            },
+            onContextMenu: (event: React.MouseEvent<HTMLElement>, breadcrumb: NavBreadcrumb) => {
+                this.openContextMenu(event, breadcrumb.itemId);
+            }
+        };
+    
+        toggleSidePanelOpen = (itemId: string) => {
+            this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_OPEN(itemId));
+        }
+    
+        toggleSidePanelActive = (itemId: string) => {
+            this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_ACTIVE(itemId));
+            this.props.dispatch(projectActions.RESET_PROJECT_TREE_ACTIVITY(itemId));
+        }
+    
+        handleCreationDialogOpen = (itemUuid: string) => {
+            this.closeContextMenu();
+            this.props.dispatch(projectActions.OPEN_PROJECT_CREATOR({ ownerUuid: itemUuid }));
+        }
+    
+    
+        openContextMenu = (event: React.MouseEvent<HTMLElement>, itemUuid: string) => {
+            event.preventDefault();
+            this.setState({
+                contextMenu: {
+                    anchorEl: mockAnchorFromMouseEvent(event),
+                    itemUuid
+                }
+            });
+        }
+    
+        closeContextMenu = () => {
+            this.setState({ contextMenu: {} });
+        }
+    
+        openCreateDialog = (item: ContextMenuAction) => {
+            const { itemUuid } = this.state.contextMenu;
+            if (item.openCreateDialog && itemUuid) {
+                this.handleCreationDialogOpen(itemUuid);
+            }
+        }
 }
 
 const contextMenuActions = [[{
@@ -302,6 +261,47 @@ const contextMenuActions = [[{
 }
 ]];
 
+const drawerWidth = 240;
+const appBarHeight = 100;
+
+type CssRules = 'root' | 'appBar' | 'drawerPaper' | 'content' | 'contentWrapper' | 'toolbar';
+
+const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
+    root: {
+        flexGrow: 1,
+        zIndex: 1,
+        overflow: 'hidden',
+        position: 'relative',
+        display: 'flex',
+        width: '100vw',
+        height: '100vh'
+    },
+    appBar: {
+        zIndex: theme.zIndex.drawer + 1,
+        position: "absolute",
+        width: "100%"
+    },
+    drawerPaper: {
+        position: 'relative',
+        width: drawerWidth,
+        display: 'flex',
+        flexDirection: 'column',
+    },
+    contentWrapper: {
+        backgroundColor: theme.palette.background.default,
+        display: "flex",
+        flexGrow: 1,
+        minWidth: 0,
+        paddingTop: appBarHeight
+    },
+    content: {
+        padding: `${theme.spacing.unit}px ${theme.spacing.unit * 3}px`,
+        overflowY: "auto",
+        flexGrow: 1
+    },
+    toolbar: theme.mixins.toolbar
+});
+
 export default connect<WorkbenchDataProps>(
     (state: RootState) => ({
         projects: state.projects.items,