Improve handling on of project url changes
authorMichal Klobukowski <michal.klobukowski@contractors.roche.com>
Sat, 30 Jun 2018 12:19:36 +0000 (14:19 +0200)
committerMichal Klobukowski <michal.klobukowski@contractors.roche.com>
Sat, 30 Jun 2018 12:19:36 +0000 (14:19 +0200)
Feature #13678

Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski <michal.klobukowski@contractors.roche.com>

src/views/project-panel/project-panel.tsx
src/views/workbench/workbench.tsx

index 0cd74ff91388b3287f09de80ecac745a3ea6b798..dd61e58a74a6c567a0fc423e72371f98aa46ca0b 100644 (file)
@@ -19,10 +19,9 @@ import { RouteComponentProps } from 'react-router';
 
 export const PROJECT_PANEL_ID = "projectPanel";
 
-type ProjectPanelProps = { onItemOpen: (itemId: string) => void }
+type ProjectPanelProps = { onItemClick: (item: ProjectPanelItem) => void }
     & DispatchProp
-    & WithStyles<CssRules>
-    & RouteComponentProps<{ id: string }>;
+    & WithStyles<CssRules>;
 class ProjectPanel extends React.Component<ProjectPanelProps> {
     render() {
         return <div>
@@ -42,7 +41,7 @@ class ProjectPanel extends React.Component<ProjectPanelProps> {
                 contextActions={contextMenuActions}
                 onColumnToggle={this.toggleColumn}
                 onFiltersChange={this.changeFilters}
-                onRowClick={this.openProject}
+                onRowClick={this.props.onItemClick}
                 onSortToggle={this.toggleSort}
                 onSearch={this.search}
                 onContextAction={this.executeAction}
@@ -55,12 +54,6 @@ class ProjectPanel extends React.Component<ProjectPanelProps> {
         this.props.dispatch(actions.SET_COLUMNS({ id: PROJECT_PANEL_ID, columns }));
     }
 
-    componentWillReceiveProps(nextProps: ProjectPanelProps) {
-        if (this.props.match.params.id !== nextProps.match.params.id) {
-            this.props.onItemOpen(nextProps.match.params.id);
-        }
-    }
-
     toggleColumn = (toggledColumn: DataColumn<ProjectPanelItem>) => {
         this.props.dispatch(actions.TOGGLE_COLUMN({ id: PROJECT_PANEL_ID, columnName: toggledColumn.name }));
     }
@@ -88,10 +81,6 @@ class ProjectPanel extends React.Component<ProjectPanelProps> {
     changeRowsPerPage = (rowsPerPage: number) => {
         this.props.dispatch(actions.SET_ROWS_PER_PAGE({ id: PROJECT_PANEL_ID, rowsPerPage }));
     }
-
-    openProject = (item: ProjectPanelItem) => {
-        this.props.onItemOpen(item.uuid);
-    }
 }
 
 type CssRules = "toolbar" | "button";
index c095868f8c58f0eee3c5fb26ac475f3754651979..48cab3c64dd25222f04f02a8f58139367133b077 100644 (file)
@@ -157,7 +157,7 @@ class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
             label: item.data.name,
             itemId: item.data.uuid,
             status: item.status
-        }));  
+        }));
 
         const { classes, user } = this.props;
         return (
@@ -206,12 +206,18 @@ class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
         );
     }
 
-    renderProjectPanel = (props: RouteComponentProps<any>) =>
-        <ProjectPanel
-            onItemOpen={itemId => this.props.dispatch<any>(
-                setProjectItem(itemId, ItemMode.ACTIVE)
-            )}
-            {...props} />
+    renderProjectPanel = (props: RouteComponentProps<{ id: string }>) => {
+        if (props.match.params.id !== this.props.currentProjectId) {
+            this.props.dispatch<any>(
+                setProjectItem(props.match.params.id, ItemMode.ACTIVE)
+            );
+        }
+        return <ProjectPanel
+            onItemClick={item => this.props.dispatch<any>(
+                setProjectItem(item.uuid, ItemMode.ACTIVE)
+            )} />;
+    }
+
 }
 
 export default connect<WorkbenchDataProps>(