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 { TreeItemStatus } from "../../components/tree/tree";
9 import { findTreeItem } from "../project/project-reducer";
10 import { Resource, ResourceKind as R } from "../../models/resource";
11 import sidePanelActions from "../side-panel/side-panel-action";
12 import dataExplorerActions from "../data-explorer/data-explorer-action";
13 import { PROJECT_PANEL_ID } from "../../views/project-panel/project-panel";
14 import { RootState } from "../store";
15 import { sidePanelData } from "../side-panel/side-panel-reducer";
16 import { loadDetails } from "../details-panel/details-panel-action";
17 import { ResourceKind } from "../../models/kinds";
19 export const getResourceUrl = (resource: Resource): string => {
20 switch (resource.kind) {
21 case R.PROJECT: return `/projects/${resource.uuid}`;
22 case R.COLLECTION: return `/collections/${resource.uuid}`;
27 export enum ItemMode {
33 export const setProjectItem = (itemId: string, itemMode: ItemMode) =>
34 (dispatch: Dispatch, getState: () => RootState) => {
35 const { projects, router, sidePanel } = getState();
36 const treeItem = findTreeItem(projects.items, itemId);
39 // TODO: Get correct resource kind
40 dispatch<any>(loadDetails(treeItem.data.uuid, ResourceKind.Project));
42 dispatch(sidePanelActions.RESET_SIDE_PANEL_ACTIVITY());
43 const projectsItem = sidePanelData[0];
44 if(sidePanel.some(item => item.id === projectsItem.id && !item.open)){
45 dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_OPEN(projectsItem.id));
48 if (itemMode === ItemMode.OPEN || itemMode === ItemMode.BOTH) {
49 dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_OPEN(treeItem.data.uuid));
52 const resourceUrl = getResourceUrl({ ...treeItem.data });
54 if (itemMode === ItemMode.ACTIVE || itemMode === ItemMode.BOTH) {
55 if (router.location && !router.location.pathname.includes(resourceUrl)) {
56 dispatch(push(resourceUrl));
58 dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(treeItem.data.uuid));
61 const promise = treeItem.status === TreeItemStatus.Loaded
63 : dispatch<any>(getProjectList(itemId));
66 .then(() => dispatch<any>(() => {
67 dispatch(dataExplorerActions.RESET_PAGINATION({id: PROJECT_PANEL_ID}));
68 dispatch(dataExplorerActions.REQUEST_ITEMS({id: PROJECT_PANEL_ID}));