X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/d116e491ef904d97dcece5ab1632bef08906ec87..7cac459611f4e4d089cedbe13120553f97152509:/src/views/workbench/workbench.tsx

diff --git a/src/views/workbench/workbench.tsx b/src/views/workbench/workbench.tsx
index ea8fce80..257c7c4f 100644
--- a/src/views/workbench/workbench.tsx
+++ b/src/views/workbench/workbench.tsx
@@ -3,7 +3,7 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import * as React from 'react';
-import { StyleRulesCallback, Theme, WithStyles, withStyles } from '@material-ui/core/styles';
+import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core/styles';
 import Drawer from '@material-ui/core/Drawer';
 import { connect, DispatchProp } from "react-redux";
 import { Route, Switch, RouteComponentProps, withRouter } from "react-router";
@@ -28,13 +28,17 @@ import { ItemMode, setProjectItem } from "../../store/navigation/navigation-acti
 import projectActions from "../../store/project/project-action";
 import ProjectPanel from "../project-panel/project-panel";
 import { sidePanelData } from '../../store/side-panel/side-panel-reducer';
+import DetailsPanel from '../../views-components/details-panel/details-panel';
+import { ArvadosTheme } from '../../common/custom-theme';
+import ContextMenu from '../../components/context-menu/context-menu';
+import { mockAnchorFromMouseEvent } from '../../components/popover/helpers';
 
 const drawerWidth = 240;
-const appBarHeight = 102;
+const appBarHeight = 100;
 
 type CssRules = 'root' | 'appBar' | 'drawerPaper' | 'content' | 'contentWrapper' | 'toolbar';
 
-const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
+const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
     root: {
         flexGrow: 1,
         zIndex: 1,
@@ -46,7 +50,6 @@ const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
     },
     appBar: {
         zIndex: theme.zIndex.drawer + 1,
-        backgroundColor: '#692498',
         position: "absolute",
         width: "100%"
     },
@@ -64,7 +67,7 @@ const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
         paddingTop: appBarHeight
     },
     content: {
-        padding: theme.spacing.unit * 3,
+        padding: `${theme.spacing.unit}px ${theme.spacing.unit * 3}px`,
         overflowY: "auto",
         flexGrow: 1
     },
@@ -92,6 +95,9 @@ interface NavMenuItem extends MainAppBarMenuItem {
 }
 
 interface WorkbenchState {
+    contextMenu: {
+        anchorEl?: HTMLElement;
+    };
     isCreationDialogOpen: boolean;
     anchorEl: any;
     searchText: string;
@@ -100,10 +106,14 @@ interface WorkbenchState {
         helpMenu: NavMenuItem[],
         anonymousMenu: NavMenuItem[]
     };
+    isDetailsPanelOpened: boolean;
 }
 
 class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
     state = {
+        contextMenu: {
+            anchorEl: undefined
+        },
         isCreationDialogOpen: false,
         anchorEl: null,
         searchText: "",
@@ -131,7 +141,8 @@ class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
                     action: () => this.props.dispatch(authActions.LOGIN())
                 }
             ]
-        }
+        },
+        isDetailsPanelOpened: false
     };
 
     mainAppBarActions: MainAppBarActionProps = {
@@ -142,7 +153,10 @@ class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
             this.setState({ searchText });
             this.props.dispatch(push(`/search?q=${searchText}`));
         },
-        onMenuItemClick: (menuItem: NavMenuItem) => menuItem.action()
+        onMenuItemClick: (menuItem: NavMenuItem) => menuItem.action(),
+        onDetailsPanelToggle: () => {
+            this.setState(prev => ({ isDetailsPanelOpened: !prev.isDetailsPanelOpened }));
+        }
     };
 
     toggleSidePanelOpen = (itemId: string) => {
@@ -162,6 +176,16 @@ class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
         this.setState({ isCreationDialogOpen: false });
     }
 
+    openContextMenu = (event: React.MouseEvent<HTMLElement>, item: any) => {
+        event.preventDefault();
+        this.setState({ contextMenu: { anchorEl: mockAnchorFromMouseEvent(event) } });
+        console.log(item);
+    }
+
+    closeContextMenu = () => {
+        this.setState({ contextMenu: {} });
+    }
+
     render() {
         const path = getTreePath(this.props.projects, this.props.currentProjectId);
         const breadcrumbs = path.map(item => ({
@@ -193,15 +217,12 @@ class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
                             toggleOpen={this.toggleSidePanelOpen}
                             toggleActive={this.toggleSidePanelActive}
                             sidePanelItems={this.props.sidePanelItems}
-                            handleCreationDialogOpen={this.handleCreationDialogOpen}
-                            handleCreationDialogClose={this.handleCreationDialogClose}>
+                            onContextMenu={this.openContextMenu}>
                             <ProjectTree
                                 projects={this.props.projects}
                                 toggleOpen={itemId => this.props.dispatch<any>(setProjectItem(itemId, ItemMode.OPEN))}
                                 toggleActive={itemId => this.props.dispatch<any>(setProjectItem(itemId, ItemMode.ACTIVE))}
-                                handleCreationDialogOpen={this.handleCreationDialogOpen}
-                                handleCreationDialogClose={this.handleCreationDialogClose}
-                            />
+                                onContextMenu={this.openContextMenu} />
                         </SidePanel>
                     </Drawer>}
                 <main className={classes.contentWrapper}>
@@ -210,7 +231,15 @@ class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
                             <Route path="/projects/:id" render={this.renderProjectPanel} />
                         </Switch>
                     </div>
+                    <DetailsPanel
+                        isOpened={this.state.isDetailsPanelOpened}
+                        onCloseDrawer={this.mainAppBarActions.onDetailsPanelToggle} />
                 </main>
+                <ContextMenu
+                    anchorEl={this.state.contextMenu.anchorEl}
+                    actions={contextMenuActions}
+                    onActionClick={console.log}
+                    onClose={this.closeContextMenu} />
             </div>
         );
     }
@@ -218,12 +247,40 @@ class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
     renderProjectPanel = (props: RouteComponentProps<{ id: string }>) => <ProjectPanel
         onItemRouteChange={itemId => this.props.dispatch<any>(setProjectItem(itemId, ItemMode.ACTIVE))}
         onItemClick={item => this.props.dispatch<any>(setProjectItem(item.uuid, ItemMode.ACTIVE))}
+        onContextMenu={this.openContextMenu}
         handleCreationDialogOpen={this.handleCreationDialogOpen}
         handleCreationDialogClose={this.handleCreationDialogClose}
         isCreationDialogOpen={this.state.isCreationDialogOpen}
         {...props} />
-    
+
+}
+
+const contextMenuActions = [[{
+    icon: "fas fa-plus fa-fw",
+    name: "New project"
+}, {
+    icon: "fas fa-users fa-fw",
+    name: "Share"
+}, {
+    icon: "fas fa-sign-out-alt fa-fw",
+    name: "Move to"
+}, {
+    icon: "fas fa-star fa-fw",
+    name: "Add to favourite"
+}, {
+    icon: "fas fa-edit fa-fw",
+    name: "Rename"
+}, {
+    icon: "fas fa-copy fa-fw",
+    name: "Make a copy"
+}, {
+    icon: "fas fa-download fa-fw",
+    name: "Download"
+}], [{
+    icon: "fas fa-trash-alt fa-fw",
+    name: "Remove"
 }
+]];
 
 export default connect<WorkbenchDataProps>(
     (state: RootState) => ({
