getting tree path
authorPawel Kowalczyk <pawel.kowalczyk@contractors.roche.com>
Fri, 3 Aug 2018 06:51:55 +0000 (08:51 +0200)
committerPawel Kowalczyk <pawel.kowalczyk@contractors.roche.com>
Fri, 3 Aug 2018 06:51:55 +0000 (08:51 +0200)
Feature #13905

Arvados-DCO-1.1-Signed-off-by: Pawel Kowalczyk <pawel.kowalczyk@contractors.roche.com>

src/store/navigation/navigation-action.ts
src/validators/create-collection/create-collection-validator.tsx [new file with mode: 0644]
src/validators/create-project/create-project-validator.tsx
src/views-components/create-project-dialog/create-project-dialog.tsx
src/views-components/dialog-create/dialog-collection-create.tsx
src/views/workbench/workbench.tsx

index f8687ed754ad51f4604b4541361c5e3aff318fb5..68d7fc5239528cb3bbcbb1a0464172fcfd713757 100644 (file)
@@ -6,13 +6,14 @@ import { Dispatch } from "redux";
 import { projectActions, getProjectList } from "../project/project-action";
 import { push } from "react-router-redux";
 import { TreeItemStatus } from "../../components/tree/tree";
-import { findTreeItem } from "../project/project-reducer";
+import { findTreeItem, getTreePath } from "../project/project-reducer";
 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";
+import { getProjectUrl, ProjectResource } from "../../models/project";
+import { projectService } from "../../services/services";
 
 export const getResourceUrl = <T extends Resource>(resource: T): string => {
     switch (resource.kind) {
@@ -34,14 +35,22 @@ export const setProjectItem = (itemId: string, itemMode: ItemMode) =>
         const treeItem = findTreeItem(projects.items, itemId);
 
         if (treeItem) {
+            console.log('treeItem', treeItem);
 
+            const treePath = getTreePath(projects.items, treeItem.data.uuid);
+
+            console.log('treePath', treePath);
             const resourceUrl = getResourceUrl(treeItem.data);
 
+            console.log('resourceUrl', resourceUrl);
+            const ancestors = loadProjectAncestors(treeItem.data.uuid);
+            console.log('ancestors', ancestors);
+
             if (itemMode === ItemMode.ACTIVE || itemMode === ItemMode.BOTH) {
                 if (router.location && !router.location.pathname.includes(resourceUrl)) {
                     dispatch(push(resourceUrl));
                 }
-                dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(treeItem.data.uuid));
+                dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(treePath[treePath.length - 1].id));
             }
 
             const promise = treeItem.status === TreeItemStatus.LOADED
@@ -60,3 +69,14 @@ export const setProjectItem = (itemId: string, itemMode: ItemMode) =>
         }
     };
 
+    const USER_UUID_REGEX = /.*tpzed.*/;
+
+    export const loadProjectAncestors = async (uuid: string): Promise<Array<ProjectResource>> => {
+        if (USER_UUID_REGEX.test(uuid)) {
+            return [];
+        } else {
+            const currentProject = await projectService.get(uuid);
+            const ancestors = await loadProjectAncestors(currentProject.ownerUuid);
+            return [...ancestors, currentProject];
+        }
+    };
\ No newline at end of file
diff --git a/src/validators/create-collection/create-collection-validator.tsx b/src/validators/create-collection/create-collection-validator.tsx
new file mode 100644 (file)
index 0000000..2d8e1f5
--- /dev/null
@@ -0,0 +1,9 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import { require } from '../require';
+import { maxLength } from '../max-length';
+
+export const COLLECTION_NAME_VALIDATION = [require, maxLength(255)];
+export const COLLECTION_DESCRIPTION_VALIDATION = [maxLength(255)];
\ No newline at end of file
index 527043d9d8567024c60546091f6b4103dcdbe684..928efdd2205e439c82fbd936e0e476e13f046139 100644 (file)
@@ -7,5 +7,3 @@ import { maxLength } from '../max-length';
 
 export const PROJECT_NAME_VALIDATION = [require, maxLength(255)];
 export const PROJECT_DESCRIPTION_VALIDATION = [maxLength(255)];
-export const COLLECTION_NAME_VALIDATION = [require, maxLength(255)];
-export const COLLECTION_DESCRIPTION_VALIDATION = [maxLength(255)];
index eacb1eb5c09a3d58823d1230c3eb269fe2f22c7a..cbb80fff1281a6806424aa8469fdad1b396a2018 100644 (file)
@@ -22,7 +22,7 @@ const addProject = (data: { name: string, description: string }) =>
         const { ownerUuid } = getState().projects.creator;
         return dispatch<any>(createProject(data)).then(() => {
             dispatch(snackbarActions.OPEN_SNACKBAR({
-                message: "Created a new project",
+                message: "Project has been successfully created.",
                 hideDuration: 2000
             }));
             dispatch(dataExplorerActions.REQUEST_ITEMS({ id: PROJECT_PANEL_ID }));
index d0f793bfd854887df5b3afc1dbf6685d5b4290c0..08f47028c1c19a85df20898c88d2d2f221f647df 100644 (file)
@@ -12,7 +12,7 @@ import DialogContent from '@material-ui/core/DialogContent';
 import DialogTitle from '@material-ui/core/DialogTitle';
 import { Button, StyleRulesCallback, WithStyles, withStyles, CircularProgress } from '@material-ui/core';
 
-import { COLLECTION_NAME_VALIDATION, COLLECTION_DESCRIPTION_VALIDATION } from '../../validators/create-project/create-project-validator';
+import { COLLECTION_NAME_VALIDATION, COLLECTION_DESCRIPTION_VALIDATION } from '../../validators/create-collection/create-collection-validator';
 
 type CssRules = "button" | "lastButton" | "formContainer" | "textField" | "dialog" | "dialogTitle" | "createProgress" | "dialogActions";
 
index 160e12f84017e5a99e19c6e0084d3546dbdd59c9..1695201b4d2923e9892d0d208d7055500f8bffd7 100644 (file)
@@ -89,6 +89,7 @@ interface WorkbenchDataProps {
     user?: User;
     currentToken?: string;
     sidePanelItems: SidePanelItem[];
+    router?: any;
 }
 
 interface WorkbenchActionProps {
@@ -122,7 +123,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> {
@@ -162,6 +164,13 @@ export const Workbench = withStyles(styles)(
                 }
             };
 
+            componentDidMount() {
+                if (this.props.router.pathname.includes("/projects")) {
+                    this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_OPEN(SidePanelIdentifiers.PROJECTS));
+                    this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_ACTIVE(SidePanelIdentifiers.PROJECTS));
+                }
+            }
+
             render() {
                 const path = getTreePath(this.props.projects, this.props.currentProjectId);
                 const breadcrumbs = path.map(item => ({
@@ -169,6 +178,7 @@ export const Workbench = withStyles(styles)(
                     itemId: item.data.uuid,
                     status: item.status
                 }));
+                console.log("breadcrumbs", breadcrumbs);
 
                 const { classes, user } = this.props;
                 return (
@@ -234,7 +244,7 @@ export const Workbench = withStyles(styles)(
                 );
             }
 
-            renderCollectionPanel = (props: RouteComponentProps<{ id: string }>) => <CollectionPanel 
+            renderCollectionPanel = (props: RouteComponentProps<{ id: string }>) => <CollectionPanel
                 onItemRouteChange={(collectionId) => this.props.dispatch<any>(loadCollection(collectionId, ResourceKind.COLLECTION))}
                 onContextMenu={(event, item) => {
                     this.openContextMenu(event, {
@@ -266,7 +276,7 @@ export const Workbench = withStyles(styles)(
                         case ResourceKind.COLLECTION:
                             this.props.dispatch<any>(loadCollection(item.uuid, item.kind as ResourceKind));
                             this.props.dispatch(push(getCollectionUrl(item.uuid)));
-                        default: 
+                        default:
                             this.props.dispatch<any>(setProjectItem(item.uuid, ItemMode.ACTIVE));
                             this.props.dispatch<any>(loadDetails(item.uuid, item.kind as ResourceKind));
                     }