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 { getCollectionList } from "../collection/collection-action";
10 import { findTreeItem } from "../project/project-reducer";
11 import { Resource, ResourceKind } from "../../models/resource";
12 import sidePanelActions from "../side-panel/side-panel-action";
13 import dataExplorerActions from "../data-explorer/data-explorer-action";
14 import { PROJECT_PANEL_ID } from "../../views/project-panel/project-panel";
15 import { projectPanelItems } from "../../views/project-panel/project-panel-selectors";
16 import { RootState } from "../store";
18 export const getResourceUrl = (resource: Resource): string => {
19 switch (resource.kind) {
20 case ResourceKind.PROJECT: return `/projects/${resource.uuid}`;
21 case ResourceKind.COLLECTION: return `/collections/${resource.uuid}`;
26 export enum ItemMode {
32 export const setProjectItem = (itemId: string, itemMode: ItemMode) =>
33 (dispatch: Dispatch, getState: () => RootState) => {
34 const { projects, router } = getState();
35 const treeItem = findTreeItem(projects.items, itemId);
39 dispatch(sidePanelActions.RESET_SIDE_PANEL_ACTIVITY());
41 if (itemMode === ItemMode.OPEN || itemMode === ItemMode.BOTH) {
42 dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_OPEN(treeItem.data.uuid));
45 const resourceUrl = getResourceUrl({ ...treeItem.data });
47 if (itemMode === ItemMode.ACTIVE || itemMode === ItemMode.BOTH) {
48 if (router.location && !router.location.pathname.includes(resourceUrl)) {
49 dispatch(push(resourceUrl));
51 dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(treeItem.data.uuid));
54 const promise = treeItem.status === TreeItemStatus.Loaded
56 : dispatch<any>(getProjectList(itemId));
59 .then(() => dispatch<any>(getCollectionList(itemId)))
60 .then(() => dispatch<any>(() => {
61 const { projects, collections } = getState();
62 dispatch(dataExplorerActions.SET_ITEMS({
64 items: projectPanelItems(