Merge branch 'master' into 13853-collection-view-info-card
[arvados.git] / src / store / navigation / navigation-action.ts
index 50f6e205e096c3743819a2bc97c75e8537fc0b45..f8687ed754ad51f4604b4541361c5e3aff318fb5 100644 (file)
@@ -11,11 +11,13 @@ import { dataExplorerActions } from "../data-explorer/data-explorer-action";
 import { PROJECT_PANEL_ID } from "../../views/project-panel/project-panel";
 import { RootState } from "../store";
 import { Resource, ResourceKind } from "../../models/resource";
+import { getCollectionUrl } from "../../models/collection";
+import { getProjectUrl } from "../../models/project";
 
 export const getResourceUrl = <T extends Resource>(resource: T): string => {
     switch (resource.kind) {
-        case ResourceKind.Project: return `/projects/${resource.uuid}`;
-        case ResourceKind.Collection: return `/collections/${resource.uuid}`;
+        case ResourceKind.PROJECT: return getProjectUrl(resource.uuid);
+        case ResourceKind.COLLECTION: return getCollectionUrl(resource.uuid);
         default: return resource.href;
     }
 };
@@ -33,10 +35,6 @@ export const setProjectItem = (itemId: string, itemMode: ItemMode) =>
 
         if (treeItem) {
 
-            if (itemMode === ItemMode.OPEN || itemMode === ItemMode.BOTH) {
-                dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_OPEN(treeItem.data.uuid));
-            }
-
             const resourceUrl = getResourceUrl(treeItem.data);
 
             if (itemMode === ItemMode.ACTIVE || itemMode === ItemMode.BOTH) {
@@ -46,12 +44,15 @@ export const setProjectItem = (itemId: string, itemMode: ItemMode) =>
                 dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(treeItem.data.uuid));
             }
 
-            const promise = treeItem.status === TreeItemStatus.Loaded
+            const promise = treeItem.status === TreeItemStatus.LOADED
                 ? Promise.resolve()
                 : dispatch<any>(getProjectList(itemId));
 
             promise
                 .then(() => dispatch<any>(() => {
+                    if (itemMode === ItemMode.OPEN || itemMode === ItemMode.BOTH) {
+                        dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_OPEN(treeItem.data.uuid));
+                    }
                     dispatch(dataExplorerActions.RESET_PAGINATION({id: PROJECT_PANEL_ID}));
                     dispatch(dataExplorerActions.REQUEST_ITEMS({id: PROJECT_PANEL_ID}));
                 }));