1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { Dispatch } from "redux";
6 import projectActions, { getProjectList } from "../project/project-action";
7 import { push } from "react-router-redux";
8 import { TreeItem, TreeItemStatus } from "../../components/tree/tree";
9 import { getCollectionList } from "../collection/collection-action";
10 import { findTreeItem } from "../project/project-reducer";
11 import { Project } from "../../models/project";
12 import { Resource, ResourceKind } from "../../models/resource";
13 import sidePanelActions from "../side-panel/side-panel-action";
15 export const getResourceUrl = (resource: Resource): string => {
16 switch (resource.kind) {
17 case ResourceKind.LEVEL_UP: return `/projects/${resource.ownerUuid}`;
18 case ResourceKind.PROJECT: return `/projects/${resource.uuid}`;
19 case ResourceKind.COLLECTION: return `/collections/${resource.uuid}`;
25 export const setProjectItem = (projects: Array<TreeItem<Project>>, itemId: string, itemKind: ResourceKind) => (dispatch: Dispatch) => {
27 const openProjectItem = (resource: Resource) => {
28 dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_OPEN(resource.uuid));
29 dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(resource.uuid));
30 dispatch(sidePanelActions.RESET_SIDE_PANEL_ACTIVITY(resource.uuid));
31 dispatch(push(getResourceUrl({...resource, kind: itemKind})));
33 const treeItem = findTreeItem(projects, itemId);
36 if (treeItem.status === TreeItemStatus.Loaded) {
37 openProjectItem(treeItem.data);
39 dispatch<any>(getProjectList(itemId))
40 .then(() => openProjectItem(treeItem.data));
42 dispatch<any>(getCollectionList(itemId));
44 // if (item.type === ResourceKind.PROJECT || item.type === ResourceKind.LEVEL_UP) {
45 // this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM(item.uuid));
47 // this.props.dispatch<any>(getCollectionList(item.uuid));
52 // toggleProjectTreeItemActive = (itemId: string, status: TreeItemStatus) => {
53 // if (status === TreeItemStatus.Loaded) {
54 // this.openProjectItem(itemId);
55 // this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(itemId));
56 // this.props.dispatch(sidePanelActions.RESET_SIDE_PANEL_ACTIVITY(itemId));
58 // this.props.dispatch<any>(getProjectList(itemId))
60 // this.openProjectItem(itemId);
61 // this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(itemId));
62 // this.props.dispatch(sidePanelActions.RESET_SIDE_PANEL_ACTIVITY(itemId));