Move context menu to workbench component
[arvados-workbench2.git] / src / views / workbench / workbench.tsx
index 8cc5fc22700571a207395746390d8e778ad4e1f8..57f0898977cbf6177fa4dda62fbbdf579145f16e 100644 (file)
@@ -30,6 +30,8 @@ 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 = 100;
@@ -93,6 +95,10 @@ interface NavMenuItem extends MainAppBarMenuItem {
 }
 
 interface WorkbenchState {
+    contextMenu: {
+        anchorEl?: HTMLElement;
+    };
+    isCreationDialogOpen: boolean;
     anchorEl: any;
     searchText: string;
     menuItems: {
@@ -105,6 +111,10 @@ interface WorkbenchState {
 
 class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
     state = {
+        contextMenu: {
+            anchorEl: undefined
+        },
+        isCreationDialogOpen: false,
         anchorEl: null,
         searchText: "",
         breadcrumbs: [],
@@ -158,6 +168,24 @@ class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
         this.props.dispatch(projectActions.RESET_PROJECT_TREE_ACTIVITY(itemId));
     }
 
+    handleCreationDialogOpen = () => {
+        this.setState({ isCreationDialogOpen: true });
+    }
+
+    handleCreationDialogClose = () => {
+        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 => ({
@@ -188,11 +216,15 @@ class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
                         <SidePanel
                             toggleOpen={this.toggleSidePanelOpen}
                             toggleActive={this.toggleSidePanelActive}
-                            sidePanelItems={this.props.sidePanelItems}>
+                            sidePanelItems={this.props.sidePanelItems}
+                            handleCreationDialogOpen={this.handleCreationDialogOpen}
+                            handleCreationDialogClose={this.handleCreationDialogClose}>
                             <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}
                             />
                         </SidePanel>
                     </Drawer>}
@@ -202,10 +234,15 @@ class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
                             <Route path="/projects/:id" render={this.renderProjectPanel} />
                         </Switch>
                     </div>
-                    <DetailsPanel 
-                        isOpened={this.state.isDetailsPanelOpened} 
+                    <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>
         );
     }
@@ -213,10 +250,41 @@ 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) => ({
         projects: state.projects.items,