X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/77af50a44c54ef12a1d7abb59a0e4cba4284e77e..5385afcada8666051658c6889c83848702497759:/src/store/side-panel/side-panel-action.ts diff --git a/src/store/side-panel/side-panel-action.ts b/src/store/side-panel/side-panel-action.ts index 6a83946c..6279aaea 100644 --- a/src/store/side-panel/side-panel-action.ts +++ b/src/store/side-panel/side-panel-action.ts @@ -2,16 +2,42 @@ // // SPDX-License-Identifier: AGPL-3.0 -import { default as unionize, ofType, UnionOf } from "unionize"; +import { Dispatch } from 'redux'; +import { isSidePanelTreeCategory, SidePanelTreeCategory } from '~/store/side-panel-tree/side-panel-tree-actions'; +import { navigateToFavorites, navigateTo, navigateToTrash, navigateToSharedWithMe, navigateToWorkflows, navigateToPublicFavorites, navigateToAllProcesses } from '~/store/navigation/navigation-action'; +import {snackbarActions, SnackbarKind} from '~/store/snackbar/snackbar-actions'; -const actions = unionize({ - TOGGLE_SIDE_PANEL_ITEM_OPEN: ofType(), - TOGGLE_SIDE_PANEL_ITEM_ACTIVE: ofType(), - RESET_SIDE_PANEL_ACTIVITY: ofType<{}>(), -}, { - tag: 'type', - value: 'payload' -}); +export const navigateFromSidePanel = (id: string) => + (dispatch: Dispatch) => { + if (isSidePanelTreeCategory(id)) { + dispatch(getSidePanelTreeCategoryAction(id)); + } else { + dispatch(navigateTo(id)); + } + }; -export type SidePanelAction = UnionOf; -export default actions; \ No newline at end of file +const getSidePanelTreeCategoryAction = (id: string) => { + switch (id) { + case SidePanelTreeCategory.FAVORITES: + return navigateToFavorites; + case SidePanelTreeCategory.PUBLIC_FAVORITES: + return navigateToPublicFavorites; + case SidePanelTreeCategory.TRASH: + return navigateToTrash; + case SidePanelTreeCategory.SHARED_WITH_ME: + return navigateToSharedWithMe; + case SidePanelTreeCategory.WORKFLOWS: + return navigateToWorkflows; + case SidePanelTreeCategory.ALL_PROCESSES: + return navigateToAllProcesses; + default: + return sidePanelTreeCategoryNotAvailable(id); + } +}; + +const sidePanelTreeCategoryNotAvailable = (id: string) => + snackbarActions.OPEN_SNACKBAR({ + message: `${id} not available`, + hideDuration: 3000, + kind: SnackbarKind.ERROR + });