X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/4beb141298fce3da40f07e1a0a08f29ac28dfd09..ab3e261d28ff83fa214002a372a055817a931cd1:/src/store/navigation/navigation-action.ts diff --git a/src/store/navigation/navigation-action.ts b/src/store/navigation/navigation-action.ts index 0b4bcdf87a..7f782438f5 100644 --- a/src/store/navigation/navigation-action.ts +++ b/src/store/navigation/navigation-action.ts @@ -3,22 +3,20 @@ // SPDX-License-Identifier: AGPL-3.0 import { Dispatch } from "redux"; -import projectActions, { getProjectList } from "../project/project-action"; +import { projectActions, getProjectList } from "../project/project-action"; import { push } from "react-router-redux"; -import { TreeItem, TreeItemStatus } from "../../components/tree/tree"; -import { getCollectionList } from "../collection/collection-action"; +import { TreeItemStatus } from "../../components/tree/tree"; import { findTreeItem } from "../project/project-reducer"; -import { Project } from "../../models/project"; +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 sidePanelActions from "../side-panel/side-panel-action"; -export const getResourceUrl = (resource: Resource): string => { +export const getResourceUrl = (resource: T): string => { switch (resource.kind) { - case ResourceKind.LEVEL_UP: return `/projects/${resource.ownerUuid}`; - case ResourceKind.PROJECT: return `/projects/${resource.uuid}`; - case ResourceKind.COLLECTION: return `/collections/${resource.uuid}`; - default: - return "#"; + case ResourceKind.Project: return `/projects/${resource.uuid}`; + case ResourceKind.Collection: return `/collections/${resource.uuid}`; + default: return resource.href; } }; @@ -28,36 +26,40 @@ export enum ItemMode { ACTIVE } -export const setProjectItem = (projects: Array>, itemId: string, itemKind: ResourceKind, itemMode: ItemMode) => (dispatch: Dispatch) => { +export const setProjectItem = (itemId: string, itemMode: ItemMode) => + (dispatch: Dispatch, getState: () => RootState) => { + const { projects, router } = getState(); + const treeItem = findTreeItem(projects.items, itemId); - const openProjectItem = (resource: Resource) => { - if (itemMode === ItemMode.OPEN || itemMode === ItemMode.BOTH) { - dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_OPEN(resource.uuid)); - } + if (treeItem) { - if (itemMode === ItemMode.ACTIVE || itemMode === ItemMode.BOTH) { - dispatch(sidePanelActions.RESET_SIDE_PANEL_ACTIVITY(resource.uuid)); - } + if (itemMode === ItemMode.OPEN || itemMode === ItemMode.BOTH) { + dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_OPEN(treeItem.data.uuid)); + } - dispatch(push(getResourceUrl({...resource, kind: itemKind}))); - }; + const resourceUrl = getResourceUrl(treeItem.data); - let treeItem = findTreeItem(projects, itemId); - if (treeItem && itemKind === ResourceKind.LEVEL_UP) { - treeItem = findTreeItem(projects, treeItem.data.ownerUuid); - } + 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)); + } - if (treeItem) { - dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(treeItem.data.uuid)); + const promise = treeItem.status === TreeItemStatus.Loaded + ? Promise.resolve() + : dispatch(getProjectList(itemId)); + + promise + .then(() => dispatch(() => { + dispatch(dataExplorerActions.RESET_PAGINATION({id: PROJECT_PANEL_ID})); + dispatch(dataExplorerActions.REQUEST_ITEMS({id: PROJECT_PANEL_ID})); + })); - if (treeItem.status === TreeItemStatus.Loaded) { - openProjectItem(treeItem.data); - } else { - dispatch(getProjectList(itemId)) - .then(() => openProjectItem(treeItem!.data)); - } - if (itemMode === ItemMode.ACTIVE || itemMode === ItemMode.BOTH) { - dispatch(getCollectionList(itemId)); } - } -}; + }; + +export const setFavoriteItem = (itemId: string, itemMode: ItemMode) => + (dispatch: Dispatch, getState: () => RootState) => { + const a = 1; + };