X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/6e44781d01db889030cc5f7819aa7f15fe837e19..3a3de86b86ef60fc86f1190d42bc8a2471ab5276:/src/store/navigation/navigation-action.ts diff --git a/src/store/navigation/navigation-action.ts b/src/store/navigation/navigation-action.ts index 80318ec7..fc08f3ac 100644 --- a/src/store/navigation/navigation-action.ts +++ b/src/store/navigation/navigation-action.ts @@ -2,46 +2,66 @@ // // 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"; - -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) => { +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, getProcessLogUrl } from '~/routes/routes'; +import { RootState } from '~/store/store'; +import { ServiceRepository } from '~/services/services'; - const openProjectItem = (resource: Resource) => { - dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM(resource.uuid)); - dispatch(push(getResourceUrl({...resource, kind: itemKind}))); - }; - const treeItem = findTreeItem(projects, itemId); - - if (treeItem) { - if (treeItem.status === TreeItemStatus.Loaded) { - openProjectItem(treeItem.data); - } else { - dispatch(getProjectList(itemId)) - .then(() => openProjectItem(treeItem.data)); +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); + } else if (uuid === SidePanelTreeCategory.SHARED_WITH_ME) { + dispatch(navigateToSharedWithMe); + } else if (uuid === SidePanelTreeCategory.WORKFLOWS) { + dispatch(navigateToWorkflows); + } else if (uuid === SidePanelTreeCategory.TRASH) { + dispatch(navigateToTrash); } - dispatch(getCollectionList(itemId)); + }; + +export const navigateToRoot = push(Routes.ROOT); + +export const navigateToFavorites = push(Routes.FAVORITES); + +export const navigateToTrash = push(Routes.TRASH); - // 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 navigateToWorkflows = push(Routes.WORKFLOWS); +export const navigateToProject = compose(push, getProjectUrl); + +export const navigateToCollection = compose(push, getCollectionUrl); + +export const navigateToProcess = compose(push, getProcessUrl); + +export const navigateToProcessLogs = compose(push, getProcessLogUrl); + +export const navigateToRootProject = (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { + const rootProjectUuid = services.authService.getUuid(); + if (rootProjectUuid) { + dispatch(navigateToProject(rootProjectUuid)); } }; + +export const navigateToSharedWithMe = push(Routes.SHARED_WITH_ME); + +export const navigateToRunProcess = push(Routes.RUN_PROCESS); + +export const navigateToSearchResults = push(Routes.SEARCH_RESULTS); + +export const navigateToRepositories = push(Routes.REPOSITORIES); + +export const navigateToSshKeys= push(Routes.SSH_KEYS);