Connect project explorer to the store
[arvados-workbench2.git] / src / views / workbench / workbench.tsx
index 20e3648e0561151c8d63fd57ef04858206f5d914..6a8698fd7f9e5c2a86b2c182512d7dd992e9533d 100644 (file)
@@ -9,21 +9,25 @@ import Drawer from '@material-ui/core/Drawer';
 import { connect, DispatchProp } from "react-redux";
 import { Route, Switch } from "react-router";
 import authActions from "../../store/auth/auth-action";
+import dataExplorerActions from "../../store/data-explorer/data-explorer-action";
 import { User } from "../../models/user";
 import { RootState } from "../../store/store";
-import MainAppBar, { MainAppBarActionProps, MainAppBarMenuItem } from '../../components/main-app-bar/main-app-bar';
+import MainAppBar, { MainAppBarActionProps, MainAppBarMenuItem } from '../../views-components/main-app-bar/main-app-bar';
 import { Breadcrumb } from '../../components/breadcrumbs/breadcrumbs';
 import { push } from 'react-router-redux';
-import projectActions from "../../store/project/project-action";
-import ProjectTree from '../../components/project-tree/project-tree';
+import projectActions, { getProjectList } from "../../store/project/project-action";
+import ProjectTree from '../../views-components/project-tree/project-tree';
 import { TreeItem, TreeItemStatus } from "../../components/tree/tree";
 import { Project } from "../../models/project";
-import { projectService } from '../../services/services';
-import DataExplorer from '../data-explorer/data-explorer';
+import { getTreePath, findTreeItem } from '../../store/project/project-reducer';
+import ProjectPanel from '../project-panel/project-panel';
+import { PROJECT_EXPLORER_ID } from '../../views-components/project-explorer/project-explorer';
+import { ProjectExplorerItem } from '../../views-components/project-explorer/project-explorer-item';
 
 const drawerWidth = 240;
+const appBarHeight = 102;
 
-type CssRules = 'root' | 'appBar' | 'drawerPaper' | 'content' | 'toolbar';
+type CssRules = 'root' | 'appBar' | 'drawerPaper' | 'content' | 'contentWrapper' | 'toolbar';
 
 const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
     root: {
@@ -45,12 +49,17 @@ const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
         position: 'relative',
         width: drawerWidth,
     },
-    content: {
-        flexGrow: 1,
+    contentWrapper: {
         backgroundColor: theme.palette.background.default,
-        padding: theme.spacing.unit * 3,
-        height: '100%',
+        display: "flex",
+        flexGrow: 1,
         minWidth: 0,
+        paddingTop: appBarHeight
+    },
+    content: {
+        padding: theme.spacing.unit * 3,
+        overflowY: "auto",
+        flexGrow: 1
     },
     toolbar: theme.mixins.toolbar
 });
@@ -66,7 +75,8 @@ interface WorkbenchActionProps {
 type WorkbenchProps = WorkbenchDataProps & WorkbenchActionProps & DispatchProp & WithStyles<CssRules>;
 
 interface NavBreadcrumb extends Breadcrumb {
-    path: string;
+    itemId: string;
+    status: TreeItemStatus;
 }
 
 interface NavMenuItem extends MainAppBarMenuItem {
@@ -88,15 +98,7 @@ class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
     state = {
         anchorEl: null,
         searchText: "",
-        breadcrumbs: [
-            {
-                label: "Projects",
-                path: "/projects"
-            }, {
-                label: "Project 1",
-                path: "/projects/project-1"
-            }
-        ],
+        breadcrumbs: [],
         menuItems: {
             accountMenu: [
                 {
@@ -125,7 +127,9 @@ class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
 
 
     mainAppBarActions: MainAppBarActionProps = {
-        onBreadcrumbClick: (breadcrumb: NavBreadcrumb) => this.props.dispatch(push(breadcrumb.path)),
+        onBreadcrumbClick: ({ itemId, status }: NavBreadcrumb) => {
+            this.toggleProjectTreeItem(itemId, status);
+        },
         onSearch: searchText => {
             this.setState({ searchText });
             this.props.dispatch(push(`/search?q=${searchText}`));
@@ -137,13 +141,34 @@ class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
         if (status === TreeItemStatus.Loaded) {
             this.openProjectItem(itemId);
         } else {
-            this.props.dispatch<any>(projectService.getProjectList(itemId)).then(() => this.openProjectItem(itemId));
+            this.props.dispatch<any>(getProjectList(itemId))
+                .then(() => this.openProjectItem(itemId));
         }
     }
 
     openProjectItem = (itemId: string) => {
+        const branch = getTreePath(this.props.projects, itemId);
+        this.setState({
+            breadcrumbs: branch.map(item => ({
+                label: item.data.name,
+                itemId: item.data.uuid,
+                status: item.status
+            }))
+        });
         this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM(itemId));
         this.props.dispatch(push(`/project/${itemId}`));
+
+        const project = findTreeItem(this.props.projects, itemId);
+        const items: ProjectExplorerItem[] = project && project.items
+            ? project.items.map(({ data }) => ({
+                uuid: data.uuid,
+                name: data.name,
+                type: data.kind,
+                owner: data.ownerUuid,
+                lastModified: data.modifiedAt
+            }))
+            : [];
+        this.props.dispatch(dataExplorerActions.SET_ITEMS({ id: PROJECT_EXPLORER_ID, items }));
     }
 
     render() {
@@ -170,11 +195,12 @@ class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
                             projects={this.props.projects}
                             toggleProjectTreeItem={this.toggleProjectTreeItem} />
                     </Drawer>}
-                <main className={classes.content}>
-                    <div className={classes.toolbar} />
-                    <Switch>
-                        <Route path="/project/:name" component={DataExplorer} />
-                    </Switch>
+                <main className={classes.contentWrapper}>
+                    <div className={classes.content}>
+                        <Switch>
+                            <Route path="/project/:name" component={ProjectPanel} />
+                        </Switch>
+                    </div>
                 </main>
             </div>
         );