X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/5fd5db805554d3eddd46cc911a5108fbb74b3cfc..cba0f400f56889778321bdc0fdcf6cee236f6a79:/src/store/navigation/navigation-action.ts diff --git a/src/store/navigation/navigation-action.ts b/src/store/navigation/navigation-action.ts index 6d1754d92c..188acf12bd 100644 --- a/src/store/navigation/navigation-action.ts +++ b/src/store/navigation/navigation-action.ts @@ -2,64 +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 { TreeItem, TreeItemStatus } from "../../components/tree/tree"; -import { getCollectionList } from "../collection/collection-action"; -import { findTreeItem } from "../project/project-reducer"; -import { Project } from "../../models/project"; -import { Resource, ResourceKind } from "../../models/resource"; -import sidePanelActions from "../side-panel/side-panel-action"; - -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 "#"; - } -}; - -export const setProjectItem = (projects: Array>, itemId: string, itemKind: ResourceKind) => (dispatch: Dispatch) => { - - const openProjectItem = (resource: Resource) => { - dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_OPEN(resource.uuid)); - dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(resource.uuid)); - dispatch(sidePanelActions.RESET_SIDE_PANEL_ACTIVITY(resource.uuid)); - dispatch(push(getResourceUrl({...resource, kind: itemKind}))); +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); + } }; - const treeItem = findTreeItem(projects, itemId); - if (treeItem) { - if (treeItem.status === TreeItemStatus.Loaded) { - openProjectItem(treeItem.data); - } else { - dispatch(getProjectList(itemId)) - .then(() => openProjectItem(treeItem.data)); - } - dispatch(getCollectionList(itemId)); +export const navigateToFavorites = push(Routes.FAVORITES); - // if (item.type === ResourceKind.PROJECT || item.type === ResourceKind.LEVEL_UP) { - // this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM(item.uuid)); - // } - // this.props.dispatch(getCollectionList(item.uuid)); +export const navigateToProject = compose(push, getProjectUrl); - } -}; +export const navigateToCollection = compose(push, getCollectionUrl); - // toggleProjectTreeItemActive = (itemId: string, status: TreeItemStatus) => { - // if (status === TreeItemStatus.Loaded) { - // this.openProjectItem(itemId); - // this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(itemId)); - // this.props.dispatch(sidePanelActions.RESET_SIDE_PANEL_ACTIVITY(itemId)); - // } else { - // this.props.dispatch(getProjectList(itemId)) - // .then(() => { - // this.openProjectItem(itemId); - // this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(itemId)); - // this.props.dispatch(sidePanelActions.RESET_SIDE_PANEL_ACTIVITY(itemId)); - // }); - // } - // } +export const navigateToProcess = compose(push, getProcessUrl);