X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/52cc3b912c703c24bc90e67aaf24e8ad912d3ebf..f05e6a9cece7e3b118134136ee81bd7477ad10a0:/src/store/navigation/navigation-action.ts diff --git a/src/store/navigation/navigation-action.ts b/src/store/navigation/navigation-action.ts index b811f9a2..1cab7349 100644 --- a/src/store/navigation/navigation-action.ts +++ b/src/store/navigation/navigation-action.ts @@ -6,22 +6,21 @@ import { Dispatch } from "redux"; import projectActions, { getProjectList } from "../project/project-action"; import { push } from "react-router-redux"; import { TreeItemStatus } from "../../components/tree/tree"; -import { getCollectionList } from "../collection/collection-action"; import { findTreeItem } from "../project/project-reducer"; -import { Resource, ResourceKind } from "../../models/resource"; +import { Resource, ResourceKind as R } from "../../models/resource"; import sidePanelActions from "../side-panel/side-panel-action"; import dataExplorerActions from "../data-explorer/data-explorer-action"; import { PROJECT_PANEL_ID } from "../../views/project-panel/project-panel"; -import { projectPanelItems } from "../../views/project-panel/project-panel-selectors"; import { RootState } from "../store"; +import { sidePanelData } from "../side-panel/side-panel-reducer"; +import { loadDetails } from "../details-panel/details-panel-action"; +import { ResourceKind } from "../../models/kinds"; export const getResourceUrl = (resource: Resource): 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 R.PROJECT: return `/projects/${resource.uuid}`; + case R.COLLECTION: return `/collections/${resource.uuid}`; + default: return ""; } }; @@ -31,50 +30,41 @@ export enum ItemMode { ACTIVE } -export const setProjectItem = (itemId: string, itemKind = ResourceKind.PROJECT, itemMode = ItemMode.OPEN) => +export const setProjectItem = (itemId: string, itemMode: ItemMode) => (dispatch: Dispatch, getState: () => RootState) => { - const { projects } = getState(); - - let treeItem = findTreeItem(projects.items, itemId); - if (treeItem && itemKind === ResourceKind.LEVEL_UP) { - treeItem = findTreeItem(projects.items, treeItem.data.ownerUuid); - } + const { projects, router, sidePanel } = getState(); + const treeItem = findTreeItem(projects.items, itemId); if (treeItem) { - dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(treeItem.data.uuid)); - if (treeItem.status === TreeItemStatus.Loaded) { - dispatch(openProjectItem(treeItem.data, itemKind, itemMode)); - } else { - dispatch(getProjectList(itemId)) - .then(() => dispatch(openProjectItem(treeItem!.data, itemKind, itemMode))); + dispatch(sidePanelActions.RESET_SIDE_PANEL_ACTIVITY()); + const projectsItem = sidePanelData[0]; + if(sidePanel.some(item => item.id === projectsItem.id && !item.open)){ + dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_OPEN(projectsItem.id)); } - if (itemMode === ItemMode.ACTIVE || itemMode === ItemMode.BOTH) { - dispatch(getCollectionList(itemId)); + + if (itemMode === ItemMode.OPEN || itemMode === ItemMode.BOTH) { + dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_OPEN(treeItem.data.uuid)); } - } - }; -const openProjectItem = (resource: Resource, itemKind: ResourceKind, itemMode: ItemMode) => - (dispatch: Dispatch, getState: () => RootState) => { + const resourceUrl = getResourceUrl({ ...treeItem.data }); + + 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)); + } - const { collections, projects } = getState(); + const promise = treeItem.status === TreeItemStatus.Loaded + ? Promise.resolve() + : dispatch(getProjectList(itemId)); - if (itemMode === ItemMode.OPEN || itemMode === ItemMode.BOTH) { - dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_OPEN(resource.uuid)); - } + promise + .then(() => dispatch(() => { + dispatch(dataExplorerActions.RESET_PAGINATION({id: PROJECT_PANEL_ID})); + dispatch(dataExplorerActions.REQUEST_ITEMS({id: PROJECT_PANEL_ID})); + })); - if (itemMode === ItemMode.ACTIVE || itemMode === ItemMode.BOTH) { - dispatch(sidePanelActions.RESET_SIDE_PANEL_ACTIVITY(resource.uuid)); } - - dispatch(push(getResourceUrl({ ...resource, kind: itemKind }))); - dispatch(dataExplorerActions.SET_ITEMS({ - id: PROJECT_PANEL_ID, - items: projectPanelItems( - projects.items, - resource.uuid, - collections - ) - })); };