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 } 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";
17 export const getResourceUrl = (resource: Resource): string => {
18 switch (resource.kind) {
19 case ResourceKind.PROJECT: return `/projects/${resource.uuid}`;
20 case ResourceKind.COLLECTION: return `/collections/${resource.uuid}`;
25 export enum ItemMode {
31 export const setProjectItem = (itemId: string, itemMode: ItemMode) =>
32 (dispatch: Dispatch, getState: () => RootState) => {
33 const { projects, router, sidePanel } = getState();
34 const treeItem = findTreeItem(projects.items, itemId);
38 dispatch(sidePanelActions.RESET_SIDE_PANEL_ACTIVITY());
39 const projectsItem = sidePanelData[0];
40 if(sidePanel.some(item => item.id === projectsItem.id && !item.open)){
41 dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_OPEN(projectsItem.id));
44 if (itemMode === ItemMode.OPEN || itemMode === ItemMode.BOTH) {
45 dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_OPEN(treeItem.data.uuid));
48 const resourceUrl = getResourceUrl({ ...treeItem.data });
50 if (itemMode === ItemMode.ACTIVE || itemMode === ItemMode.BOTH) {
51 if (router.location && !router.location.pathname.includes(resourceUrl)) {
52 dispatch(push(resourceUrl));
54 dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(treeItem.data.uuid));
57 const promise = treeItem.status === TreeItemStatus.Loaded
59 : dispatch<any>(getProjectList(itemId));
62 .then(() => dispatch<any>(() => {
63 dispatch(dataExplorerActions.RESET_PAGINATION({id: PROJECT_PANEL_ID}));
64 dispatch(dataExplorerActions.REQUEST_ITEMS({id: PROJECT_PANEL_ID}));