Project-creation-on-button
[arvados.git] / src / views / project-panel / project-panel.tsx
index dd61e58a74a6c567a0fc423e72371f98aa46ca0b..3d7d89492c0a87e978f12d37d40b8ecc05985554 100644 (file)
@@ -12,17 +12,30 @@ import { DataTableFilterItem } from '../../components/data-table-filters/data-ta
 import { ContextMenuAction } from '../../components/context-menu/context-menu';
 import { DispatchProp, connect } from 'react-redux';
 import actions from "../../store/data-explorer/data-explorer-action";
-import { setProjectItem, ItemMode } from "../../store/navigation/navigation-action";
 import { DataColumns } from '../../components/data-table/data-table';
 import { ResourceKind } from "../../models/resource";
 import { RouteComponentProps } from 'react-router';
+import { RootState } from '../../store/store';
+import DialogProjectCreate from '../../components/dialog-create/dialog-project-create';
 
 export const PROJECT_PANEL_ID = "projectPanel";
 
-type ProjectPanelProps = { onItemClick: (item: ProjectPanelItem) => void }
+type ProjectPanelProps = {
+    currentItemId: string,
+    onItemClick: (item: ProjectPanelItem) => void,
+    onItemRouteChange: (itemId: string) => void,
+    handleCreationDialogOpen: () => void;
+    handleCreationDialogClose: () => void;
+    isCreationDialogOpen: boolean;
+}
     & DispatchProp
-    & WithStyles<CssRules>;
+    & WithStyles<CssRules>
+    & RouteComponentProps<{ id: string }>;
 class ProjectPanel extends React.Component<ProjectPanelProps> {
+    state = {
+        open: false,
+    };
+
     render() {
         return <div>
             <div className={this.props.classes.toolbar}>
@@ -32,9 +45,10 @@ class ProjectPanel extends React.Component<ProjectPanelProps> {
                 <Button color="primary" variant="raised" className={this.props.classes.button}>
                     Run a process
                 </Button>
-                <Button color="primary" variant="raised" className={this.props.classes.button}>
+                <Button color="primary" onClick={this.props.handleCreationDialogOpen} variant="raised" className={this.props.classes.button}>
                     Create a project
                 </Button>
+                <DialogProjectCreate open={this.props.isCreationDialogOpen} handleClose={this.props.handleCreationDialogClose}/>
             </div>
             <DataExplorer
                 id={PROJECT_PANEL_ID}
@@ -54,6 +68,12 @@ class ProjectPanel extends React.Component<ProjectPanelProps> {
         this.props.dispatch(actions.SET_COLUMNS({ id: PROJECT_PANEL_ID, columns }));
     }
 
+    componentWillReceiveProps({ match, currentItemId }: ProjectPanelProps) {
+        if (match.params.id !== currentItemId) {
+            this.props.onItemRouteChange(match.params.id);
+        }
+    }
+
     toggleColumn = (toggledColumn: DataColumn<ProjectPanelItem>) => {
         this.props.dispatch(actions.TOGGLE_COLUMN({ id: PROJECT_PANEL_ID, columnName: toggledColumn.name }));
     }
@@ -81,6 +101,7 @@ class ProjectPanel extends React.Component<ProjectPanelProps> {
     changeRowsPerPage = (rowsPerPage: number) => {
         this.props.dispatch(actions.SET_ROWS_PER_PAGE({ id: PROJECT_PANEL_ID, rowsPerPage }));
     }
+
 }
 
 type CssRules = "toolbar" | "button";
@@ -92,7 +113,7 @@ const styles: StyleRulesCallback<CssRules> = theme => ({
     },
     button: {
         marginLeft: theme.spacing.unit
-    }
+    },
 });
 
 const renderName = (item: ProjectPanelItem) =>
@@ -213,4 +234,6 @@ const contextMenuActions = [[{
 }
 ]];
 
-export default withStyles(styles)(connect()(ProjectPanel));
+export default withStyles(styles)(
+    connect((state: RootState) => ({ currentItemId: state.projects.currentItemId }))(
+        ProjectPanel));