1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
6 import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core/styles';
7 import Drawer from '@material-ui/core/Drawer';
8 import { connect } from "react-redux";
9 import { ProjectTree } from '~/views-components/project-tree/project-tree';
10 import { SidePanel, SidePanelItem } from '~/components/side-panel/side-panel';
11 import { ArvadosTheme } from '~/common/custom-theme';
12 import { RootState } from '~/store/store';
13 import { TreeItem } from '~/components/tree/tree';
14 import { ProjectResource } from '~/models/project';
15 import { sidePanelActions } from '../../store/side-panel/side-panel-action';
16 import { Dispatch } from 'redux';
17 import { projectActions } from '~/store/project/project-action';
18 import { navigateToResource } from '../../store/navigation/navigation-action';
19 import { openContextMenu } from '~/store/context-menu/context-menu-actions';
20 import { ContextMenuKind } from '~/views-components/context-menu/context-menu';
23 const DRAWER_WITDH = 240;
25 type CssRules = 'drawerPaper' | 'toolbar';
27 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
32 flexDirection: 'column',
34 toolbar: theme.mixins.toolbar
37 interface NavigationPanelDataProps {
38 projects: Array<TreeItem<ProjectResource>>;
39 sidePanelItems: SidePanelItem[];
42 interface NavigationPanelActionProps {
43 toggleSidePanelOpen: (panelItemId: string) => void;
44 toggleSidePanelActive: (panelItemId: string) => void;
45 toggleProjectOpen: (projectUuid: string) => void;
46 toggleProjectActive: (projectUuid: string) => void;
47 openRootContextMenu: (event: React.MouseEvent<any>) => void;
48 openProjectContextMenu: (event: React.MouseEvent<any>, item: TreeItem<ProjectResource>) => void;
51 type NavigationPanelProps = NavigationPanelDataProps & NavigationPanelActionProps & WithStyles<CssRules>;
53 const mapStateToProps = (state: RootState): NavigationPanelDataProps => ({
54 projects: state.projects.items,
55 sidePanelItems: state.sidePanel
58 const mapDispatchToProps = (dispatch: Dispatch): NavigationPanelActionProps => ({
59 toggleSidePanelOpen: panelItemId => {
60 dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_OPEN(panelItemId));
62 toggleSidePanelActive: panelItemId => {
63 dispatch(projectActions.RESET_PROJECT_TREE_ACTIVITY(panelItemId));
65 // const panelItem = this.props.sidePanelItems.find(it => it.id === itemId);
66 // if (panelItem && panelItem.activeAction) {
67 // panelItem.activeAction(this.props.dispatch, this.props.authService.getUuid());
70 toggleProjectOpen: projectUuid => {
71 dispatch<any>(navigateToResource(projectUuid));
73 toggleProjectActive: projectUuid => {
74 dispatch<any>(navigateToResource(projectUuid));
76 openRootContextMenu: event => {
77 dispatch<any>(openContextMenu(event, {
80 kind: ContextMenuKind.ROOT_PROJECT
83 openProjectContextMenu: (event, item) => {
84 dispatch<any>(openContextMenu(event, {
87 kind: ContextMenuKind.PROJECT
92 export const NavigationPanel = withStyles(styles)(
93 connect(mapStateToProps, mapDispatchToProps)(
94 ({ classes, sidePanelItems, projects, ...actions }: NavigationPanelProps) => <Drawer
96 classes={{ paper: classes.drawerPaper }}>
97 <div className={classes.toolbar} />
99 toggleOpen={actions.toggleSidePanelOpen}
100 toggleActive={actions.toggleSidePanelOpen}
101 sidePanelItems={sidePanelItems}
102 onContextMenu={actions.openRootContextMenu}>
105 toggleOpen={actions.toggleProjectOpen}
106 onContextMenu={actions.openProjectContextMenu}
107 toggleActive={actions.toggleProjectActive} />