From 81db818eb5a3404d0b98e6afbbbccc1ae064fd48 Mon Sep 17 00:00:00 2001 From: Michal Klobukowski Date: Sat, 30 Jun 2018 14:19:36 +0200 Subject: [PATCH] Improve handling on of project url changes Feature #13678 Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski --- src/views/project-panel/project-panel.tsx | 17 +++-------------- src/views/workbench/workbench.tsx | 20 +++++++++++++------- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/src/views/project-panel/project-panel.tsx b/src/views/project-panel/project-panel.tsx index 0cd74ff9..dd61e58a 100644 --- a/src/views/project-panel/project-panel.tsx +++ b/src/views/project-panel/project-panel.tsx @@ -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 - & RouteComponentProps<{ id: string }>; + & WithStyles; class ProjectPanel extends React.Component { render() { return
@@ -42,7 +41,7 @@ class ProjectPanel extends React.Component { 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 { 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) => { this.props.dispatch(actions.TOGGLE_COLUMN({ id: PROJECT_PANEL_ID, columnName: toggledColumn.name })); } @@ -88,10 +81,6 @@ class ProjectPanel extends React.Component { 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"; diff --git a/src/views/workbench/workbench.tsx b/src/views/workbench/workbench.tsx index c095868f..48cab3c6 100644 --- a/src/views/workbench/workbench.tsx +++ b/src/views/workbench/workbench.tsx @@ -157,7 +157,7 @@ class Workbench extends React.Component { 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 { ); } - renderProjectPanel = (props: RouteComponentProps) => - this.props.dispatch( - setProjectItem(itemId, ItemMode.ACTIVE) - )} - {...props} /> + renderProjectPanel = (props: RouteComponentProps<{ id: string }>) => { + if (props.match.params.id !== this.props.currentProjectId) { + this.props.dispatch( + setProjectItem(props.match.params.id, ItemMode.ACTIVE) + ); + } + return this.props.dispatch( + setProjectItem(item.uuid, ItemMode.ACTIVE) + )} />; + } + } export default connect( -- 2.30.2