Merge branch 'master' into 13905-restoring-correct-tree-state-and-panel-item-highligh...
[arvados-workbench2.git] / src / views / workbench / workbench.tsx
index 3611d7b10fb12210f9573f9ebf2df41476d62693..e78c3e7cddcd1d9f58c29772ab171a3e7bd6378f 100644 (file)
@@ -18,7 +18,7 @@ import { TreeItem } from "../../components/tree/tree";
 import { getTreePath } from '../../store/project/project-reducer';
 import { sidePanelActions } from '../../store/side-panel/side-panel-action';
 import { SidePanel, SidePanelItem } from '../../components/side-panel/side-panel';
-import { ItemMode, setProjectItem } from "../../store/navigation/navigation-action";
+import { ItemMode, setProjectItem, restoreBranch } from "../../store/navigation/navigation-action";
 import { projectActions } from "../../store/project/project-action";
 import { collectionCreateActions } from '../../store/collections/creator/collection-creator-action';
 import { ProjectPanel } from "../project-panel/project-panel";
@@ -93,6 +93,7 @@ interface WorkbenchDataProps {
     user?: User;
     currentToken?: string;
     sidePanelItems: SidePanelItem[];
+    router?: any;
 }
 
 interface WorkbenchServiceProps {
@@ -130,7 +131,8 @@ export const Workbench = withStyles(styles)(
             currentProjectId: state.projects.currentItemId,
             user: state.auth.user,
             currentToken: state.auth.apiToken,
-            sidePanelItems: state.sidePanel
+            sidePanelItems: state.sidePanel,
+            router: state.router.location
         })
     )(
         class extends React.Component<WorkbenchProps, WorkbenchState> {
@@ -170,6 +172,20 @@ export const Workbench = withStyles(styles)(
                 }
             };
 
+            componentDidMount() {
+                const PROJECT_URL_REGEX = /\/projects\/(.*)/;
+                const getProjectIdFromUrl = (url: string) => {
+                    const match = PROJECT_URL_REGEX.exec(url);
+                    return match ? match[1] : match;
+                };
+
+                const id = getProjectIdFromUrl(this.props.router.pathname);
+                if (id) {
+                    this.props.dispatch<any>(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_ACTIVE(SidePanelIdentifiers.PROJECTS));
+                    this.props.dispatch<any>(restoreBranch(id));
+                }
+            }
+
             render() {
                 const path = getTreePath(this.props.projects, this.props.currentProjectId);
                 const breadcrumbs = path.map(item => ({
@@ -277,7 +293,7 @@ export const Workbench = withStyles(styles)(
                         case ResourceKind.COLLECTION:
                             this.props.dispatch(loadCollection(item.uuid, item.kind as ResourceKind));
                             this.props.dispatch(push(getCollectionUrl(item.uuid)));
-                        default: 
+                        default:
                             this.props.dispatch(setProjectItem(item.uuid, ItemMode.ACTIVE));
                             this.props.dispatch(loadDetails(item.uuid, item.kind as ResourceKind));
                     }