X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/7622261116e685cad4af9cf6a4d1dd9c58cd1605..cba0f400f56889778321bdc0fdcf6cee236f6a79:/src/store/navigation/navigation-action.ts diff --git a/src/store/navigation/navigation-action.ts b/src/store/navigation/navigation-action.ts index 034cdacc..188acf12 100644 --- a/src/store/navigation/navigation-action.ts +++ b/src/store/navigation/navigation-action.ts @@ -2,71 +2,34 @@ // // SPDX-License-Identifier: AGPL-3.0 -import { Dispatch } from "redux"; -import projectActions, { getProjectList } from "../project/project-action"; +import { Dispatch, compose } from 'redux'; import { push } from "react-router-redux"; -import { TreeItemStatus } from "../../components/tree/tree"; -import { findTreeItem } from "../project/project-reducer"; -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 { 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 R.PROJECT: return `/projects/${resource.uuid}`; - case R.COLLECTION: return `/collections/${resource.uuid}`; - default: return ""; - } -}; - -export enum ItemMode { - BOTH, - OPEN, - ACTIVE -} - -export const setProjectItem = (itemId: string, itemMode: ItemMode) => - (dispatch: Dispatch, getState: () => RootState) => { - const { projects, router, sidePanel } = getState(); - const treeItem = findTreeItem(projects.items, itemId); - - if (treeItem) { - // TODO: Get correct resource kind - dispatch(loadDetails(treeItem.data.uuid, ResourceKind.Project)); - - 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.OPEN || itemMode === ItemMode.BOTH) { - dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_OPEN(treeItem.data.uuid)); - } - - const resourceUrl = getResourceUrl({ ...treeItem.data }); +import { ResourceKind, extractUuidKind } from '~/models/resource'; +import { getCollectionUrl } from "~/models/collection"; +import { getProjectUrl } from "~/models/project"; + +import { SidePanelTreeCategory } from '../side-panel-tree/side-panel-tree-actions'; +import { Routes, getProcessUrl } from '~/routes/routes'; + +export const navigateTo = (uuid: string) => + async (dispatch: Dispatch) => { + const kind = extractUuidKind(uuid); + if (kind === ResourceKind.PROJECT || kind === ResourceKind.USER) { + dispatch(navigateToProject(uuid)); + } else if (kind === ResourceKind.COLLECTION) { + dispatch(navigateToCollection(uuid)); + } else if (kind === ResourceKind.CONTAINER_REQUEST) { + dispatch(navigateToProcess(uuid)); + } + if (uuid === SidePanelTreeCategory.FAVORITES) { + dispatch(navigateToFavorites); + } + }; - 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)); - } +export const navigateToFavorites = push(Routes.FAVORITES); - const promise = treeItem.status === TreeItemStatus.Loaded - ? Promise.resolve() - : dispatch(getProjectList(itemId)); +export const navigateToProject = compose(push, getProjectUrl); - promise - .then(() => dispatch(() => { - dispatch(dataExplorerActions.RESET_PAGINATION({id: PROJECT_PANEL_ID})); - dispatch(dataExplorerActions.REQUEST_ITEMS({id: PROJECT_PANEL_ID})); - })); +export const navigateToCollection = compose(push, getCollectionUrl); - } - }; +export const navigateToProcess = compose(push, getProcessUrl);