X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/d6d85de50096eb0053d58c5022fd4e949c830929..cba0f400f56889778321bdc0fdcf6cee236f6a79:/src/store/navigation/navigation-action.ts diff --git a/src/store/navigation/navigation-action.ts b/src/store/navigation/navigation-action.ts index db8efbfd..188acf12 100644 --- a/src/store/navigation/navigation-action.ts +++ b/src/store/navigation/navigation-action.ts @@ -4,111 +4,32 @@ import { Dispatch, compose } from 'redux'; import { push } from "react-router-redux"; -import { RootState } from "../store"; -import { ResourceKind, Resource } from '~/models/resource'; +import { ResourceKind, extractUuidKind } from '~/models/resource'; import { getCollectionUrl } from "~/models/collection"; import { getProjectUrl } from "~/models/project"; -import { getResource } from '~/store/resources/resources'; -import { loadDetailsPanel } from '~/store/details-panel/details-panel-action'; -import { loadCollectionPanel } from '~/store/collection-panel/collection-panel-action'; -import { snackbarActions } from '../snackbar/snackbar-actions'; -import { resourceLabel } from "~/common/labels"; -import { loadFavoritePanel } from '../favorite-panel/favorite-panel-action'; -import { openProjectPanel, projectPanelActions } from '~/store/project-panel/project-panel-action'; -import { activateSidePanelTreeItem, initSidePanelTree, SidePanelTreeCategory } from '../side-panel-tree/side-panel-tree-actions'; -import { Routes } from '~/routes/routes'; -import { loadResource } from '../resources/resources-actions'; -import { ServiceRepository } from '~/services/services'; -import { favoritePanelActions } from '~/store/favorite-panel/favorite-panel-action'; -import { projectPanelColumns } from '~/views/project-panel/project-panel'; -import { favoritePanelColumns } from '~/views/favorite-panel/favorite-panel'; -import { matchRootRoute } from '~/routes/routes'; -export const navigateToResource = (uuid: string) => - async (dispatch: Dispatch, getState: () => RootState) => { - const resource = getResource(uuid)(getState().resources); - if (resource) { - dispatch(getResourceNavigationAction(resource)); - } - }; +import { SidePanelTreeCategory } from '../side-panel-tree/side-panel-tree-actions'; +import { Routes, getProcessUrl } from '~/routes/routes'; -const getResourceNavigationAction = (resource: Resource) => { - switch (resource.kind) { - case ResourceKind.COLLECTION: - return navigateToCollection(resource.uuid); - case ResourceKind.PROJECT: - case ResourceKind.USER: - return navigateToProject(resource.uuid); - default: - return cannotNavigateToResource(resource); - } -}; - -export const loadWorkbench = () => - async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { - const { auth, router } = getState(); - const { user } = auth; - if (user) { - const userResource = await dispatch(loadResource(user.uuid)); - if (userResource) { - dispatch(projectPanelActions.SET_COLUMNS({ columns: projectPanelColumns })); - dispatch(favoritePanelActions.SET_COLUMNS({ columns: favoritePanelColumns })); - dispatch(initSidePanelTree()); - if (router.location) { - const match = matchRootRoute(router.location.pathname); - if (match) { - dispatch(navigateToProject(userResource.uuid)); - } - } - } else { - dispatch(userIsNotAuthenticated); - } - } else { - dispatch(userIsNotAuthenticated); +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); } }; export const navigateToFavorites = push(Routes.FAVORITES); -export const loadFavorites = () => - async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { - dispatch(activateSidePanelTreeItem(SidePanelTreeCategory.FAVORITES)); - dispatch(loadFavoritePanel()); - }; - - export const navigateToProject = compose(push, getProjectUrl); -export const loadProject = (uuid: string) => - (dispatch: Dispatch) => { - dispatch(activateSidePanelTreeItem(uuid)); - dispatch(openProjectPanel(uuid)); - dispatch(loadDetailsPanel(uuid)); - }; - export const navigateToCollection = compose(push, getCollectionUrl); -export const loadCollection = (uuid: string) => - async (dispatch: Dispatch) => { - const collection = await dispatch(loadCollectionPanel(uuid)); - dispatch(activateSidePanelTreeItem(collection.ownerUuid)); - dispatch(loadDetailsPanel(uuid)); - }; - -export const cannotNavigateToResource = ({ kind, uuid }: Resource) => - snackbarActions.OPEN_SNACKBAR({ - message: `${resourceLabel(kind)} identified by ${uuid} cannot be opened.` - }); - -export const resourceIsNotLoaded = (uuid: string) => - snackbarActions.OPEN_SNACKBAR({ - message: `Resource identified by ${uuid} is not loaded.` - }); - -export const userIsNotAuthenticated = snackbarActions.OPEN_SNACKBAR({ - message: 'User is not authenticated' -}); - -export const couldNotLoadUser = snackbarActions.OPEN_SNACKBAR({ - message: 'Could not load user' -}); \ No newline at end of file +export const navigateToProcess = compose(push, getProcessUrl);